serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
18,201
#include "includes.h" __global__ void kExtractPatches(float* images, float* patches, float* indices, float* width_offset, float* height_offset, int num_images, int img_width, int img_height, int patch_width, int patch_height, int num_colors) { const unsigned long idx = blockIdx.x * blockDim.x + threadIdx.x; const unsig...
18,202
/* ============================================================================ Name : review_chp4_1.cu Author : freshield Version : Copyright : Your copyright notice Description : CUDA compute reciprocals ============================================================================ */ #include...
18,203
#include "includes.h" __global__ void updZ_SoA(float *z1, float *z2, float *f, float tz, float beta, int nx, int ny) { int px = blockIdx.x * blockDim.x + threadIdx.x; int py = blockIdx.y * blockDim.y + threadIdx.y; int idx = px + py*nx; if (px<nx && py<ny) { // compute the gradient float a = 0; float b = 0; float fc =...
18,204
/* Babak Poursartip 02/27/2021 CUDA topic: pinned memory - Instead of using malloc or new to allocation memory on the CPU(host), we use cudaHostAlloc(). This will allocate a pinned memory on the host. - To free the memory, we use cudaFreeHost, instead of delete to deallocate. - The disadvantage is that you cannot...
18,205
// --- Headers --- #include <cuda.h> #include <stdio.h> // --- Macros --- #define CHUNK (1024 * 1024) #define SIZE (CHUNK * 20) // --- Variable Declaration --- int *hostInputA = NULL; int *hostInputB = NULL; int *hostOutput = NULL; int *deviceInputA0 = NULL; int *deviceInputB0 = NULL; int *deviceOutput0 = NUL...
18,206
//pass //--gridDim=32 --blockDim=256 __global__ void reduceKernel(float *d_Result, float *d_Input, int N) { const int tid = blockIdx.x * blockDim.x + threadIdx.x; const int threadN = gridDim.x * blockDim.x; float sum = 0; for (int pos = tid; pos < N; pos += threadN) sum += d_...
18,207
#include<stdio.h> #include<cuda.h> # define M 10000 # define N 10000 __global__ void add( int * a, int * b, int * c) { unsigned int i= blockDim.x *blockIdx.x + threadIdx.x; unsigned int j= blockDim.y *blockIdx.y + threadIdx.y; if(i<M && j<N) c[i*M+j]=a[i*M+j]+b[i*M+j]; } int check(int *a, int *b, int *c) { for(...
18,208
#include "distance_transformation_gpu.cuh" __global__ void distTransformation_GPU (int scheme, unsigned char *raw_vol, float sp2_0, float sp2_1, float sp2_2, int height, int width, int depth, double *ed_out) { int size_of_vol = height * width * depth; int slice_stride = height * width; int ti...
18,209
#include "cuda_runtime.h" #include "stdio.h" #define CHECK(call) \ { \ const cudaError_t error = call; \ if (error != cudaSuccess...
18,210
#include "includes.h" __global__ void count_bins(int *bin, int *bin_counters, const int num_bins, const int n) { unsigned int xIndex = blockDim.x * blockIdx.x + threadIdx.x; if ( (xIndex < n) & (bin[xIndex]<num_bins) ) atomicAdd(bin_counters+bin[xIndex],1); }
18,211
/************************************************************************* > File Name: 05_0304.cu > Author: dong xu > Mail: gwmxyd@163.com > Created Time: 2016年03月30日 星期三 13时37分15秒 ************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <time.h> ...
18,212
#include "includes.h" __device__ int f () { return 21; } __global__ void AplusB_wait(int *ret, int a, int N, clock_t sleepInterval) { clock_t start = clock64(); while ( clock64() < start + sleepInterval ) { } size_t gindex = threadIdx.x + blockIdx.x * blockDim.x; if ( gindex < N ) // Only change the needed. ret[gindex]...
18,213
#include <cuda_runtime.h> #include <stdio.h> int main(int argc,char **argv){ // set up device int dev = 0; cudaSetDevice(dev); // memory size unsigned int isize = 1<<22; unsigned int nbytes = isize * sizeof(float); // get device information cudaDeviceProp deviceProp; cudaGetD...
18,214
#include "includes.h" __global__ void add3(float *val1, float *val2, int *num_elem) { int i = threadIdx.x; val1[i] += val2[i]; }
18,215
#include "includes.h" #define BLOCKSIZE 1024 __global__ void dotProduct_dVector_kernel(double *a, double *b, double *partial_sum, int n) { __shared__ double partial_sums[BLOCKSIZE]; double local_sum = 0; int id = blockIdx.x*blockDim.x + threadIdx.x; int partial_index = threadIdx.x; while (id < n) { local_sum += (...
18,216
#include "includes.h" __global__ void MD_ED_I(float *S, float *T, int trainSize, int window_size, int dimensions, float *data_out, int task, int gm) { int idx, offset_x; float sumErr = 0; long long int i, j; if(gm == 0){ extern __shared__ float sh_mem[]; float *T2 = (float *)sh_mem; float *DTW_single_dim = (float ...
18,217
#include "cuda_RandomForest_Constants.cu" namespace Bagging{ __global__ void kernel_entry(paramPack_Kernel params); __host__ void cuda_RandomForest_UpdateConstants(void* src); } namespace ExtremeCreateNodes{ __global__ void kernel_entry(paramPack_Kernel params); __host__ void cuda_RandomForest_UpdateConstants(voi...
18,218
#include <thrust/count.h> #include <thrust/device_vector.h> #include <iostream> int main(int argc, char* argv[]) { // put three 1s in a device_vector thrust::device_vector<int> vec(5,0); vec[1] = 1; vec[3] = 1; vec[4] = 1; // count the 1s int result = thrust::count(vec.begin(), vec.end(), 1); ...
18,219
/* * CUDA kernel for 2D max-blurring (dilation) * Applies Gaussian convolution filter to input image, but instead of * summing up the neighboring area, it takes the maximum product it finds. * Sofie Lovdal 12.6.2018 */ __global__ void maxBlur(double * output, double * const input, unsigned int const numRows, ...
18,220
#include <cuda_runtime.h> #include <iostream> using namespace std; __global__ void test_add(int a, int b) { // added parameters int a, int b a += b; } int main() { // cout<<(test_add<<<1,1>>>(4,5))<<endl; test_add<<<1,1>>>(4,5); cudaDeviceSynchronize(); // was CudaDeviceSinchronize cudaDeviceReset(); // ...
18,221
#include "includes.h" __global__ void simple_input_shortcut_kernel(float *in, int size, float *add, float *out) { int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; if (id >= size) return; out[id] = in[id] + add[id]; }
18,222
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> extern "C" void JacobiHost( float* a, int n, int m, float w0, float w1, float w2, float tol ); extern "C" void JacobiGPU( float* a, int n, int m, float w0, float w1, float w2, float tol ); static void init( float* a, int n, int m ) { int i, j; memse...
18,223
#include "includes.h" __global__ void unsafe(int *shared_var, int iters) { for (int i = 0; i < iters; i++) { int old = *shared_var; *shared_var = old + 1; } }
18,224
#define length_of_features 12 __global__ void sgd_lock_free_naive(float *x, float* y, float* weights, float reg_strength, float learning_rate, int total_examples, int max_epochs) { int tid = blockIdx.x * blockDim.x + threadIdx.x; float val=0; float dw[length_of_features]; flo...
18,225
#include <iostream> #include <memory> __global__ void square1(float* out, float* in) { int index = blockDim.x * blockIdx.x + threadIdx.x; float f = in[index]; out[index] = f * f; } int main() { const int N = 1024; std::unique_ptr<float[]> h_in(new float[N]); std::unique_ptr<float[]> h_out(new float[N]); for(i...
18,226
#define bidx (blockIdx.x) #define bidy (blockIdx.y) #define tidx (threadIdx.x) #define tidy (threadIdx.y) #define gridDimX (gridDim.x) #define gridDimY (gridDim.y) #define COALESCED_NUM 16 #define blockDimX 128 #define blockDimY 1 #define idx (bidx*blockDimX+tidx) #define idy (bidy*blockDimY+tidy) #define merger_y 32 #...
18,227
#include <stdio.h> #include <sys/time.h> double mysecond(){ struct timeval tp; struct timezone tzp; int i = gettimeofday(&tp, &tzp); return ((double)tp.tv_sec + (double)tp.tv_usec * 1.e-6); } void SAXPY_CPU(int N, float A, float *X, float *Y, float *R){ for(int i=0; i<N; i++){ R[i] = A * X[i] + Y[i]; ...
18,228
__global__ void ReductionMax2(float *input, float *results, int n) //take thread divergence into account { extern __shared__ int sdata[]; unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; unsigned int tx = threadIdx.x; //load input into __shared__ memory int x = INT_MIN; if(i < n) x = input[i]; sdata...
18,229
#include<stdio.h> int main() { int dimx = 16; int num_bytes = dimx*sizeof(int); int *d_a=0, *h_a=0; // device and host pointers // Allocate memory on host (CPU) h_a = (int*)malloc(num_bytes); // Allocate memory on device (GPU) cudaMalloc((void**)&d_a,num_bytes); // Check to see that...
18,230
#include <stdio.h> #define MAX_SECRET 8000000 #define KEY_SIZE 8 #define BUFFER 512 __global__ void exor(const int size, const char *secret, char *key) { char temp[KEY_SIZE]; temp[0] = blockIdx.x/10 + 48; temp[1] = blockIdx.x%10 + 48; temp[2] = blockIdx.y/10 + 48; temp[3] = blockIdx.y%10 + 48; ...
18,231
#include <iostream> #include <vector> #include "thrust/count.h" #include "thrust/device_vector.h" #include "thrust/inner_product.h" #include "thrust/sort.h" struct Data { thrust::device_vector<int> day; thrust::device_vector<int> site; thrust::device_vector<int> measure; }; int days_with_rainfall(const Data& d...
18,232
// test constant variable and cudaMemcpyToSymbol #include <iostream> #include <cuda_runtime.h> __constant__ float dfactor; __global__ void test(float *a, int size) { int idx = threadIdx.x; if(idx<size) a[idx] = dfactor; } int main(void) { float factor=9.0f; cudaMemcpyToSymbol(dfactor, ...
18,233
#include <cassert> #include <iostream> #include <stdio.h> #include <stdlib.h> #include "lbp.cuh" __global__ void lbp_value_kernel(const unsigned char* image, unsigned char* lbp_values, const int width, const int height, const size_t pitch) { int x ...
18,234
#include "../Headers/Includes.cuh" /////////////// General GPU Functions /////////////// __device__ void D_unit_vector(float *start, float *stop, float *vec){ // Gives the unit vector which points between two locations float magsq = 0; for (unsigned i = 0; i < 3; i++) { vec[i] = stop[i] - start[i]; m...
18,235
#include <iostream> #include <cmath> #include <cstdio> #define cudaErrchk(ans) { GPUAssert((ans), __FILE__, __LINE__); } inline void GPUAssert(cudaError_t code, const char *file, int line, bool abort=true){ if (code != cudaSuccess) { fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); ...
18,236
__global__ void Suma(int t_a, int t_b, int size_n, int size_m, float *a, float *b, float *c) { const uint idx = threadIdx.x + blockDim.x * blockIdx.x; const uint idy = threadIdx.y + blockDim.y * blockIdx.y; int ida = 0; int idb = 0; if(idx < size_m && idy < size_n){ ...
18,237
struct MscData { float a; float b; }; __global__ void apply_kernel(const MscData data, float const* __restrict__ step, float* __restrict__ result) { result[threadIdx.x] = data.a * step[threadIdx.x] + data.b; }
18,238
#include <stdio.h> #include <iostream> #include <ctime> #include <string.h> #include <cuda_runtime.h> #include <curand.h> #include <curand_kernel.h> #define NUM_BLOCKS 16 #define NUM_THREADS 16 #define Num_Queens 8 #define MAX_ITER 4000 using namespace std; __device__ int checkDiagonals(int q,int i, int* S) // Retur...
18,239
#include <iostream> #include <stdlib.h> #include <ctime> #include <cuda_runtime.h> #include <cuda.h> using namespace std; __global__ void vecAddKernel(float * A, float *B, float *C, int n){ int i = blockDim.x*blockIdx.x + threadIdx.x; if(i<n) C[i] = A[i] + B[i]; } void vecAdd(float * A, float *B, float *...
18,240
#include "includes.h" __global__ void ChangeRecurrentWeightsKernel( float *recurrentWeights, float *recurrentWeightDeltas, float *outputWeights, float *outputDeltas, float *recurrentWeightRTRLDerivatives, float trainingRate, float momentum ) { int weightId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current ro...
18,241
#include <iostream> #include <cstdlib> #include <cassert> // Add a scalar to the vector void vadd(int *const v, int const a, size_t const len) { for (size_t i = 0; i < len; ++i) { v[i] += a; } } int main() { // Vector length constexpr size_t LEN = 100'000; // Allocate vector int *dat...
18,242
#include <cuda.h> #include <cuda_runtime.h> #include <iostream> int main(int argc, char ** argv) { int deviceCount; cudaGetDeviceCount(&deviceCount); for (int dev = 0; dev < deviceCount; dev++) { cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); if (dev == 0)...
18,243
#include "cuda_runtime.h" #include "stdio.h" #define BDIMX 32 #define BDIMY 16 #define IPAD 2 // Transactions = BDIMY * sizeof(T) / 8 #define IPAD_D 2 __global__ void setRowReadRow(int* out) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; int idx = y * gri...
18,244
#include <iostream> #include <stdlib.h> #include <fstream> #include <sstream> #include <utility> #include <unordered_map> #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <chrono> #include <vector> #include <assert.h> #include <math.h> #define NUM_STREAMS 16 // This is firs...
18,245
// Device code // A is assumed to be initialized by an // initializer port to be uniformly 0. // output should be uniformly scalar. extern "C" __global__ void scale(float* A, float scalar, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) A[i] = A[i]+scalar; }
18,246
#include "includes.h" __device__ unsigned int getGid3d3d(){ int blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z) + (threadIdx.y * blockDim.x) + (threadIdx.z * (blockDim.x * blockDim.y)) + threadIdx.x; return threadId; } _...
18,247
#include "includes.h" __global__ void __linComb(float *X, float wx, float *Y, float wy, float *Z, int len) { int ip = threadIdx.x + blockDim.x * (blockIdx.x + gridDim.x * blockIdx.y); for (int i = ip; i < len; i += blockDim.x * gridDim.x * gridDim.y) { Z[i] = X[i]*wx + Y[i]*wy; } }
18,248
#include "includes.h" __global__ void _bcnn_forward_softmax_layer_kernel(int n, int batch, float *input, float *output) { int i; float sum = 0; float largest = -INFINITY; int b = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; if (b >= batch) { return; } for (i = 0; i < n; ++i) { int val = input[i+b*n...
18,249
#include <stdio.h> #include <assert.h> #define N 1000000 int main (int argc, char **argv){ int a[N], b[N], c[N]; int i; for (i=0;i<N;i++) a[i]=i; for (i=0;i<N;i++) b[i]=i; #pragma acc parallel loop for (i=0;i<N;i++) c[i] = a[i] + b[i]; for (i=0;i<N;i++) assert (c[i] == a[i] + b[i]); ...
18,250
/* Voxel sampling GPU implementation * Author Zhaoyu SU * All Rights Reserved. Sep., 2019. */ #include <stdio.h> #include <iostream> #include <float.h> __device__ int get_batch_id(int* accu_list, int batch_size, int id) { for (int b=0; b<batch_size-1; b++) { if (id >= accu_list[b]) { if(id ...
18,251
#include <iostream> #include <cuda.h> #define mycout cout<<"["<<__FILE__<<":"<<__LINE__<<"] " #define CHECK(res) if(res!=cudaSuccess){exit(-1);} #define rows 5 #define cols 3 using namespace std; typedef float FLOAT; // __global__ void vec_add(FLOAT **a,const int rows,const int cols) __global__ void vec_add(FLOAT **...
18,252
#include <stdio.h> #include <math.h> #include <cuda_runtime.h> #include "gillespie_simulation_cuda.cuh" /** * This kernel advances each simulation by one event. It does this by modeling * each simulation as independent Poisson processes and using the Gillespie * algorithm to randomly choose an event and a timespa...
18,253
#include <stdio.h> #include <assert.h> #include <pthread.h> #define THREADS 4 int intervalsT=100000000; double store,base; double partialStore[]={0.0, 0.0, 0.0, 0.0}; void *threadRoutine(void *param) { int i; int *threadId = (int *)param; int partialInterval = intervalsT/THREADS; double height; double x; for ...
18,254
#include "vector2D.cu" #include "circle.cu" #include "line.cu" extern "C"{ __global__ void billiard_kernel( const int nParticles, const int iterPerSnapshot, const int nSnapshots, const float timePerSnapshot, const int nCircles, double *circlesProperties, const int nLines, double *linesPr...
18,255
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <limits.h> #include <cuda.h> #include <curand.h> #define CUDA_CALL(x) \ if ( cudaSuccess != (x) ) { \ fprintf(stderr,"cuda call failed at line :%d \n",__LINE__); \ exit(1); } #define CURAND_CALL(x) \ if ((x) != CURAND_STATU...
18,256
#include "includes.h" #define _size 512 __global__ void mul(int *a, int *b, int *c) { c[threadIdx.x + blockIdx.x*blockDim.x] = a[threadIdx.x + blockIdx.x*blockDim.x]*b[threadIdx.x + blockIdx.x*blockDim.x]; }
18,257
/*#include "cuda_runtime.h" #include <cublas.h> #include "device_launch_parameters.h" #include <helper_cuda.h> #include <helper_math.h> #include <functional> #include <chrono> #include <iostream> #include <vector> #include <memory> #include <cub/cub.cuh> #include <cub/block/block_load.cuh> #include <cub/block/block_sto...
18,258
#include <cuda.h> __device__ uint32_t pcg32_64(volatile uint64_t &state, uint64_t inc){ // Calculate output function (XSH RR), uses old state for max ILP uint32_t xorshifted = ((state >> 18u)^state) >> 27u; uint32_t rot = state >> 59u; // Update state state = (state * 6364136223846793005ULL + ...
18,259
__global__ void dual(float* xn, float* xcur, float* y1, float* y2, float* img, float tau, float lambda, int w, int h, int nc) { int x = threadIdx.x + blockDim.x * blockIdx.x; int y = threadIdx.y + blockDim.y * blockIdx.y; if (x < w && y < h) { int i; float d1, d2, val, value; float factor = tau * lambda; ...
18,260
#include "includes.h" __global__ void cuAdd(int *a,int *b,int *c, int N) { // 1D global index int offset = blockDim.x * blockIdx.x + threadIdx.x; if(offset < N) { c[offset] = a[offset] + b[offset]; } }
18,261
/* * Noopur Maheshwari : 111464061 * Rahul Rane : 111465246 */ #include <pthread.h> #include <iostream> using namespace std; extern pthread_mutex_t lock; int get_shared_var_value(int *ptr) { int ret; //cout<<"About to lock 1"<<endl; pthread_mutex_lock(&lock); //cout<<"lock 1"<<endl; ret = *ptr; ...
18,262
#include <stdio.h> #include <cuda.h> #define SIM_THREADS 10 // how many simultaneus threads #define N 100 // number of variables in a vector // this function does absolutely nothing, but runs on multiple cores __global__ void dummyFunct(void) { int i; int a = 0; // this loop will do sequences: // i = 0, ...
18,263
#include "includes.h" /* There can be problem with crashing app It is caused by WDDM TDR delay this delay works in such a way that kill the kernel if it doesnt finish in specific time so for big numbers it can be a problem but you can change time or even turn it off in Nsight monitor : option->general->microsoft displa...
18,264
#include "includes.h" // CUDA Kernel function to add the elements of two arrays on the GPU __global__ void add(int n, float *x, float *y) { int index = threadIdx.x; int stride = blockDim.x; for (int i = index; i < n; i+= stride) y[i] = x[i] + y[i]; }
18,265
#include <stdio.h> #include <stdlib.h> //cuda include #include <cuda.h> __device__ void Gswap(void *from, void *to, int length){ void *tmp = malloc(length); memcpy(tmp, to, length); memcpy(to, from, length); memcpy(from, tmp, length); }
18,266
using namespace std; #include <stdio.h> #include <time.h> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template < typename F > struct vArray { F* _; size_t n; vArray( F* _, size_t n ) : _( _ ) , n( n ) { } __host__ __device__ F& ...
18,267
// Tests handling of CUDA attributes. // // RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s // Now pretend that we're compiling a C file. There should be warnings. // RUN: %clang_cc1 -DEXPECT_WARNINGS -fsyntax-only -verify -x c %s #if defined(EXPECT_WARNINGS) // ex...
18,268
#include "includes.h" __global__ void x3(int* x4, int x5, int x6) { int x7 = gridDim.x * blockDim.x; int x8 = threadIdx.x + blockIdx.x * blockDim.x; int x9 = -x5; while (x8 < x6) { int x10 = x8; if (x4[x10] > x5) x4[x10] = x5; if (x4[x10] < x9) x4[x10] = x9; x8 = x8 + x7; } }
18,269
#include<stdio.h> #include<stdlib.h> #define SIZE 1000 #define NUM_BLOCKS 10 #define THREADS_PER_BLOCK 100 __global__ void DotProd(int *a, int *b, int *c) { __shared__ int temp[THREADS_PER_BLOCK]; int x = threadIdx.x + blockDim.x * blockIdx.x; /*printf("Block ID :%d:\n", blockIdx.x); printf("Block Dim :%d:\n",...
18,270
/* Simple CUDA Example -- Williams */ #include <iostream> #include <math.h> #include <stdio.h> // __global__ means this function is available on CPU and GPU // This version does NOT print any data out for debugging __global__ void scale(unsigned int n, float *x, float *y) { unsigned int i, base=blockIdx.x*blockDim...
18,271
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> #include<thrust/device_vector.h> #include<thrust/host_vector.h> const int TGM_VALUE_BASE = 5; const int TGM_VALUE_CB = TGM_VALUE_BASE * TGM_VALUE_BASE * TGM_VALUE...
18,272
#include <stdio.h> #include <math.h> const double N = 16; __global__ void exp(double* d_in, double *d_exp) { unsigned idx = blockIdx.x * blockDim.x + threadIdx.x; // map function: exp(xi) d_exp[idx] = exp(d_in[idx]); } __global__ void sum(double *d_exp, double *d_sum) { // reduction function: sum(exp(x)) ...
18,273
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include "cuda.h" #include <string.h> #define MAXBLOCKSIZE 512 int Size; float *a, *b, *FinalArray; float *m; void ForwardFunction(); void BackwardSubstitution(); //void MultiplierMatrix(float *m, float *a, int Size, int t); //void ForwardEliminate(float ...
18,274
// System includes #include <stdio.h> #include <assert.h> // CUDA runtime #include <cuda.h> #include <cuda_runtime.h> __global__ void vectorAddGPU(float *a, float *b, float *c, int N) { int idx = blockIdx.x*blockDim.x + threadIdx.x; if (idx < N) { c[idx] = a[idx] + b[idx]; } } void unified_sampl...
18,275
#include "includes.h" __global__ void GetOutLod(const size_t* num_erased, const size_t* in_lod, const size_t lod_len, size_t* out_lod0) { int index = blockIdx.x * blockDim.x + threadIdx.x; if (index < lod_len) { out_lod0[index] = in_lod[index] - num_erased[in_lod[index]]; } }
18,276
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N 10000000 #define TPB 256 #define ATOMIC 1 // 0 for non-atomic addition double cpuSecond() { struct timeval tp; gettimeofday(&tp, NULL); return ((double)tp.tv_sec + (double)tp.tv_usec*1.e-6); } __global__ void dotKernel(int *d_res, const int *d...
18,277
#include<stdio.h> #include<stdint.h> __global__ void saxpy(int32_t *tab, int32_t N, int32_t a, int32_t b); int main(int argc, char const *argv[]) { int32_t N = (int32_t) atoi(argv[1]); int32_t a = (int32_t) atoi(argv[2]); int32_t b = (int32_t) atoi(argv[3]); int32_t N_threads = (int32_t) atoi(argv[4]); int...
18,278
#include <iostream> #include <fstream> #include <math.h> #include <limits> #include "cuda_runtime.h" #include <curand_kernel.h> #include <curand.h> #include "device_launch_parameters.h" __constant__ float maxDistance = 3.40282346639e+38f; using namespace std; const int width = 1280; const int height = 720; int samp...
18,279
#include <cstdio> #include <cstdlib> #include <math.h> #include <sys/time.h> // get time of day #include <sys/times.h> // get time of day #include <sys/mman.h> // mmap #include <unistd.h> // getpid #include <cuda.h> // Assertion to check for errors #define CUDA_SAFE_CALL(ans) { gpuAssert((ans), __FILE__, __LINE__);...
18,280
#include "includes.h" __global__ void saxpy(int * a, int * b, int * c) { int tid = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; for (int i = tid; i < N; i += stride) { c[i] = 2 * a[i] + b[i]; } }
18,281
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <arpa/inet.h> #include <math.h> #include "cs_cuda.h" #include "cs_dbg.h" #include "cs_helper.h" #include "cs_copy_box.h" // #define CUDA_DBG // #define CUDA_DBG1 // ex...
18,282
/** cudacal.h Purpose: a simple CUDA example @author Fan Gong @version 1.0 07/03/18 */ #include <stdexcept> /** device code to calculate sqr of x. In CUDA, device code is prefixed with "__device__", which only runs in GPU. It can only be called by other device code or kernel code. Sometimes...
18,283
#include <stdio.h> #include <math.h> #include <string.h> #define CSC(call) \ do { \ cudaError_t res = call; \ if (res != cudaSuccess) { \ fprintf(stderr, "ERROR: file:%s line:%d message:%s\n", \ __FILE__, __LINE__, cudaGetErrorString(res)); \ exit(0); \ } \ } while (0) #define DIM3 3 #define R 0 #define G ...
18,284
#include"cuda_runtime.h" #define MAX_THREADS_PER_BLOCK 512 #define VWARP_WIDTH 32 #define BATCH_SIZE 32 const int DEAFAULT_THREADS_PER_BLOCK=256; const int MAX_BLOCK_PER_DIMENSION=65535; /* *Global linear thread index */ #define THREAD_GLOBAL_INDEX (threadIdx.x+blockDim.x \ *(gridDim.x*bl...
18,285
#include <stdio.h> #include <cmath> #define BLOCK_SIZE 16 __global__ void LCS_kenel(int map_row, int map_col, const char *stringA, const char *stringB, int *map, int i) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; int cur_element = x + y * map_col; /...
18,286
#include<iostream> using namespace std; __global__ void addition(int *a, int*b, int n) { int tid=threadIdx.x; int sum=0; for(int i=0;i<n;i++) { sum+=a[i]; } b[tid]=sum; } int main() { int n=1000; int *a=(int*)malloc(n*sizeof(int)); cudaEvent_t start, end; for(int i=0;i<n;i++) { a[i...
18,287
#include "matrix.cuh" #include <stdexcept> #define THREAD_X 8 #define THREAD_Y 8 /** * @brief The cuda kernel to add two 2D matrices. * * @tparam T, the type of value to retrieve. * * @param[in] width, the width of the two matrices. * @param[in] height, the height of the two matrices. * @param[in] m, the first matr...
18,288
#include "includes.h" /* * CCL3D.cu */ #define CCL_BLOCK_SIZE_X 8 #define CCL_BLOCK_SIZE_Y 8 #define CCL_BLOCK_SIZE_Z 8 __device__ int d_isNotDone; __global__ void scanLabels(int* labels, int w, int h, int d) { const int x = blockIdx.x * CCL_BLOCK_SIZE_X + threadIdx.x; const int y = blockIdx.y * CCL_BLOCK_SIZE_Y...
18,289
/* Benchmark that calculate the integral of F(x) over the interval [A,B] */ #include <stdio.h> #define NUM_INTERVALS 1000000 #define F(x) (x)*(x) #define A 0 #define B 10 #define CUDA_BLOCK_X 128 #define CUDA_BLOCK_Y 1 #define CUDA_BLOCK_Z 1 __global__ void _auto_kernel_0(float arr[1000000],float delta) { int thread...
18,290
// REQUIRES: x86-registered-target // REQUIRES: amdgpu-registered-target // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -o - -fcuda-is-device -x hip %s | FileCheck --check-prefix=DEV %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -x hip %s | FileCheck --check-prefix=HOST %s // DEV-NOT: llvm.de...
18,291
#include "includes.h" __global__ void update_postsynaptic_activities_kernel( float timestep, size_t total_number_of_neurons, float * d_recent_postsynaptic_activities_D, float * d_last_spike_time_of_each_neuron, float current_time_in_seconds, float decay_term_tau_D, float model_parameter_alpha_D) { int idx = threadIdx....
18,292
#include "includes.h" __global__ void extracunn_MSSECriterion_updateOutput_kernel(float* output, float *input, float *target, int nframe, int dim) { __shared__ float buffer[MSSECRITERION_THREADS]; int k = blockIdx.x; float *input_k = input + k*dim; float *target_k = target + k*dim; int i_start = threadIdx.x; int i_end...
18,293
/* Example from "Introduction to CUDA C" from NVIDIA website: https://developer.nvidia.com/cuda-education Compile with: $ nvcc example_intro.cu */ #include <stdio.h> #include <stdlib.h> #include <cuda.h> const int side = 16; const int N = side*side; const int THREADS_PER_BLOCK = N; /* While d...
18,294
#include <stdio.h> #include <iostream> #include <cuda_runtime.h> int main() { int devices; cudaDeviceProp prop; try { cudaGetDeviceCount(&devices); for(int device = 0; device < devices; device++) { cudaGetDeviceProperties(&prop, device); std::cout << "Device Number ...
18,295
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <assert.h> #ifndef THREADS_PER_BLOCK #define THREADS_PER_BLOCK 1024 #endif #define CUDA_ERROR_CHECK #define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) inline void __cudaSafeCall( cudaError err, const char *file, const int line )...
18,296
#include "includes.h" __global__ void sortVerifyKernel(uint *d_DstKey, uint *d_DstVal, uint *d_SrcKey, uint *errNum) { uint idx = blockIdx.x * blockDim.x + threadIdx.x; uint iterator; #pragma unroll for (iterator = 0; iterator < THREAD_SIZE; iterator++) if ((d_SrcKey[d_DstVal[idx*THREAD_SIZE + iterator]] != d_DstKey[i...
18,297
#include <stdio.h> #define CSC(call) do { \ cudaError_t res = call; \ if (res != cudaSuccess) { \ fprintf(stderr, "CUDA Error in %s:%d: %s\n", __FILE__, __LINE__, cudaGetErrorString(res)); \ exit(0); \ } \ } while (0) __global__ void kernel(double* da, double* db, int n) { int offset = blockDim.x * gridDim.x;...
18,298
// SDSC Summer Institute 2018 // Andreas Goetz (agoetz@sdsc.edu) // CUDA program that performs 1D stencil operation in parallel on the GPU // #include<stdio.h> // define vector length, stencil radius, #define N (1024*1024*8l) #define RADIUS 3 #define GRIDSIZE 128 #define BLOCKSIZE 256 // --------------------------...
18,299
/** * Base on example codes of CUDA Documentation * https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared-memory **/ #include <stdio.h> #include <stdlib.h> #define BLOCK_SIZE 16 typedef struct { int width; int height; int stride; float* elements; } Matrix; // Get a matrix element _...
18,300
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <string.h> #include <math.h> #define N 4 //Filas #define M 4 //Columnas __global__ void sumaMatrices(float *c, float *a, float *b){ //Kernel, salto a la GPU. Esta funcion es ejecutada por todos los hilos al mismo tiempo. int i = (blockIdx.y*blockDim....