serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
18,301
#ifndef _SIGMOID_KERNEL_ #define _SIGMOID_KERNEL_ #include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> /* * The actual kernel */ template <class T> __global__ void sigmoidKernel(T * in, T * out, int n) { int index = threadIdx.x + blockIdx.x * blockDim.x; if(index < n) out[index] = 1.0f / ...
18,302
#include <math.h> #include <stdio.h> #include <iostream> #include <vector> #include <time.h> #include <math.h> #include <chrono> int N; using namespace std::chrono; // Compares two arrays and print error if there is a difference. void cmp_tab(float *t1, float *t2){ for(int i=0; i<N; ++i) if(t1[i]!=t2[i])...
18,303
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <cufft.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #define dim 3 #define TPBx 16 // TPBx * TPBy = number of threads per block #define TPBy 8 #define TPBz 8 __global__ void real2complex(cufftDoubleComplex *c, double *a, int n)...
18,304
#ifndef INVERT_CU #define INVERT_CU #include <cuda.h> #include <stdio.h> #include <assert.h> extern "C" void invertImage(unsigned char *bits, int width, int height); __global__ void invert(unsigned char *bits, int size) { // invert one pixel int idx = blockIdx.x*blockDim.x + threadIdx.x; if(idx < size) ...
18,305
#include <cstdio> #include <cstring> #include <iomanip> #include <iostream> int const MARKS = 256; int const ROWS = 128; int const COLS = 128; __global__ void knotHash(unsigned char const *input, int inputSize, int *grid) { int row = blockIdx.x * blockDim.x + threadIdx.x; unsigned char lengths[64]; int numLeng...
18,306
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> // Always remember to add these 3 header files #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> // Create and allocate space for a random vector of size n where each element is in the range of 0-49 int* genRa...
18,307
/* CUDA C program @author Juan Manuel Tortajada @mail ai.robotics.inbox@gmail.com */ #include <iostream> #include <sys/time.h> __global__ void calculate_arrays_GPU( int n, float *A, float *B, float *C, float *D, float *E, float *F, float *G, float *H, float *K ){ int unique_thread_id = ( blockIdx.x * blockDi...
18,308
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> void init(double **A, double **C1, double **C2, int dim) { int i, j; int size = dim * dim * sizeof(double); *A = (double *) malloc(size); srand(time(NULL)); for (i = 0; i < dim; i++) { for (j = 0; j < dim; j++) { ...
18,309
#include "includes.h" extern "C" extern "C" __global__ void deltasBatch(float *inputs, float *outputs, float *weights, float *weightsDeltas, int noInputs, int inputSize){ int gid = blockIdx.x * blockDim.x + threadIdx.x; float sum=0; int offsetDeltas = (inputSize+1)*gid; int offsetInput = noInputs*inputSize*gid; int of...
18,310
__device__ volatile int uc = 1; __device__ volatile unsigned int counter = 0; __device__ volatile unsigned int cnt = 1; __global__ void histogram(int *d_input, int* d_bin, int M, int N, int BIN_COUNT) { int id = threadIdx.x + blockIdx.x * blockDim.x; if (id < M*N) { int bid = d_input[id] % BIN_COUNT; atomicAdd(...
18,311
#include "includes.h" __global__ void k_copy_reshape_rowmajor(unsigned int numEls, unsigned int a_nd, const float * a_data, const int * a_dim, const int * a_str, unsigned int z_nd, float * z_data, const int * z_dim, const int * z_str) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int ...
18,312
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <assert.h> __global__ void matrixMult(int *A, int *B, int *C, int N){ // Calculate the global row and column for each thread int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x;...
18,313
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <fstream> #include <cstdlib> #include <math.h> #define BLOCK_SIZE 16 #define FEATURE_LEN 128 using namespace std; //kp[featureNum][4] //h[3][3]->h[9] __global__ void InlineCuda(double *kp, bool *choose, double* h,int featureNum...
18,314
#include "includes.h" __global__ void lga_filter_backward (const int n, const float *bottom_data, const float *top_diff, const int height, const int width, const int channel, const int radius, float *filter_diff){ int index = blockIdx.x * blockDim.x + threadIdx.x; if (index >= n) { return; } int step = height * width...
18,315
// NAME : JUSTINE J AYROOR // UCID : ja573 // Assignment 1 // import libraries #include<cuda.h> #include<stdio.h> #include<stdlib.h> #include <math.h> // Kernel Function __global__ void dotPro(float *a, float *b, float *c, int rows, int cols){ int sum = 0; int tid = threadIdx.x + blockIdx.x * blockDim.x; fo...
18,316
#ifdef _WIN32 #include <time.h> #else #include <sys/time.h> #endif double wall_time(void) { #ifdef _WIN32 return (double)((double)clock() / (double)CLOCKS_PER_SEC); #else struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); return(tv.tv_sec + tv.tv_usec/1000000.0); #endif }
18,317
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <iostream> using namespace std; #define CUDA_THREAD_NUM 1024 // must be a multiply of 2 void dotProductCPU(); __global__ void dotProductCuda(float *a, float *b, float *c); //host code int main() { dotProductCPU(); cudaThreadExit(); return 0; } void...
18,318
// This is the REAL "hello world" for CUDA! // It takes the string "Hello ", prints it, then passes it to CUDA with an array // of offsets. Then the offsets are added in parallel to produce the string "World!" // By Ingemar Ragnemalm 2010 #include <stdio.h> const int N = 16; const int blocksize = 16; __global__...
18,319
#include "includes.h" __global__ void reg_GetConjugateGradient2_kernel( float4 *nodeNMIGradientArray_d, float4 *conjugateG_d, float4 *conjugateH_d) { const int tid= (blockIdx.y*gridDim.x+blockIdx.x)*blockDim.x+threadIdx.x; if(tid < c_NodeNumber){ // G = - grad float4 gradGValue = nodeNMIGradientArray_d[tid]; gradGValue...
18,320
#include "includes.h" __global__ void transposeGlobalRow(float *in, float *out, const int nx, const int ny) { unsigned int i = threadIdx.x+blockDim.x*blockIdx.x; unsigned int j = threadIdx.y+blockDim.y*blockIdx.y; if (i<nx && j<ny) { out[i*ny+j] = in[j*nx+i]; } }
18,321
#include <stdio.h> #include <cuda.h> #include <sys/time.h> __global__ void reset(unsigned *matrix, unsigned matrixsize) { unsigned id = blockIdx.x * blockDim.x + threadIdx.x; for (unsigned jj = 0; jj < matrixsize; ++jj) { matrix[id * matrixsize + jj] = 0; } } __global__ void init(unsigned *matrix, unsigned matrix...
18,322
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda_runtime.h> /** * HOST: Handle the CUDA Errors. */ #define HANDLE_CUDA_ERROR( cuda_expression ) { assertGpuError( ( cuda_expression ), __FILE__, __LINE__ ); } inline void assertGpuError( cudaError_t error_index, const char *error_file, const ...
18,323
/* ================================================================== Programmers: Conner Wulf (connerwulf@mail.usf.edu), Derek Rodriguez (derek23@mail.usf.edu) David Hoambrecker (david106@mail.usf.edu) To Compile use: nvcc -o queens proj3-Nqueens.cu you can specify the board size by...
18,324
#include "includes.h" __global__ void reciprocalKernel(float *data, unsigned vectorSize) { unsigned idx = blockIdx.x*blockDim.x+threadIdx.x; if (idx < vectorSize) data[idx] = 1.0/data[idx]; }
18,325
#include<bits/stdc++.h> #include<cuda.h> #include<thrust/device_vector.h> using namespace std; int nt, nb; void init_bt(int val){ // initialize the num thread blks and grids: if(val <= 1024){ nt = val; nb = 1; } else{ nt = 1024; nb = (val+1024-1)/1024; } } __globa...
18,326
#include "includes.h" __global__ void gSetSparse(float* out, const size_t* indices, const float* values, int length) { for(int bid = 0; bid < length; bid += blockDim.x * gridDim.x) { int index = bid + blockDim.x * blockIdx.x + threadIdx.x; if(index < length) { out[indices[index]] = values[index]; } } }
18,327
#include <stdio.h> __global__ void roi_logits_to_attrs_gpu_kernel(int input_npoint, int channels, float anchor_w, float anchor_l, float anchor_h, const float* base_coors, const f...
18,328
#include <math.h> #include <float.h> #include <cuda.h> __global__ void gpu_Heat (float *h, float *g, int N,float *residual) { // TODO: kernel computation //... extern __shared__ float res_vector[]; int row = blockIdx.x*blockDim.x + threadIdx.x; int col = blockIdx.y*blockDim.y + threadIdx.y; int index = row*N...
18,329
// B=diagm(A) extern "C" { __global__ void diagm_kernel_32(const int lengthA, const float *a, float *b) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i<lengthA) { b[i+i*lengthA] = a[i]; } } }
18,330
#include "includes.h" __global__ void update_bins(unsigned int* bins, int* in_binID, int binNumber, const int size){ unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x; int nt = blockDim.x * blockDim.y; __shared__ unsigned int temp[1024]; temp[tid] = 0; __syncthreads(); for(int x=tid; x<size; x+=nt){ if(in_b...
18,331
//pass //--blockDim=1024 --gridDim=1 --no-inline #include <cuda.h> #include <stdio.h> #define N 2 //1024 __global__ void definitions (unsigned int* B) { atomicInc(B,7);//0111 -> 1000 -> 0000 -> 0001 -> 0010 -> 0011 -> 0100 -> 0101 -> 0110 ... /*the second argument on atomicInc() is a limit for increments. Whe...
18,332
#include <iostream> #include <cuda_runtime.h> #include <stdio.h> #define THREADS 512 // 2^9 #define BLOCKS 32768 // 2^15 #define NUM_VALS THREADS*BLOCKS __device__ void swap(unsigned int a, unsigned int b, float *data){ float temp = data[a]; data[a]=data[b]; data[b]=temp; } __global__ void bitonic_sort_step(float...
18,333
// Useful functions for the PVM that are specific to the tracker // derivative and error calculation __global__ void der_and_error_kernel(double *A, double *B, double *C, unsigned int L) { unsigned int stride = blockDim.x * gridDim.x; unsigned int start = threadIdx.x + blockIdx.x * blockDim.x; for (unsigned int ...
18,334
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/sequence.h> #define MAXP 100000 #define MAXN 21 #define MAXG 1280000 #define THREADS 256 struct pair { int key; int value; }; st...
18,335
/** * By yohanes.gultom@gmail.com * Observing GPU block and grid behavior by playing with 1D (1 Dimension) block and grid */ #include <stdio.h> #include <string.h> __global__ void kernel1( int *a ) { int idx = blockIdx.x * blockDim.x + threadIdx.x; a[idx] = 9; } __global__ void kernel2( int *a ) { int...
18,336
// Copyright (c) OpenMMLab. All rights reserved. #include <stdint.h> namespace mmdeploy { namespace cuda { template <int channels> __global__ void cast(const uint8_t *src, int height, int width, float *dst) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if (x >...
18,337
#include "stdio.h" #include "stdlib.h" #define MAX_NC 32 #define ERROR_HANDLING(call) { \ cudaError error = call; \ if(error != cudaSuccess) { \ fprintf(stderr, "ERROR: in file '%s' in line %i: %s.\n", \ __FILE__, __LINE__, cudaGetErrorString(error)); \ ...
18,338
#include "kernel.cuh" double getValue(int M, int N, int x_row, int y_col, double* List) { int Ind = x_row * N + y_col; return List[Ind]; } int getRowInd(int M, int N, int Ind) { return (int)(Ind / N); } int getColInd(int M, int N, int Ind) { return (int)(Ind % N); } void getMulti(int M, int N, int K, int ind, d...
18,339
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <string.h> __global__ void ascii(char *a, int *b){ int tid = threadIdx.x; b[tid] = int(a[tid]); printf("%d\t", b[tid]); printf("\n"); } __global__ void reverse(int *b, int *c){ int tid = threadIdx.x; c[tid]=0; while(b[tid...
18,340
#include "includes.h" __global__ void cuda_Pad_Dict(float *PadD, float *D, int nRows_D, int nCols_D, int nFilts, int nRows, int nCols) { unsigned int Tidx_D = threadIdx.x + blockIdx.x * blockDim.x; unsigned int Tidy_D = threadIdx.y + blockIdx.y * blockDim.y; int Dim_D = nRows_D * nFilts; int i,j; if ((Tidx_D < nCols_...
18,341
#include "includes.h" __global__ void copy(int *src, int *dest) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int idy = blockIdx.y * blockDim.y + threadIdx.y; if (idx >= WIDTH || idy >= HEIGHT) return; dest[idy * WIDTH + idx] = src[idy * WIDTH + idx]; // Copio tal cual con los mismos indices facil... :) }
18,342
#include "includes.h" __global__ void callOperationSharedDynamic(int *a, int *b, int *res, int k, int p, int n) { int tid = blockDim.x * blockIdx.x + threadIdx.x; if (tid>= n) { return; } extern __shared__ int data[]; int *s_a = data; int *s_b = &s_a[n]; int *s_res = &s_b[n]; __shared__ int s_k, s_p; s_k = k; s_p ...
18,343
extern "C" __global__ void bhsm_backward2( const float *wxy, const float *x, const float *w, const int *ts, const int *paths, const float *codes, const int *begins, const int *lens, const float *gLoss, const int n_in, const int max_len, const int n_ex, float *gx, float *gW ) {...
18,344
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "device_functions.h" #include <stdio.h> //# define num 10 __global__ void add1(int* a, int* b, int* c, int nu) { int i = threadIdx.x; if (i < nu) { c[i] = b[i] + a[i]; //__syncthreads(); } //__syncthreads(); } int main(void) { const int...
18,345
/* ********************************************** * CS314 Principles of Programming Languages * * Fall 2020 * ********************************************** */ #include <stdio.h> #include <stdlib.h> __global__ void check_handshaking_gpu(int * strongNeighbor, int * matches, int nu...
18,346
__global__ void calculate_tensors(double* SR, const double* fields, const double* norms, const int num_modes, const int Nx) { unsigned int full_thread_idx = threadIdx.x + blockIdx.x*blockDim.x; // Calculate the index unsigned int nmp4 = num_modes*num_modes*num_modes*num_modes; unsigned int Nxnm = Nx*n...
18,347
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <time.h> const int N = 100; const int M = 100; __global__ void matrixAdd(int* A, int* B, int* C){ //Posicion del thread int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; int pos = i * N + j; i...
18,348
#include "includes.h" __global__ void Bprop2(const float* layer1, float* dsyn2, const float* out, const float alpha) { int i = threadIdx.x; //256 int j = blockDim.y*blockIdx.y + threadIdx.y; //10 int k = blockIdx.x; //Data.count atomicAdd(&dsyn2[i*10 + j], out[k*10 + j] * layer1[256*k + i] * alpha); }
18,349
#include <stdio.h> #include <stdlib.h> #define N 4096 * 1024 void saxpy(int n, float a, float *x, float *y){ for( int i=0; i<n; i++) { y[i] = a * x[i] + y[i]; } return ; } __global__ void saxpy_line6_kernel(int n, float a, float *x, float *y){ int i = blockIdx.x * blockDim.x + threadIdx.x ; ...
18,350
#include <stdio.h> #include <assert.h> #define N 11 #define M 3 __global__ void kernel(float * d_matrix, size_t pitch) { for (int j = blockIdx.y * blockDim.y + threadIdx.y; j < N; j += blockDim.y * gridDim.y) { float* row_d_matrix = (float*)((char*)d_matrix + j*pitch); for (int i = blockIdx.x * bl...
18,351
#include "includes.h" __global__ void fmaf_kernel(float *d_x, float *d_y, float *d_z, int size) { int idx_x = blockIdx.x * blockDim.x + threadIdx.x; int stride = gridDim.x * blockDim.x; for (int i = idx_x; i < size; i += stride) { d_z[i] = fmaf(d_x[i], d_y[i], 0.f); } }
18,352
#include "includes.h" extern "C" { } __global__ void scaleParams(int N, int M, float c, float *Mat, float *F) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; int index = j*N + i; if (i < N && j < M) { float s = __saturatef( __fdividef(c, __fsqrt_rn(F[i]))); ...
18,353
#include <stdio.h> #include <cuda.h> __global__ void computeRays() { printf("Hello from my kernel\n"); } int rfraytrace(){ computeRays<<<1,1>>>(); cudaDeviceSynchronize(); printf("Hello from rfraytrace!\n"); return 0; }
18,354
/* Copyright (c) 1993-2015, NVIDIA CORPORATION. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of ...
18,355
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, float var_1,float var_2,float var_3,float var_4,int var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float ...
18,356
/***************************************************************************//** * \file LHS1.cu * \author Christopher Minar (minarc@oregonstate.edu) * \brief kernels to generate the left hand side for the intermediate velocity solve */ #include "LHS1.h" namespace kernels { __global__ void LHS_mid_X(int *row, int...
18,357
#include <iostream> #include <cstdlib> #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> __global__ void vecAdd(double* res, double* inA, double* inB, size_t n) { int x = blockDim.x * blockIdx.x + threadIdx.x; if (x >= n) return; res[x] = inA[x] + inB[x]; } i...
18,358
#include <cuda.h> #include <cuda_runtime.h> #include "stdio.h" #define TILE_SIZE 512 #define WARP_SIZE 32 extern "C" void CSRmatvecmult(int* ptr, int* J, float* Val, int N, int nnz, float* x, float *y, bool bVectorized); extern "C" void ELLmatvecmult(int N, int num_cols_per_row , int * indices, float * data , float *...
18,359
#include <stdint.h> #include <cuda.h> __global__ void add(float *a, float *b, float *c, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if (i < n && j < n) { int idx = i * n + j; c[idx] = a[idx] + b[idx]; } }
18,360
#include "includes.h" __global__ void removeRuntyPartsKernel(int size, int *partition, int *removeStencil, int *subtractions) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < size) { int currentNode = partition[idx]; if(removeStencil[currentNode] == 1) partition[idx] = -1; else partition[idx] -= subtractions...
18,361
#include "includes.h" __global__ void kernel(float* data, size_t from, size_t to, size_t min, size_t max, size_t NX) { size_t i = min + blockIdx.x * blockDim.x + threadIdx.x; while (i < max) { //TODO CONSIDER REMOVING MODULUS (might be slow) if ( (i % NX != 0) && (i % NX != NX - 1) ){ data[to+i] = 0.2 * ( data[from+i] ...
18,362
#include "includes.h" __global__ void _adam64(int n, int t, double eps, double b1, double b2, double *fstm, double *scndm, double *dw) { int i = threadIdx.x + blockIdx.x * blockDim.x; while (i < n) { fstm[i] = b1*fstm[i] + (1-b1)*dw[i]; scndm[i] = b2*scndm[i] + (1-b2)*(dw[i] *dw[i]); dw[i] = (fstm[i] / (1 - pow(b1,(dou...
18,363
#include <iostream> #include <stdio.h> #include <cuda.h> #include <math.h> using namespace std; #define BDIM 256 #define datafloat double #define BX 16 #define BY 16 /* Poisson problem: diff(u, x, 2) + diff(u, y, 2) = f Coordinate transform: x -> -1 + delta*i, ...
18,364
#include <iostream> #include <ctime> #define N 50000 const int threads_per_block = 256; __global__ void dot_gpu(float *a, float *b, float *c) { __shared__ float cache[threads_per_block]; int tid = threadIdx.x + blockIdx.x * blockDim.x; int cacheIndex = threadIdx.x; float temp = 0; whil...
18,365
#include "cuda.h" #include <cuda_runtime_api.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <iostream> #define BLOCK_SIZE 1024 #define MAX_BLOCKS 65535 #define MAX_GB 2 typedef double memory; typedef unsigned char byte_memory; typedef unsigned long long int counter_type; __g...
18,366
/*#include "cutil_math.h" // Data #define SIZE 256 #define MASK 0xFF // Permutation table __constant__ unsigned char p[SIZE]; // Gradients __constant__ float gx[SIZE]; __constant__ float gy[SIZE]; __constant__ float gz[SIZE]; extern "C" void host_PerlinInitialize(unsigned int nSeed) { int i, j, nSwap; srand(nSeed...
18,367
#include "includes.h" __global__ void LinearBinning(float *vec, int *bin, int *bin_counters, const int num_bins, const int MaxBin, const int n, const float slope, const float intercept) { unsigned int xIndex = blockDim.x * blockIdx.x + threadIdx.x; float temp = abs(vec[xIndex]); if ( xIndex < n ){ if ( temp > (intercep...
18,368
#include<cuda.h> #include<iostream> __global__ void simpleKernel(int a, int* dA) { //this adds a value to a variable stored in global memory int x = threadIdx.x; int y = blockIdx.x; // printf("x is %d, y is %d, index is %d, num is %d\n",x,8*y+x,a*x+y); dA[8*y+x] = a*x + y; } int main() { int h...
18,369
#include "buffer.cuh" void hostpinned_malloc(void **ptr, size_t const size){ assert(size != 0); cudaHostAlloc(ptr, size, cudaHostAllocPortable); } void hostpinned_free(void *ptr){ assert(ptr != NULL); cudaFree(ptr); } void host_malloc(void **ptr, size_t const size){ assert(size != 0); *ptr = ...
18,370
/** * kernelFunctions.cpp - Functions used by the device (the GPU) * in the (obviously) GPU implementaiton of our algorithm. */ #include <iostream> __global__ void kernel_internalMemcpy(double *dest, const double *from, const unsigned W, const unsigned H) { const unsigned start_idx = blockDim.x * blockIdx.x + ...
18,371
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <stdint.h> #define MASTER 0 void Usage(char* prog_name) { fprintf(stderr, "usage: %s <thread_count> <n>\n", prog_name); fprintf(stderr, " n is the number of terms and should be >= 1\n"); exit(1); } __host__ double seque...
18,372
//pass #include <cuda.h> #include <assert.h> #define N 2 __global__ void race_test (unsigned int* i, int* A) { int tid = threadIdx.x; int j = atomicAdd(i,1); A[j] = tid; }
18,373
#define BLOCK_SIZE 16 // block size #define v3_v3_dot(a, b) (a.x * b.x + a.y * b.y + a.z * b.z) __global__ void TestKernel( uchar4* dst,float3* normal_map, float3 cam_vec, unsigned int imgWidth, unsigned int imgHeight ) { unsigned int tx = threadIdx.x; unsigned int ty = threadIdx.y; unsigned int bw =...
18,374
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #include "cuda_runtime.h" #include <cuda_runtime_api.h> #include "device_launch_parameters.h" #define N 128 #define base 0 //sto visual studio ta kanw define otan ta kanw compile ta dinw orismata //#define block_count 100; //#define thread_cou...
18,375
#include<stdio.h> #include<cuda_runtime.h> #include<device_launch_parameters.h> __global__ void add(int *a,int *b,int *c) { int id=blockIdx.x*blockDim.x+threadIdx.x; c[id]=a[id]+b[id]; } int main() { int a[10],b[10],c[10],n; printf("Enter n: "); scanf("%d",&n); printf("Enter A:\n"); for(int i=0;i<n;i++) ...
18,376
#include <stdio.h> __device__ int getGlobalIdx() { return blockIdx.x * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; } __global__ void kernel(int * d_in, int * d_out) { int global_idx = getGlobalIdx(); printf("Hello world! I'm a thread %d in block %d, my global id is %d and my value is %d\n", t...
18,377
/* * Ejercicio 4: Área del conjunto de Mandelbrot */ #include <stdlib.h> #include <math.h> #include <stdio.h> #include <time.h> # define NPOINTS 2000 // # define NPOINTS 10 # define MAXITER 2000 # define THREADS_PER_BLOCK 256 # define NUM_BLOCKS 16 struct complex{ double real; double imag; }; const int ARR_B...
18,378
#include <stdio.h> #include <iostream> #include <cuda.h> #define BLOCK_DIM 32 // This will output the proper error string when calling cudaGetLastError #define getLastCudaError(msg) __getLastCudaError (msg, __FILE__, __LINE__) inline void __getLastCudaError( const char *errorMessage, const char *file, const int...
18,379
#include "includes.h" __global__ void add(int* in, int* out, int n){ int gid = threadIdx.x + blockIdx.x * blockDim.x; if(gid >= n) return ; extern __shared__ int temp[]; int pout = 0, pin = 1; temp[threadIdx.x + pout * n] = (threadIdx.x>0) ? in[threadIdx.x-1] : 0; __syncthreads(); for(int offset=1; offset<n; offset...
18,380
float h_A[]= { 0.7185843264759357, 0.6041700431822224, 0.7256437446631514, 0.9089973626601424, 0.9562761075961994, 0.6940164365610328, 0.6687524630661181, 0.7718164992934502, 0.8220086944902376, 0.7908604522679337, 0.5240308037310879, 0.98401940309521, 0.7823056452595585, 0.6401788851042656, 0.6000053911411694, 0.79066...
18,381
#include <cuda_runtime.h> #include<iostream> using namespace std; #include <device_launch_parameters.h> //programs ran on GPU, called device //func itself is a kernel //global identifier indicates func ran on device, not host //main code -> compiled via host, kernel code -> compiled via device __global__ void add(int ...
18,382
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> //// notes // based on the examples given in the CUDE programming guide // this one makes a list of gals, one list for ra and one for dec. // it can then calcs the separation between gal pairs. // note that it's not returning anythign from the...
18,383
/* * Test for processing images in CUDA (input and output, are processed * as 1D arrays). */ __global__ void test(double * output, double * const input, unsigned int const numRows, unsigned int const numCols) { /*current pixel*/ const int rowIdx = blockIdx.x*blockDim.x + threadIdx.x; const int colIdx ...
18,384
#include "includes.h" __global__ void gpuDot(float* dot, float* a, float* b, int N) { __shared__ float cache[THREADS_PER_BLOCK]; int tid = blockIdx.x*blockDim.x + threadIdx.x; int cacheIdx = threadIdx.x; float temp = 0; while (tid < N) { temp += a[tid] * b[tid]; tid += blockDim.x * gridDim.x; } cache[cacheIdx]=temp;...
18,385
// including used headers #include <vector> #include <iostream> #include <numeric> #include <algorithm> #include <random> // kernel __global__ void adjacent_difference(int n, float *x, float *y) { // data indices to blocks int i = blockIdx.x * blockDim.x + threadIdx.x; // run algorithm // first element ~ do nothin...
18,386
#include "includes.h" #define TB 128 #define GS(x) (((x) - 1) / TB + 1) __global__ void Normalize_forward_(float *input, float *norm, float *output, int size23, int size123, int size0123) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < size0123) { int dim23 = id % size23; int dim0 = (id / size123); output...
18,387
/* * usage: nvcc --default-stream per-thread ./stream_test_v4.cu -o ./stream_v4_per-thread * nvvp ./stream_v4_per-thread ( or as root: * nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java ./stream_v4_per-thread ) * * purpose: modify the kernel code to really use a ...
18,388
/************************************************************************************************* * * Computer Engineering Group, Heidelberg University - GPU Computing Exercise 03 * * Group : TBD * * File : main.cu * * Purpose ...
18,389
#include "includes.h" __global__ void addKernel(int * dev_a, int* x) { int i = threadIdx.x; if (dev_a[i] < *x) dev_a[i] = 0; else dev_a[i] = 1; }
18,390
#include <cuda_runtime.h> __global__ void gemm_kernel_0(const float* A, const float* B, float* C, int m, int n, int k) { // A -> m x n // B -> n x k // C -> m x k int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; if(row >= m || col >= k) ...
18,391
#include <stdio.h> #include <sys/time.h> // Kernel to print thread id __global__ void saxpyGPU(float *xx, float *yy, float aa){ int ii = blockIdx.x * blockDim.x + threadIdx.x; yy[ii] += aa * xx[ii]; } int main(){ // Array size #define ARRAY_SIZE 10000 printf("Array size: %d\n", ARRAY_SIZE); // Threads...
18,392
/****************************************************************************** *cr *cr (C) Copyright 2010 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr *****************************************************************...
18,393
#include <iostream> #include <cstdlib> /* GPU kernel to perform 1 dim stencil on a data including boundary data using shared memory in: device array for input data including boundary out: device array for output data including boundary unchanged arraySize: size of in and out wArr: weight array wArrSize: size of wA...
18,394
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include "string.h" #include <iostream> #define DEFAULT_THRESHOLD 8000 #define TILE_SIZE 16 #define DEFAULT_FILENAME "BWstop-sign.ppm" unsigned int *read_ppm( char *filename, int * xsize, int * ysize, int *maxval ){ if ( !filename || filename[0] == '\0'...
18,395
#define t_max 1 #define t 1 /* (u[0][0][0][1][0]=((((u[1][0][0][0][0]+(u[-1][0][0][0][0]+u[0][1][0][0][0]))+(u[0][-1][0][0][0]+(u[0][0][1][0][0]+u[0][0][-1][0][0])))*0.25)-u[0][0][0][0][0])) */ __global__ void laplacian(float * * u_0_1_out, float * u_0_0, float * u_0_1, int x_max, int y_max, int z_max, int cbx) {...
18,396
/* * Solves the Panfilov model using an explicit numerical scheme. * Based on code orginally provided by Xing Cai, Simula Research Laboratory * and reimplementation by Scott B. Baden, UCSD * * Modified and restructured by Didem Unat, Koc University * */ #include <stdio.h> #include <assert.h> #include <stdlib...
18,397
#include "includes.h" __global__ void sec_max_cuda_(int nProposal, int C, float *inp, int *offsets, float *out){ for(int p_id = blockIdx.x; p_id < nProposal; p_id += gridDim.x){ int start = offsets[p_id]; int end = offsets[p_id + 1]; for(int plane = threadIdx.x; plane < C; plane += blockDim.x){ float max_val = -1e50; ...
18,398
#include <stdio.h> #include <algorithm> #include <cmath> #include <iostream> #include <fstream> #include <ctime> #include <string> #include <cuda.h> #include <cuda_runtime.h> #include <cuda_runtime_api.h> #include <thrust/host_vector.h> #include <thrust/device_ptr.h> #include <thrust/scan.h> #include <thrust/reduce.h...
18,399
extern "C" __global__ void biasKernel (int batchSize, int numberEntriesPerInstance, int numberRows, float* input, float* bias, float* result) { int indexInstance = blockIdx.x; int startInstance = indexInstance * numberEntriesPerInstance; int indexEntryInInstance = blockIdx.y * blockDim.x + threadIdx.x; ...
18,400
#include <stdio.h> #include <cuda.h> __global__ void Add(float *A, int size) { const unsigned int numThreads = blockDim.x * gridDim.x; const int idx = (blockIdx.x * blockDim.x) + threadIdx.x; for (unsigned int i = idx;i < size; i += numThreads) A[i] = A[i]+ A[i]; } void test_bandwidth() { cudaEvent_t* ti...