serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
6,101
#include <assert.h> //#include <sys/time.h> #include <time.h> #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <algorithm> using std::cout; using std::endl; using std::cerr; #define DECLINE_HORIZONTAL 0.1 #define DECLINE_VERTICAL 0.1 #define STEPS 1000 /...
6,102
 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <algorithm> #include <cstdlib> int main1() { // generate 100 random numbers...
6,103
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/transform_reduce.h> #include <thrust/functional.h> #include <thrust/extrema.h> #include <thrust/random.h> #include <iostream> #include <cuda.h> #include <cuda_fp16.h> template <typename T> struct asum_amax_type { T asum_val; T ama...
6,104
#include "PiecewiseConstant.cuh" inline CUDA_FUNC float rgb2y_xyz(const float3 &rgb) { return rgb.x + 4.5906f * rgb.y + 0.06007 * rgb.z; } CUDA_FUNC Distribution::Distribution(int num, float *v) : n(num) { value = new float[n]; memcpy(value, v, sizeof(float) * n); cdf = new float[n + 1]; cdf[0] = ...
6,105
#include <stdio.h> // includes CUDA Runtime #include <cuda_runtime.h> int main(int argc, char *argv[]) { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("Device Number: %d\n", i); ...
6,106
#include <stdio.h> #include <math.h> #include <assert.h> __global__ void partial_sum(long num, double *out) { int x = threadIdx.x + blockIdx.x * blockDim.x, y = threadIdx.y + blockIdx.y * blockDim.y, index = x + y*blockDim.x*gridDim.x; double sum = 0.0; double cur = index*num + 1; for (...
6,107
#define __rose_lt(x,y) ((x)<(y)?(x):(y)) #define __rose_gt(x,y) ((x)>(y)?(x):(y)) #define D__(solventMol) D_[solventMol] __global__ void Action_No_image_GPU(double *D_,double *maskCenter,double (*SolventMols_)[1024][3]); //this is only used for cuda-chill //heavy simplification #define NsolventMolecules_ 1024 #define ...
6,108
#include "includes.h" __device__ void warpReduce(volatile int* sdata, int tid, int n) { if(tid + 32 < n) sdata[tid] += sdata[tid+32]; if(tid + 16 < n) sdata[tid] += sdata[tid+16]; if(tid + 8 < n) sdata[tid] += sdata[tid+8]; if(tid + 4 < n) sdata[tid] += sdata[tid+4]; } __global__ void ReduceRowMajor5(int *g_idata, int ...
6,109
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,float var_2,float var_3,float var_4,float var_5,float var_6,float var_7,int var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float va...
6,110
#include "includes.h" __global__ void inclusive_scan(const unsigned int *input, unsigned int *result) { extern __shared__ unsigned int sdata[]; unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; // load input into __shared__ memory unsigned int sum = input[i]; sdata[threadIdx.x] = sum; __syncthreads(); for(int o...
6,111
// CUDA programming // Exercise n. 09 #include <errno.h> #include <cuda.h> #include <stdio.h> #define BLOCKS 2 #define THREADS 2 // Prototypes __global__ void square_matrix_transpose(int *d_X, int *d_Y, int N); __host__ void ints(int *m, int N); __host__ void print_matrix(int *A, int N); int main(void) { int *...
6,112
//Cuda hello world #include<stdio.h> #define N 10 #define THREADS_PER_BLOCK 1 #define BLOCK_SIZE THREADS_PER_BLOCK // calculation of loss __global__ void cal_loss(float *err, float *label, int n){ printf("threadIdx:(%d) blockIdx:(%d)\n " , threadIdx.x, blockIdx.x); const int pos = blockIdx.x * blockDim.x + threadI...
6,113
#include <chrono> #include <iostream> #include <math.h> typedef std::chrono::high_resolution_clock Clock; #define NUM_THREADS_IN_BLOCK 256 __global__ //runtime GPU 195.58us //runtime CPU 3015 microseconds void daxpyGPU(int arraySize, float *a, float *b, float *c, float *result) { int index = blockIdx.x * blockD...
6,114
#include "basic_conv.cuh" #include "assert.h" #include "real.h" #include <iostream> void trial(){ constexpr int asize=10^5; constexpr int bsize=1000; real A[asize]; for(int i=0; i< asize; i++){ A[i]=1; } real M[bsize]; for (int i=0; i<bsize; ++i){ M[i]=i; } real P[asize]; basic_conv(A,M,P,bsize,asize);...
6,115
#include <stdio.h> #include <stdlib.h> #include <curand_kernel.h> // Device code __global__ void MyKernel() { //int idx = threadIdx.x + blockIdx.x * blockDim.x; } // Host code int main() { int blockSize; // The launch configurator returned block size int minGridSize; // The minimum grid size needed to achieve th...
6,116
#include "includes.h" extern "C" { } __global__ void updateEst(int N, int M, float beta2, float scale, float *PARAMS, float *AVG, float *EST) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; int index = j*N + i; float beta2a = __fsub_rn(1.0, beta2); if (i < N...
6,117
#include <stdio.h> #include <cuda.h> #include <sys/time.h> #define N 1024*1024 //array size __global__ void read_alloc_kernel1(int *A, int *B, int *time){ int x1, x2, x3, x4, x5, x6, x7, x8, x9; int t0, t1, t2, t3, t4, t5; t0 = clock(); x1 = A[64]; x2 = A[1088]; x3 = A[2144]; ...
6,118
//////////////////////////////////////////////////////////////////////////// // // Copyright 1993-2015 NVIDIA Corporation. All rights reserved. // // Please refer to the NVIDIA end user license agreement (EULA) associated // with this source code for terms and conditions that govern your use of // this software. Any u...
6,119
#include "includes.h" __global__ void gpuIt3(float *tNew,float *tOld,float *tOrig,int x,int y,int z,float k,float st) { int i = threadIdx.x + blockIdx.x * blockDim.x; if(i < x*y*z){ if(i == 0){ // front upper left corner tNew[i] = tOld[i]+k*(tOld[i]+tOld[i+(x*y)]+tOld[i]+tOld[i+x]+tOld[i]+tOld[i+1]-6*tOld[i]); //tNew[...
6,120
#include "includes.h" __global__ void selection_k_radius_gpu(int b, int m, int k, float radius, const int* idx, const float* val, int* idx_out, float* val_out){ int batch_index = blockIdx.x; int stride = batch_index * m * k; idx += stride; val += stride; idx_out += stride; val_out += stride; for(int i = threadIdx.x; i ...
6,121
// Assignment 1: ParallelSine // CSCI 415: Networking and Parallel Computation // Spring 2017 // Name(s): // // Sine implementation derived from slides here: http://15418.courses.cs.cmu.edu/spring2016/lecture/basicarch // standard imports #include <stdio.h> #include <math.h> #include <iomanip> #include <iostream> #i...
6,122
#include "includes.h" #define FALSE 0 #define TRUE !FALSE #define NUMTHREADS 16 #define THREADWORK 32 __global__ void noNAsPmccMeans(int nRows, int nCols, float * a, float * means) { int col = blockDim.x * blockIdx.x + threadIdx.x, inOffset = col * nRows, outOffset = threadIdx.x * blockDim.y, j = outOffset + t...
6,123
#include <stdio.h> #include <time.h> #include <iostream> #include <vector> #include <math.h> #include <fstream> void checkCUDAError(const char *msg); #include <cuda_runtime.h> using namespace std; // --------------------INPUT DATA--------------------- const int Nx = 24, Ny = 120, Nz = 20; // Number of mass points fl...
6,124
# include<stdio.h> __global__ void print_thread_ids() { printf("threadIdx.x: %d, threadIdx.y: %d, threadIdx.z: %d <-> blockIdx.x: %d, blockIdx.y: %d, blockIdx.z: %d <-> blockDim.x: %d, blockDim.y: %d, blockDim.z: %d <-> gridDim.x: %d, gridDim.y: %d, gridDim.z: %d\n", threadIdx.x, threadIdx.y, threadIdx.z, blo...
6,125
#pragma once #ifndef BLOCK_MATCHING_KERNEL #define BLOCK_MATCHING_KERNEL #define INDXs(s,i,j) ((s) * (i) + (j) + 0) __device__ double computeMatchKernel(unsigned char *im, int im_step, unsigned char *bl, int bl_step, int bl_cols, int bl_rows, int oi, int oj, int stri...
6,126
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "device_functions.h" //#include<stdio.h> #include<assert.h> /*------------------------------------------------------------------------------------------*/ /** * * * */ /*-----------------------------------------------------------------------------...
6,127
#include "includes.h" __global__ void SumCentroids(float* delta, float* sumDelta, int numOfCentroids, int numOfElements) { int id = blockDim.x * blockIdx.y * gridDim.x + blockDim.x * blockIdx.x + threadIdx.x; if (id < numOfCentroids * NUM_SUMS) { float sum = 0; for (int i = 0; i < numOfElements; i++) { sum += delta[n...
6,128
#include <stdio.h> #include <stdlib.h> #include <algorithm> #define BLOCK_SIZE 256 __global__ void dot(int numElements, const float3* a, const float3* b, float* c) { int i = threadIdx.x + blockIdx.x*blockDim.x; if (i < numElements) { c[i] = a[i].x*b[i].x + a[i].y*b[i].y + a[i].z*b[i].z; } } i...
6,129
#include <stdio.h> #include <cuda_runtime.h> #define threadsPerBlock 512 //Device code __global__ void calculateCCoeff(const int* AdjMatrix, int numElements, float* globalSum) { __shared__ float local[threadsPerBlock]; int i = threadIdx.x + blockIdx.x * blockDim.x; if(i < numElements) { in...
6,130
/* This program takes a matrix transpose using shared memory. * It takes care of memory coalescence as both memory read and memory write are * coalesced by accessing in colum major. * It takes care of bank conflicts by padding the shared memory by 1 to get optimum performance. * There is no thread divergence in the...
6,131
/* * Copyright 1993-2015 NVIDIA Corporation. All rights reserved. * * Please refer to the NVIDIA end user license agreement (EULA) associated * with this source code for terms and conditions that govern your use of * this software. Any use, reproduction, disclosure, or distribution of * this software and related...
6,132
#include<iostream> #include <fstream> #include <string> #include <stdio.h> #include <stdlib.h> using namespace std; __global__ void kernel( float* r_gpu, float* g_gpu, float* b_gpu, int N) { int tId = threadIdx.x + blockIdx.x * blockDim.x; if(tId < N) { r_gpu[tId] = 1 - r_gpu[tId]; g_gpu[tId] = 1 - g_gpu[tI...
6,133
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,float var_2,float var_3,float var_4,float 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 ...
6,134
#include "includes.h" __constant__ float *c_Kernel; __global__ void average(float *d_ip_v, float *d_ip_ir, int app_len) { const int X = blockIdx.x * blockDim.x + threadIdx.x; if (X < app_len) { d_ip_v[X] = (d_ip_v[X] + d_ip_ir[X]) / 2; } }
6,135
#include "includes.h" __global__ static void findNew(double* cCurr, double* cBar, double* cHalf, int nx) { // Matrix index int globalIdx = blockDim.x * blockIdx.x + threadIdx.x; int globalIdy = blockDim.y * blockIdx.y + threadIdx.y; // Set index being computed int index = globalIdy * nx + globalIdx; // Recover the ne...
6,136
#include <iostream> using namespace std; __global__ void multiply(int *ad, int *bd, int *cd, int n) { int row = blockIdx.x ; int col = blockIdx.y ; int sum = 0; for (int i = 0; i < n; i++) { sum = sum + ad[row * n + i] * bd[i * n + col]; } cd[row * n + col] = sum; } int main() { cout << "Enter the si...
6,137
#include <stdio.h> #include <time.h> #include<math.h> void load_matrix_from_file(FILE * file, int nb_rows,int nb_cols, double* mat){ for(int i = 0; i < nb_rows; i++){ for(int j = 0; j < nb_cols; j++){ //Use lf format specifier, %c is for character ...
6,138
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> __global__ void someKernel(int N) { int idx = blockIdx.x*blockDim.x + threadIdx.x; if (idx<N) printf("Hello from thread # %i (block #: %i)\n", idx, blockIdx.x); } extern void cuda_doStuff(void) { int numberOfBlocks = 2; int threadsPerBlock = 5; in...
6,139
#include <iostream> #include <unistd.h> #include <sys/time.h> #define tile_width 32 __global__ void normal_square_matrix_mult_kernel(int *m, int *n, int *p, unsigned width){ unsigned col = threadIdx.x+(blockIdx.x*blockDim.x); unsigned row = threadIdx.y+(blockIdx.y*blockDim.y); if(col<width and row<width){ int p...
6,140
#include <stdlib.h> #include <thrust/device_ptr.h> #include <thrust/device_vector.h> #include <thrust/scan.h> #include <pthread.h> #include "cuda_runtime.h" #include <stdio.h> #include <tgmath.h> #include <sys/time.h> #include <assert.h> extern "C" { void threshold_ecg(float * output1, float * ...
6,141
// // fast_transpose.cu // // // Created by Laura Balasso on 13/05/2019. // #include <stdio.h> #include <stdlib.h> #define TILE_DIM 32 /* function that fills an array with random doubles */ void random_doubles(double *p, int n) { int i; for(i=0; i<n; i++) { p[i]= ( (double)rand() * 100 ) / (double...
6,142
#include "stdio.h" __global__ void cuda_hello(){ printf("Hello World! My thread ID is %d\n\n", threadIdx.x); } int main() { cuda_hello<<<1,256>>>(); cudaError_t cudaerr = cudaDeviceSynchronize(); if (cudaerr != cudaSuccess) printf("kernel launch failed with error \"%s\".\n", ...
6,143
#include <iostream> #include <stdio.h> #define checkCudaError(status) { \ if(status != cudaSuccess) { \ std::cout << "CUDA Error " << __FILE__ << ", " << __LINE__ \ << ": " << cudaGetErrorString(status) << "\n"; \ exit(-1); \ } \ } __global__ void vecAdd(int * a, int * b, int * c, int size) { //ADD CODE HE...
6,144
/* * usage: nvcc ./stream_test.cu -o ./stream_legacy * nvvp ./stream_legacy ( or as root: * nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java ./stream_legacy ) * ... versus ... * nvcc --default-stream per-thread ./stream_test.cu -o ./stream_per-thread *...
6,145
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <cuda_runtime.h> //#define B_T //#define DEBUG #define L1 1024 #define L2 1024 #define L3 1024 #define TILE_WIDTH 32 /* ========== Multiple block, Multiple threads ========== */ /* ========== Tile multiplication ========== */ /* ========== Can ch...
6,146
#include <cmath> #include <cstdlib> #include <iostream> #include <fstream> #include <cassert> #include <chrono> #include <random> #include <string> #include <ctime> #include <algorithm> #include <fcntl.h> #include <unistd.h> //constants #define TRAINING_SET_SIZE 60000 #define TEST_SET_SIZE 10000 #define COLS 28 #defin...
6,147
#include <stdio.h> #include <stdlib.h> #include <time.h> __device__ float logsumexp(float a, float b) { if(a > b) { return a + log(1.0+exp(b-a)); } else { return b + log(1.0+exp(a-b)); } } /* __global__ void felsensteinfast(const int alphabet, const int numcols, const int numnodes, const int startnode, cons...
6,148
/* Cource - "Разработка приложений на CUDA " Task 1: Выделить на GPU массив arr из 10^9 элементов типа float и инициализировать его с помощью ядра следующим образом: arr[i] = sin((i%360)*Pi/180). Скопировать массив в память центрального процессора и посчитать ошибку err = sum_i(abs(sin((i%360)*Pi...
6,149
#ifndef picket_fence_cuda #define picket_fence_cuda #pragma once #include <cuda_runtime.h> #include <math.h> //////// kernel version /////////////////////////////////////////// // Calculates the IR band Rosseland mean opacity (local T) according to the // Freedman et al. (2014) fit and coefficents __...
6,150
#include <math.h> void getRowsNnzPerProc(int *rowsPP, int *nnzPP, const int *global_n, const int *global_nnz, const int *row_Ptr) { int worldSize=1; double nnzIncre = (double) *global_nnz/ (double) worldSize; double lookingFor=nnzIncre; int startRow=0, endRow; int partition=0; for (int row=...
6,151
#include <stdio.h> #include <stdlib.h> bool verify(int data[], int length) { for (int i = 1 ; i < length; ++i) { if (data[i] - data [i - 1] != i ) { printf("error %d\n", i); return false; } } return true; } #define DUMP(x) printf("%s %d\n", #x, props.x) void dumpCUDAProps(cudaDeviceProp & props) { DUMP(canM...
6,152
#include <iostream> #include <cuda.h> using namespace std; __global__ void reduce_kernel(const int* g_idata, int* g_odata, unsigned int n) { extern __shared__ int shared_arr[]; int *sdata = shared_arr; unsigned int idx = blockIdx.x*blockDim.x + threadIdx.x; unsigned int tidx = threadIdx.x; if(idx < n) { sdata...
6,153
namespace fastertransformer { const unsigned int WARP_REDUCE_MASK = 0xffffffff; const float CUDA_FLOAT_INF_NEG = -100000000.f; const unsigned int WARP_SIZE = 32; template <typename T> __forceinline__ __device__ T warpReduceMax(T val) { for (int mask = (WARP_SIZE >> 1); mask > 0; mask >>= 1) val = max(val, __sh...
6,154
#include <unistd.h> #include <sys/stat.h> #include <string.h> int main(int argc, char **argv) { unsigned short newmode; int i, er=0; newmode = 0666 & ~umask(0); for (i = 1; i < argc; i++) { // The first line below mith mkfifo is used in the GNU version but there is no mkfifo call in elks libc yet /*if (mkfif...
6,155
#include <stdlib.h> #include <string.h> #include <sys/time.h> #include <time.h> #include <stdio.h> #include <cuda_runtime.h> #define CHECK(call) \ { \ const cudaError_t error ...
6,156
__global__ void conv8(int *inp, int *out) { int i; int sum = 0; do { sum += inp[i]; i++; } while(i < inp[threadIdx.x]); __syncthreads(); out[0] = sum; }
6,157
__global__ void ftcsKernel(float *Cxn, float *Cyn, float *Cxo, float *Cyo, float *diffu,float *diffd,float *diffl, float *diffr, float *T2val, float Adx, int dimX) { int x = threadIdx.x + blockDim.x*blockIdx.x;// place in x dim int y = blockIdx.y; // place in y dim int ind = x+y*dimX; // current index in...
6,158
#include<stdio.h> #include<cuda.h> # define N 10000 __global__ void add( int * a, int *b, int *c) { unsigned int y= blockDim.x *blockIdx.x + threadIdx.x; if(y<N) c[y]=a[y]+b[y]; } int check(int *a, int *b, int *c) { for(int i=0;i<N;i++) { if(c[i] !=a[i]+b[i]) return 0; } return 1; } int main() { int *h...
6,159
#include <stdio.h> __global__ void modifyArray (int *modArray) { int i = threadIdx.x; modArray[i] = modArray[i] + 100; } __host__ int main (void) { int lenArray = 10; int *modArray, *gpu_modArray; size_t sizeArray; sizeArray = lenArray * sizeof(int); modArray = (int*) mall...
6,160
#include "includes.h" __global__ void addKernel(float *c, float *a, float *b, int size) { int i = blockIdx.x * blockDim.x *blockDim.y + blockDim.x * threadIdx.y * threadIdx.x; while(i < size) { c[i] = a[i] + b[i]; i += gridDim.x * blockDim.x * blockDim.y; } }
6,161
#include <iostream> #include <array> #include <fstream> #include <vector> #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <thrust/device_new.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/extrema.h> using host_buffer=thrust::host_vector<float>; using de...
6,162
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #define N 512 #define MAX_ERR 1e-6 //__global__ void vector_add(float *out, float *a, float *b, int n) { // int stride = 1; // int tid = blockIdx.x * blockDim.x + threadIdx.x; // 0...
6,163
#include "kernel.cuh" namespace gpu { __global__ void addKernel(int *c, const int *a, const int *b) { int i = threadIdx.x; c[i] = a[i] + b[i]; } // 使用CUDA并行添加矢量的辅助函数。 cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size) { int *dev_a = 0; int *dev_b = 0; int *dev_c = 0; cu...
6,164
extern "C" __global__ void createKernels( float* kernels, int size, int nrOfOrientations, int nrOfScales, float sigma_min, int N) { int index = threadIdx.x + blockIdx.x * blockDim.x; int orientation = threadIdx.x; int scale = blockIdx.x; if (index < N) { int s2 = size / 2; int nn = ...
6,165
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #define COMMENT "Histogram_GPU" #define RGB_COMPONENT_COLOR 255 #define HISTOGRAM_SIZE 64 #define TILE_WITDH 16 typedef struct { unsigned char red, green, blue; } PPMPixel; typedef struct { int x, y; PPMPixel *data; } PPMImag...
6,166
#include "includes.h" __global__ void scale_centroids(int d, int k, int* counts, double* centroids) { int global_id_x = threadIdx.x + blockIdx.x * blockDim.x; int global_id_y = threadIdx.y + blockIdx.y * blockDim.y; if ((global_id_x < d) && (global_id_y < k)) { int count = counts[global_id_y]; //To avoid introducing ...
6,167
/* Print Hello World also print the block id and thread id within the block */ #include <stdio.h> const int Nthread = 3; const int Nblock = 2; __global__ void hello(void){ printf("Hello world! block ID %d, thread ID %d\n",blockIdx.x,threadIdx.x); } int main() { hello<<<Nblock,Nthread>>>(); }
6,168
#include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/fill.h> #include <thrust/transform.h> #include <iostream> template <typename T> class saxpy : public thrust::binary_function<T, T, T> { private: T factor; public : __host__ __device__ saxpy(const T& factor) : factor(factor){} ...
6,169
#include <cuda_runtime.h> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #define THREAD_SIZE 256 using namespace std; void matgen(float* a, int lda, int n) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { a[i * lda + j] = (float)rand() / RAND_MAX + (float)rand() / (RA...
6,170
#include "includes.h" __global__ void initialSpikeIndCopyKernel( unsigned short* pLastSpikeInd, const unsigned int noReal) { unsigned int globalIndex = threadIdx.x+blockDim.x*blockIdx.x; unsigned int spikeNo = globalIndex / noReal; if (globalIndex<noReal*noSpikes) { pLastSpikeInd[globalIndex] = pLastSpikeInd[spikeNo*no...
6,171
#include <stdio.h> #include <math.h> #include <time.h> #include <cuda.h> //Code written by Alan Fleming //CONSTANTS #define MATRIXSIZE 8 #define BLOCKSIZE 4 void mul_matrix_cpu(float *M, float *N, float *P, int width){ for( int i = 0; i<width; i++){ for( int j = 0; j<width; j++){ float sum = 0; for (int k = ...
6,172
#include "includes.h" __global__ void matrixMultiKernel(float *C, float *A, float *B, int Width) { const int BLOCK_SIZE = 16; // NOTE: This must be similar to line 338 // block indexes int bx = blockIdx.x; int by = blockIdx.y; // thread indexes int tx = threadIdx.x; int ty = threadIdx.y; // int col = bx * TILE_WIDTH...
6,173
#include "includes.h" __global__ void matrixMultiply(float * A, float * B, float * C, int numARows, int numAColumns, int numBRows, int numBColumns, int numCRows, int numCColumns) { //@@ Insert code to implement matrix multiplication here __shared__ float ds_A[TILE_WIDTH][TILE_WIDTH]; __shared__ float ds_B[TILE_WIDTH][T...
6,174
#include "includes.h" //---------------------------------------------------------------------------------------------------------------------- /// @file CudaSPHKernals.cu /// @author Declan Russell /// @date 08/03/2015 /// @version 1.0 //----------------------------------------------------------------------------------...
6,175
#include <iostream> #include <stdlib.h> #include <cuda_runtime.h> using namespace std; template<typename T> T* flatten(T** M, int mWidth,int mHeight){ T* result = (T*)malloc((mWidth*mHeight)*sizeof(T)); for(int i = 0; i < mHeight; i++){ memcpy(result + (i*mWidth),M[i],(mWidth*sizeof(T))); } ...
6,176
// Liam Wynn, 3/23/2021, CUDA Learning /* * Demo taken from Kirk & Hwu's Programming Massively Parallel Processors, Third Edition. * * To compile do: * nvcc vec_add.cu * * You may get an error about a lack of Microsoft Visual Studio or whatever. In that case * do: * * nvcc -allow-unsupported-compiler vec_add....
6,177
#include "includes.h" /* * CudaOperations.cu * * Created on: Feb 6, 2019 * Author: alexander */ __global__ void cudaKernelPull(float* mat, float* spins, int size, float* temp, float tempStep, float* meanFieldElements, bool* continueIteration, float minDiff, int* unemptyCells, float linearCoef) { int blockId = b...
6,178
#include "includes.h" __global__ void kern_MinBuffers(float* b1, float* b2, int size) { int idx = CUDASTDOFFSET; float value1 = b1[idx]; float value2 = b2[idx]; float minVal = (value1 < value2) ? value1 : value2; if( idx < size ) { b1[idx] = minVal; } }
6,179
#include "includes.h" using namespace std; __device__ void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } __global__ void sort(int *d_arr, int n, bool isEven) { int i; if (isEven) { i = threadIdx.x * 2; } else { i = threadIdx.x * 2 + 1; } if (i < n -1) { if (d_arr[i] > d_arr[i + 1]) { swap(&d_arr[i], &d...
6,180
/* ============================================================================ Name : SpikeSorting.cu Author : John Version : Copyright : Description : CUDA compute reciprocals ============================================================================ */ #include <iostream> #include <nume...
6,181
/*-----------------------------------------------------------*/ /* Block Sorting, Lossless Data Compression Library. */ /* Sort Transform (GPU version) */ /*-----------------------------------------------------------*/ /*-- This file is a part of bsc and/or libbsc, a program and a...
6,182
#include "includes.h" __global__ void cunn_SpatialLogSoftMax_updateOutput_kernel(float *output, float *input, int classSize, int height, int width) { int batchIndex = blockIdx.x; int index = threadIdx.x; while (index < height*width) { int y = index / width; int x = index % width; if (y >= height) break; // calculate ...
6,183
#include <iostream> int testKernel(); namespace DOKTests { void buildAndPrint(); void testSlicing(); void testConversionToCSR(); void testConversionToELL(); } namespace CSRTests { void spMVTest(); } namespace ELLTests { void buildAndPrintMatrix(); void spMVTest(); } namespace CusparseCSRTests { void cusparseTest(); vo...
6,184
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #define COMMENT "Histogram_GPU" #define RGB_COMPONENT_COLOR 255 typedef struct { unsigned char red, green, blue; } PPMPixel; typedef struct { int x, y; PPMPixel *data; } PPMImage; double rtclock() { struct timezone Tzp; struc...
6,185
#include "includes.h" __device__ float Hue_2_RGB_gpu( float v1, float v2, float vH ) //Function Hue_2_RGB { if ( vH < 0 ) vH += 1; if ( vH > 1 ) vH -= 1; if ( ( 6 * vH ) < 1 ) return ( v1 + ( v2 - v1 ) * 6 * vH ); if ( ( 2 * vH ) < 1 ) return ( v2 ); if ( ( 3 * vH ) < 2 ) return ( v1 + ( v2 - v1 ) * ( ( 2...
6,186
#include <cstdio> #include <stdio.h> #define SIZE 256*1024*64 __global__ void input(int *a, int *b) { int i=blockIdx.x*blockDim.x + threadIdx.x; a[i]=b[i]; } int main(void) { int *arr; int *arr2; int *carr=0; int *carr2=0; arr= (int *)malloc(sizeof(int)*SIZE); arr2= (int *)malloc(sizeof(int)*SIZE); for(int...
6,187
__global__ void tsortSmall(int *input0,int *result0){ unsigned int tid = threadIdx.x; unsigned int bid = blockIdx.x; extern __shared__ unsigned char sbase[]; (( int *)sbase)[(tid<<1)] = min(input0[((bid*512)+(tid<<1))],input0[((bid*512)+((tid<<1)^1))]); (( int *)sbase)[((tid<<1)^1)] = max(input0[((bid*512)...
6,188
#include <iostream> /** * @brief Perform general 1-D grid, 2-D block reduce, along X-direction. * * @details This device function implements the reduce algorithms. The grid is * in 1-D X-direction, i.e. `gridDim.x >= 1`,`gridDim.y == 1` and * `gridDim.z == 1`. The block is in 2-D X- and Y-direction, i.e. * `bloc...
6,189
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <chrono> using namespace std::chrono; // 0,0 0,1 0,2 // 1,0 1,1 1,2 // => 0, 1, 2, 3, 4, 5 // => numberOfColumns * currentRow + currentColumn __global__ void matrixmu...
6,190
#include "includes.h" __global__ void g_FullConnectWgrad(float* wgrad, float* w, int len, float lambda, int batch) { for(int i = 0; i < len; i += blockDim.x * gridDim.x) { int id = i + blockDim.x * blockIdx.x + threadIdx.x; if(id < len) { if(fabs(lambda) < 1e-10) wgrad[id] = wgrad[id] / batch /** dropM[id]*/; else wgra...
6,191
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N (1<<24) #define THREADS_PER_BLOCK 512 #define BLOCK_NUM (N + THREADS_PER_BLOCK - 1)/THREADS_PER_BLOCK // 1<<15 block void random_floats(float *x, int Num); __global__ void kernel1(float *a, float *b, float *out, int n); __global__ void kernel2Wit...
6,192
#include "includes.h" __global__ void update_bins(float *vec, int *bin, int *bin_counters, const int num_bins, const int n, const float slope, const float intercept) { unsigned int xIndex = blockDim.x * blockIdx.x + threadIdx.x; if ( xIndex < n ){ int bin_new_val; float temp = abs(vec[xIndex]); if ( temp > (intercept ...
6,193
#include "includes.h" __global__ void orthogonalize( float *eigvec, float *Qi_gdof, int cdof, int *blocksizes, int *blocknums, int largestblock ) { int blockNum = blockIdx.x * blockDim.x + threadIdx.x; // orthogonalize original eigenvectors against gdof // number of evec that survive orthogonalization int curr_evec = ...
6,194
#include "includes.h" /** Modifed version of knn-CUDA from https://github.com/vincentfpgarcia/kNN-CUDA * The modifications are * removed texture memory usage * removed split query KNN computation * added feature extraction with bilinear interpolation * * Last modified by Christopher B. Choy <chrischoy@ai...
6,195
#include<cuda_runtime.h> #include<stdio.h> #include<iostream> #include<thrust/host_vector.h> #include<thrust/device_vector.h> using namespace std; struct saxpy_functor { const float a; saxpy_functor(float _a): a(_a) {} __host__ __device__ float operator()(const float& x, const float& b) const { ...
6,196
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <ctime> #include <stdio.h> #include <iostream> #include <math.h> using namespace std; __global__ void MulKernel(int *c, const int *a, const int *b, const int P) { int tempsum=0; int row = blockIdx.y*blockDim.y + threadIdx.y; int co...
6,197
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void print_my_index() { int tid = threadIdx.x; int bid = blockIdx.x; printf("my id :%d , block_id :%d \n",tid,bid); } //int main() //{ // printf("hello from main \n"); // print_my_index << <2, 10 >> > (); // cudaDevice...
6,198
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #include <time.h> __global__ void mul(float *d_A, float *d_B, float *d_C, int n); void matMul(float **h_Mat1, float **h_Mat2, float **h_Mat3, int n); int main() { int n; int i, j; float **h_Mat1, **h_Mat2, **h_Mat3; p...
6,199
#include "includes.h" __global__ void rgbToGreyKernel(int height,int width ,unsigned char *input_img, unsigned char *output_img) { int col = blockIdx.x*blockDim.x + threadIdx.x; int row = blockIdx.y*blockDim.y + threadIdx.y; if(row<height && col<width) { int idx = row*width + col; float red = (float)input_img[3*idx]; ...
6,200
#include <iostream> #include <math.h> // Kernel function to add the elements of two arrays //Good Reference: http://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/docs/CUDA_C_Programming_Guide.pdf //Resource for multiply: https://github.com/sashasyedin/matrix-multiplication-with-cuda #include <cstdlib> #...