serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
3,101
extern "C" __global__ void fill(int * A, int cnt){ const int gap = blockDim.x*gridDim.x; for (int id = blockDim.x*blockIdx.x + threadIdx.x; id < cnt; id += gap) A[id] = id * 2; };
3,102
#include <cuda.h> #include <stdlib.h> #include <stdio.h> #include <iostream> #include "device_launch_parameters.h" #include "cuda_runtime.h" using namespace std; int main(int argc, char ** argv) { int deviceCount; cudaGetDeviceCount(&deviceCount); for (int dev = 0; dev < deviceCount; dev++) { c...
3,103
/* randgen.c => contains random number generator and related utilities including advance_random, warmup_random, random, randomize */ #include <stdio.h> #include <cstdlib> #include "type.cuh" /* GLOBAL VARIABLES */ double oldrand[56]; /* array of 55 random numbers */ int jrand; /* current random ...
3,104
#include "includes.h" char* concat(char *s1, char *s2); __global__ void r_calculation(float* a , int * indeces , float* b , float* x,float * r ,int size) { int index = blockDim.x * blockIdx.x + threadIdx.x ; if (index < size) { float sum = 0 ; for (int i = 0 ; i<3 ; i++) { sum += a[3*index + i] * x[indeces[3*...
3,105
#include "includes.h" __global__ void addValue(int * array_val, int*b_array_val) { int x = threadIdx.x; int sum = 0; for(unsigned int i = 0; i < ROWS; i++) { sum += array_val[i*COLUMNS+x]; } b_array_val[x] = sum; }
3,106
/****************************************************************************** * Eric Blasko * 6/02/19 * Homework #3 * RecMatMulTiled.cu * This program performs rectangle matrix multiplication, which uses shared mem * of size TILE_WIDTH x TILE_WIDTH. Values of Matrix M and N are chosen by the * user such that M is of ...
3,107
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N_size 16 //number of elements in array #define thread_number 4 //number of threads per block #define block_number 4 //number of blocks __global__ void prescan(float *gpu_outdata, float *gpu_indata, int n); void scanCPU(float *f_out, float...
3,108
#include "includes.h" __global__ void FullyConnectedEstimateLearningRateKernel( float *weightLearningRatePtr, float *biasLearningRatePtr, float *avgWeightGradPtr, float *avgBiasGradPtr, float *avgWeightGradVarPtr, float *avgBiasGradVarPtr, float *avgWeightGradCurvePtr, float *avgBiasGradCurvePtr, float *avgWeightGradCu...
3,109
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "curand_kernel.h" #include <cuda.h> #include <curand.h> #include <iostream> #include <numeric> using namespace std; const long steps = 1 << 21; __global__ void belongs_circle(double* x, double* y, double* result) { const int tid = blockIdx...
3,110
#include "includes.h" static const int n_el = 512; static const size_t size = n_el * sizeof(float); // declare the kernel function // function which invokes the kernel __global__ void kernel_sum(const float* A, const float* B, float* C, int n_el) { // calculate the unique thread index int tid = blockDim.x * blockIdx...
3,111
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <memory> #include "cuda_runtime.h" __global__ void add_two_vectors(int* v1, int* v2, int* result){ int idx = threadIdx.x; result[idx] = v1[idx] + v2[idx]; //printf("%i, ",result[idx]); } int main(int argc, char **argv) { int* v1_host = (int*)...
3,112
/*#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <opencv2/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgui.hpp> #include<opencv2\imgproc.hpp> #include <iostream> #define maxThreads 1023 #define maxBlocks 65534 #define imin(a,b)(a<b?a:b) __global__ void...
3,113
#include <limits> using namespace std; // Constantes const double MENOS_INFINITO = -numeric_limits<double>::max(); const size_t BLOCK_SIZE = 128; __device__ unsigned int contadorBloques = 0; __device__ double logaritmoDeterminante(double *g_L, const size_t k, const size_t numDimensiones) { double suma = 0.0; ...
3,114
#include "includes.h" __global__ void swap_middle_column(float* data, const int num_threads, const int nx, const int ny, const int xodd, const int yodd, const int offset) { const uint x=threadIdx.x; const uint y=blockIdx.x; const uint r = x+y*num_threads+offset; int c = nx/2; int idx1 = r*nx + c; int idx2 = (r+ny/2+yo...
3,115
#include "includes.h" __global__ void scatterSum(int N, float *input, float *output){ int i = blockIdx.x * blockDim.x + threadIdx.x; if(i >= N) return; for(int j=0;j<N;++j){ atomicAdd(output+j, input[i]); // if(i<N/2) atomicAdd(output+j, input[i]); // atomicAdd(output+j, i<N/2: input[i]: 0.); } return; }
3,116
/** * 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 relate...
3,117
#include <cstdio> __global__ void linearRegressionReducerKernel(const int * const keys, const float * const vals, const int * numVals, int * const keySpace, ...
3,118
#include <iostream> #include <fstream> #include <string.h> #include <time.h> #include <math.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> using namespace std; int index(int i) { return i + 1; } // Blocksize #define BLOCKSIZE 64 // Number of mesh points int n = 60000; //*************************...
3,119
#include <iostream> #include <string.h> #include <stdio.h> #include <math.h> using namespace std; __global__ void kernel(int* dval, int nword) { int tid = threadIdx.x; int bid = blockIdx.x; int i = blockDim.x*bid + tid; dval[i] = i; } int main( int argc, char** argv) { /* int nb = 65535; // max 65535 int...
3,120
#include "includes.h" __global__ void xMinDeltaIntegralReplicateKernel( const float *intData, float *tmpArray, const int nWindows, const int h, const int w, const float *xMin, const float *yMin, const float *yMax, const int strideH, const int strideW) { // TODO: use block dim instead const int hOut = (h + strideH - 1)...
3,121
#define COALESCED_NUM 16 #define blockDimX 16 #define blockDimY 1 #define gridDimX (gridDim.x) #define gridDimY (gridDim.y) #define idx (blockIdx.x*blockDimX+threadIdx.x) #define idy (blockIdx.y*blockDimY+threadIdx.y) #define bidy (blockIdx.y) #define bidx (blockIdx.x) #define tidx (threadIdx.x) #define tidy (threadIdx...
3,122
#include<iostream> #include<ctime> using namespace std; #define O1 __global__ void add(int *a,int*b,unsigned int n) { unsigned int tid = threadIdx.x; int *idata = a + blockIdx.x * blockDim.x; unsigned int idx = tid + blockIdx.x * blockDim.x ; if(idx >= n) { //printf("%d,",blockIdx.x); return; } //pr...
3,123
#include <cstdio> #include <cmath> #include <algorithm> #include <climits> #include <cuda_runtime.h> #include "CudaGillespie_cuda.cuh" /* Atomic-max function. You may find it useful for normalization. We haven't really talked about this yet, but __device__ functions not only are run on the GPU, but are called from ...
3,124
#include "includes.h" __global__ void binZeros(int *d_bin_count, int bin_size){ int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < bin_size){ d_bin_count[i] = 0; } }
3,125
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <math.h> #include <complex.h> #include <cuda_runtime.h> #include <utility> #include <sys/time.h> #define K 3 #define BLCH 8 #define BLCW 32 __constant__ float filter[K*K]; int compute_csr(float *img_csr, float *f, float * out, int *pos, int *coor, i...
3,126
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" __global__ void misaligned_write_test(float* a, float* b, float *c, int size, int offset) { int gid = blockIdx.x * blockDim.x + threadIdx.x; int k = gid + offset; if (k < size) c[k] = a[gid]...
3,127
#include "includes.h" __global__ void MatMultipl_naive (float * A, float * B, float * C , int nColsA , int nColsB , int sizeC ) { int i_col = blockIdx.x * blockDim.x + threadIdx.x; /// index in row int i_row = blockIdx.y * blockDim.y + threadIdx.y; /// index in column int idx = i_row * nColsB + i_col; // # of cols in ...
3,128
#include <stdio.h> #include <cuda_runtime.h> #include <time.h> #include <vector> using namespace std; const int GPUs[] = {0,1,2,3,4}; // If left blank all available GPUs will be used. vector<int> g(GPUs, GPUs + sizeof(GPUs)/sizeof(int)); void configure(size_t size, vector<int*> &buffer_s, vector<int*> &buffer_d) { ...
3,129
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include "string.h" #define DEFAULT_THRESHOLD 4000 #define DEFAULT_FILENAME "BWstop-sign.ppm" unsigned int *read_ppm( char *filename, int * xsize, int * ysize, int *maxval ){ if ( !filename || filename[0] == '\0') { fprintf(stderr, "read_ppm but no...
3,130
#include <iostream> #include <iterator> #include <fstream> #include <vector> #include <stdlib.h> #include <stdio.h> #include <curand.h> #include <curand_kernel.h> #include <math.h> using namespace std; void validateNumOfArgs(int argc); vector<unsigned long long> readNumbersFromFile(char* path); __device__ unsigned lo...
3,131
#include <stdio.h> #include <stdlib.h> #include <math.h> #define checkCudaErrors(val)\ fprintf(stderr, "CUDA error at %s:%d (%s) \n", __FILE__, __LINE__, cudaGetErrorString(val)); //Par rapport a la question 7 N = 1000 et nb thread = 640 // =>si on fait 2 x nb_thread alors 1280 threads > N peut causer bufferoverfl...
3,132
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda.h> #define THREADS_PER_BLOCK 512 __global__ void s_match(const char *s1, const char *s2); __device__ int s_cmp(const char *s1, const char *s2); int main(int argc, char *argv[]){ if (argc != 3){ printf("Usage: %s <string 1> <strin...
3,133
__global__ void transform(float* transform, int length, int *cdf, int cdf_min, int img_size) { int idx, offset; idx = blockIdx.x * blockDim.x + threadIdx.x; offset = blockDim.x * gridDim.x; for (int i = idx; i < length; i += offset) { transform[i] = (float) (cdf[i] - cdf_min) / (img_size ...
3,134
#include "includes.h" __global__ void NmDistanceGradKernel(int b,int n,const float * xyz1,int m,const float * xyz2,const float * grad_dist1,const int * idx1,float * grad_xyz1,float * grad_xyz2){ for (int i=blockIdx.x;i<b;i+=gridDim.x){ for (int j=threadIdx.x+blockIdx.y*blockDim.x;j<n;j+=blockDim.x*gridDim.y){ flo...
3,135
#define THREADS 256 __global__ void select_matches( const unsigned* in_idx, const int* in_dist, const unsigned nfeat, const unsigned nelem, const int max_dist) { unsigned f = blockIdx.x * blockDim.x + threadIdx.x; unsigned sid = threadIdx.x * blockDim.y + threadIdx.y; __shared__ int s_...
3,136
#include <stdio.h> #include <time.h> __global__ void vAdd(int* a, int* b, int* c, int n){ int i = threadIdx.x; if(i<n) c[i] = a[i] + b[i]; } void wrapper(int* a, int* b, int* c, int n){ int *d_a,*d_b,*d_c; cudaMalloc(&d_a,n*sizeof(int)); cudaMalloc(&d_b,n*sizeof(int)); cudaMalloc(&d_c,n*sizeof(int)); cud...
3,137
#include <stdio.h> #define gpuErrchk(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); if (abort) exit(code);...
3,138
#include "includes.h" /* cudaStructTest testing/optimizing how to access/manipulate/return structures in cuda. */ #define N 30 #define TRUE 1 #define FALSE 0 #define MAX_BLOCKS 65000 /*#define BLOCKS 2 #define THREADS 5*/ int cuda_setup(int computeCapability); typedef struct{ int id; int age; int height; } Person;...
3,139
#include "pgm_utility.cuh" #include "mesh.cuh" int write_image(char *filename, int n, struct mesh *mesh, double *xphys){ struct image img; int img_index; FILE *fout; int i, npixel; img.row = mesh->nely; img.col = mesh->nelx; img.max = 255; img.data = (int*)malloc(n * sizeof(int)); img_index = 0; for (in...
3,140
/**************************************************************************** * cuda_bigger_block.cu - a simple multi-layer Nerual Network * * Assignment of Module 2 of Ap4AI course of AI master degree @unibo * * Last updated in 2021 by Hanying Zhang <hanying.zhang@studio.unibo.it> * * To the extent possible un...
3,141
#include "includes.h" __global__ void swap_top_left_bot_right(float* data, const int num_threads, const int nx, const int ny, const int xodd, const int yodd, const int offset) { const uint x=threadIdx.x; const uint y=blockIdx.x; const uint gpu_idx = x+y*num_threads+offset; const uint c = gpu_idx % (nx/2); const uint r...
3,142
#include "includes.h" /* Programmaufruf mit 2 Argumenten: 1. Größe des Gitters (mit Rand): Nx+2 (= Ny+2) 2. Dimension eines Cuda-Blocks: dim_block (findet nur Anwendung, wenn Nx+2 > dim_block) */ /* Globale Variablen stehen in allen Funktionen zur Verfuegung. Achtung: Das gilt *nicht* fuer Kernel-Funktionen! */ int Nx...
3,143
#include "includes.h" __global__ void convolution_kernel_v1(float *d_output, float *d_input, float *d_filter, int num_row, int num_col, int filter_size) { int idx_x = blockDim.x * blockIdx.x + threadIdx.x; int idx_y = blockDim.y * blockIdx.y + threadIdx.y; float result = 0.f; for (int filter_row = -filter_size / 2; fi...
3,144
#include "reduce.cuh" __global__ void reduce_kernel(const int *g_idata, int *g_odata, unsigned int n) { extern __shared__ int sdata[]; int i = blockIdx.x * blockDim.x + threadIdx.x; sdata[threadIdx.x] = i < n ? g_idata[i] : 0; __syncthreads(); for (unsigned int s = blockDim.x...
3,145
#include <iostream> #include <math.h> using namespace std; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++! // Function Declarations ! //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++! void storeOldValue(double *...
3,146
#include <bits/stdc++.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <thrust/random.h> #include <thrust/random/uniform_int_distribution.h> using namespace std; class Rand{ //const int mod = 1E6; thrust::unif...
3,147
// // Created by sjhuang on 2021/8/21. // #include<stdio.h> #include<stdlib.h> #define N 100000 __global__ void vector_add(const float *a, const float *b, float *output,int n){ for(int i =0; i < n; i++){ output[i] = a[i] + b[i]; } } void vector_output(float *output, int n){ for(int i =0; i < n; i+...
3,148
#include "includes.h" __global__ void FloatDivByConstant(float *A, float constant) { unsigned int i = blockIdx.x * gridDim.y * gridDim.z * blockDim.x + blockIdx.y * gridDim.z * blockDim.x + blockIdx.z * blockDim.x + threadIdx.x; A[i]=A[i]/constant; }
3,149
/** * Detect the number of CUDA capable devices. */ #include <iostream> int main() { int count = 0; cudaGetDeviceCount( &count ); std::cout << count << " device(s) found.\n"; return 0; }
3,150
#define d_vx(z,x) d_vx[(x)*(nz)+(z)] #define d_vy(z,x) d_vy[(x)*(nz)+(z)] #define d_vz(z,x) d_vz[(x)*(nz)+(z)] #define d_szz(z,x) d_szz[(x)*(nz)+(z)] // Pressure #define d_mem_dvz_dz(z,x) d_mem_dvz_dz[(x)*(nz)+(z)] #define d_mem_dvx_dx(z,x) d_mem_dvx_dx[(x)*(nz)+(z)] #define d_Lambda(z,x) d_Lambda[(x)*(nz)+(z)] ...
3,151
#include "includes.h" __global__ void histogram_equalization_gpu_son (unsigned char * d_in, unsigned char * d_out, int * d_lut, int img_size, int serialNum) { int x = threadIdx.x + blockDim.x*blockIdx.x; if (x >= img_size) return; d_out[x] = (unsigned char) d_lut[d_in[x]]; }
3,152
#include <stdio.h> __global__ void cuda_hello(){ // printf("Hello\n"); printf("Hello from Thread %d out of %d in block %d.\n The ThreadID is %d of %d. \n", threadIdx.x +1, blockDim.x, blockIdx.x, threadIdx.x + (blockIdx.x*blockDim.x), 2*blockDim.x); } int main(){ cuda_hello<<<8,2>>>(); cudaDeviceSynchronize()...
3,153
#include "includes.h" int answersNumber; int categoriesNumber; int atribsNumber; /** * Funkcja wykonywana na karcie graficznej - kazdy watek sprawdza czy jego atrybut z atribsValues to ten sam co w query. Jesli tak, przepisuje do * tablicy wynikowej prawdopodobiestwa dla kazdej jego odpowiedzi * @param query - zapyta...
3,154
#include <stdio.h> #include <stdlib.h> #include "cuda.h" // to compile for a 3.5 capable device (like the titan in bodge): // nvcc -arch=sm_35 -O3 -o mxm mxm.cu -lm // // to run a partial reduction on a vector of length 8192 : // ./mxm 8192 // assume going forward 32x32 threads in each thread-block #define BDIM 32 ...
3,155
#include <string> /* struct PointCloud { utility::device_vector<Eigen::Vector3f> points_; }; namespace ply_pointcloud_reader { struct PLYReaderState { utility::ConsoleProgressBar *progress_bar; HostPointCloud *pointcloud_ptr; long vertex_index; long vertex_num; long no...
3,156
#include <stdio.h> __global__ void AplusB( int *ret, int a, int b) { /* * Simple unimportant kernel */ ret[threadIdx.x] = a + b + threadIdx.x; } int main() { // Create space in the device int *ret; cudaMalloc(&ret, 1000 * sizeof(int)); // Call the kernel AplusB<<< 1, 1000 >>>(ret, ...
3,157
#include<stdio.h> #include<time.h> #include<stdlib.h> __global__ void func1(int *c,int *a,int *b,int n,int startvalue) { int i = blockIdx.x*blockDim.x + threadIdx.x; if( i < n && i >= startvalue ) { a[i] = i * 2; b[i] = i * 3; i++; } } __global__ void func2(int *c,int *a,int *b,int n,int startvalue) { int i = blockI...
3,158
#include <cmath> __global__ void my_copysign(double* v) { int i = threadIdx.x; // assume threadIdx < 2 *v = ((i << 1) - 1) * (*v); }
3,159
extern "C" __global__ void sconv_fprop_K128_N128 ( float* param_test, float *param_O, const float *param_I, const float *param_F, float param_alpha, int param_N, int param_K, int param_D, int param_H, int param_W, int param_WN, int param_HWN, int param_DHWN, int param_C, int param_KRST, int param_RST, ...
3,160
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); __global__ void addKernel(int *c, const int *a, const int *b) { int i = threadIdx.x; c[i] = a[i] + b[i]; } __global__ void global_scan(float* d_...
3,161
#include <string> #include <map> #include <vector> #include <iostream> #include <cuda.h> #include <cuda_runtime.h> std::map<std::string, CUfunction> functions; std::vector<CUmodule> modules; using namespace std; void load_kernels() { const size_t kernel_size = 1; const string kernel_name[kernel_size] = { "sg...
3,162
__global__ void MatrixMultiplication_cuda (float * __restrict__ a, float * __restrict__ b, float * __restrict__ c, int M, int N, int P) { float sum; int lwpriv___ti_100_0; int lwpriv__i; int lwpriv__j; int lwpriv__k; lwpriv___ti_100_0=(threadIdx.x+(blockIdx.x*32)); if (lwpriv___ti_100_0<(M*N)) { sum=0.0; lwpriv__j=(lwp...
3,163
#include "includes.h" __global__ void incSumScanB1_kernel(unsigned int* d_outVals, unsigned int* d_inVals, size_t numVals, unsigned int* d_blockOffset, unsigned int valOffset) { unsigned int tIdx = threadIdx.x; unsigned int gIdx = blockIdx.x * blockDim.x + threadIdx.x; extern __shared__ unsigned int s_incScan[]; if (g...
3,164
#include <stdio.h> #include "orbit_integrator_cuda.cu" #define N 256 #define N_TOT N * J float x_h[N_TOT], y_h[N_TOT], vx_h[N_TOT], vy_h[N_TOT]; float *x_d, *y_d, *vx_d, *vy_d; cudaError_t err; int main(int argc, char** argv) { for(int i = 0; i < N; i++) { x_h[i*J] = 1; y_h[i*J] = 0; vx_h[i*J] = 0; vy_h[i*J]...
3,165
#include <cuda.h> #include <iostream> #include <stdlib.h> #include <assert.h> #include <chrono> #define CUDA_CHECK(status) (assert(status == cudaSuccess)) #define threads_per_block 1024 // sum the shared data reductions into a single one // loop unrolled version for increased performance // Note: do not remove volat...
3,166
#include <stdio.h> // no need to change this void helloCPU() { printf("Hello from the CPU.\n"); } // add __GLOBAL__ so that the function runs from gpu __global__ void helloGPU() { printf("Hello from the GPU.\n"); } int main() { // calling the GPU function helloGPU<<<1, 1>>>(); cudaDeviceSynchronize(); /...
3,167
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <cuda.h> unsigned int getmax(unsigned int *, unsigned int); int main(int argc, char *argv[]) { unsigned int size = 0; // The size of the array unsigned int i; // loop index unsigned int * numbers; //pointer to the array if(argc !...
3,168
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> cudaError_t VectorSum(int *c, const int *a, const int *b, unsigned int size); __global__ void VectorSum(int *c, const int *a, const int *b) { int i = threadIdx.x; c[i] = a[i] + b[i]; } int main() { const int arraySize = 5; const...
3,169
//****************************************************** // Assignment #1 // Names: Anthony Enem and Cavaughn Browne // Parallel Programming Date: 10/10/16 //****************************************************** // This program implements the cooley tukey fft algorithm // and computes the values fro X_k from 0 to N. T...
3,170
#include "includes.h" /* TODO: Your code here */ /* all your GPU kernel code, e.g. matrix_softmax_cross_entropy_kernel */ // y = inputs[0], y_ = inputs[1] // np.mean(-np.sum(y_ * np.log(softmax(y)), axis=1), keepdims=True) __global__ void matrix_elementwise_add(const float *a, const float *b, float *c, int n) { i...
3,171
// This program will demo how to use CUDA to accelerate inner-product #include <iostream> #include <cstdlib> using namespace std; #define VECNUM 50000 #define VECLEN 1000 int *inputA, *inputB; int *devInputA, *devInputB, *devOut; int *outCPU, *outGPU; void init() { int i, j, idx; inputA = new int[VECNUM * VECLEN]...
3,172
// This example demonstrates how to // query about the properties of a device #include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> int main(void) { int dev_count, driverVersion = 0, runtimeVersion = 0;; cudaGetDeviceCount(&dev_count); cudaDriverGetVersion(&driverVersion); cudaRuntimeGetVersion(&...
3,173
#include <iostream> #include <string.h> void __global__ run(float * h) { int idx = blockIdx.x*64+threadIdx.x; if (idx > 10000) return; h[idx] += 1.3f; } int main(int argc, char ** argv) { int times = atoi(argv[1]); float * h_d; cudaMalloc(&h_d, 10000*sizeof(float)); for (int i = 0; i < times; ++i) run<<<157,...
3,174
#include "includes.h" __global__ void device_BFS(const int* edges, const int* dests, int* labels, int* visited, int* c_frontier_tail, int* c_frontier, int* p_frontier_tail, int* p_frontier) { int index = blockIdx.x * blockDim.x + threadIdx.x; if (index < *p_frontier_tail) { int c_vertex = p_frontier[index]; for (int i ...
3,175
///------------------------------------------------------------------------------------------------- // file: descportsout.cu // // summary: test kernal for output descriptor ports test case: // The test does a normal vector scale, but the output data // block should also have 'N' in the metadata chan...
3,176
#include "includes.h" /* Vector addition with a single thread for each addition */ /* Vector addition with thread mapping and thread accessing its neighbor parallely */ //slower than simpler /* Matrix Matrix multiplication with a single thread for each row */ /* Matrix Matrix multiplication with a single thread...
3,177
// system libraries // use nvcc -o (output name) -Wno-deprecated-gpu-targets -std=c++11 -Xcompiler -fopenmp file_name.cu #include <cuda_runtime.h> #include <cstdio> #include <cstdlib> #include <math.h> #include <chrono> // size definition. modify as needed #define N 2000 #define T_SIZE 32 using namespace std; // sa...
3,178
#include "includes.h" __global__ void Corrector_gpu(double GTIME, double *local_time, double *step, int *next, unsigned long nextsize, double4 *pos_CH, double4 *vel_CH, double4 *a_tot_D, double4 *a1_tot_D, double4 *a2_tot_D, double4 *a_H0, double4 *a3_H, double ETA6, double ETA4, double DTMAX, double DTMIN, unsigned in...
3,179
#include "user.cuh" void generateVector(float *vec, int size, float *p_minVal, float *p_maxVal) { random_device rd; mt19937 gen(rd()); uniform_real_distribution<float> dis(-100000.0, 100000.0); for (int i = 0; i < size; i++) { vec[i] = dis(gen); (*p_minVal) = (*p_minVal > vec[i]) ? vec...
3,180
#include "includes.h" //kernel for computing histogram right in memory //computer partial histogram on shared memory and mix them on global memory __global__ void hist_inGlobal (const int* values, int length, int* hist){ //compute index and interval int idx = blockDim.x * blockIdx.x + threadIdx.x; int stride = grid...
3,181
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <cuda.h> #define N 10000000 // total number of items in vectors #define nthreads 4 // total number of threads in a block __global__ void square(int n, int *vect1, int *vect2, int *sum) { int threadID; threadID = bl...
3,182
/** * I wrote, compiled, and ran this code on the cssgpu01 machine. * Which I believe runs Ubuntu 16.04 * * There appeared to be other intensive computations happening, which may * have slowed my execution output. * * To compile: * nvcc vector.cu -o vector.out * * To run: * ./vector.out <vector_size> */...
3,183
#include <iostream> #include <cuda.h> #include <stdlib.h> #include <time.h> using namespace std; __global__ void vector_add(int *d_vec1,int *d_vec2,int *d_vec3) { int idx = blockIdx.x * blockDim.x + threadIdx.x; d_vec3[idx] = d_vec1[idx] + d_vec2[idx]; } int main() { const int num_block = 1000; const int thread...
3,184
#include <iostream> #include <stdlib.h> #include <cuda.h> #include <curand_kernel.h> #define WIDTH 64 using crngState = curandStatePhilox4_32_10_t; /* Each thread gets same seed, a different sequence number, no offset */ __global__ void setup_curand(crngState *state, unsigned long seed, unsigned dim) { uint3...
3,185
#include "cuda.h" #include <iostream> #include <stdlib.h> __global__ void simple_vec_add(float * inA, float * inB, float * outC, int n) { int idx = blockIdx.x*blockDim.x+threadIdx.x; if(idx<n) { outC[idx]...
3,186
#include <iostream> #include <assert.h> #include <cstdlib> #include "cuda_runtime.h" const int SIZE = 4096; __global__ void dymTrans(int *V, int N) { extern __shared__ int array[]; int refIndex = threadIdx.x; array[refIndex] = V[refIndex]; __syncthreads(); V[refIndex] = array[N-refIndex-1]; } ...
3,187
#include "blur.cuh" #include "grayScale.cuh" #include <iostream> using namespace std; int main(int argc, char **argv) { if (argc < 3) { cout << argv[0] << ": needs two arguments\n" << "<image_path> <option>\n"; return 0; } string image_path(argv[1]), option(argv[2]); if (option == "gray") { ...
3,188
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include "string.h" #include <math.h> #define DEFAULT_FILENAME "small-zibra-unsplash.ppm" #define MAX_VALUE 256 //max value of the pic luminance #define NUM_BINS 256 //num of bins equals to the max value __constant__ double PARAMS[4]; void write_ppm( char...
3,189
#include <stdio.h> #define N 12 #define THREADS_X 3 #define THREADS_Y 4 #define A(i,j) A[i*N+j] #define B(i,j) B[i*N+j] #define C(i,j) C[i*N+j] __global__ void index(int *A, int *B, int *C) { int i = blockDim.x * blockIdx.x + threadIdx.x; int j = blockDim.y * blockIdx.y + threadIdx.y; C(i,j) = A(i,j) + B(i,j); ...
3,190
//#include <iostream> //#include "common.h" //#include "cuda.h" //#include "DeviceVector.cpp" //#include "dev_noise.cuh" //using namespace std; // //int main(){ // DeviceVector<float> vc1(0,10,1); // DeviceVector<float> vc2(0, 10,1); // for (float aa : vc1){ // cout << aa << " "; // } // cout << endl; // for (float aa...
3,191
#include <cuda.h> #include <stdio.h> #include <stdint.h> #define WIDTH 512 #define HEIGHT 512 #define ITERS 512 #define N (WIDTH*HEIGHT) #define max_size 4 #define max_colors 16 #define xmax 1.2f #define xmin -2.0f #define ymax 1.2f #define ymin -1.2f #define deltaP ((xmax - xmin)/512) #define deltaQ ((ymax ...
3,192
#include <stdio.h> typedef struct { int n; int m; int tile; float* arr; } Matrix; // Thread block size #define BLOCK_SIZE 16 void printa(float *A, int n, int m); void generateMatrix(float *A, int n, int m, int num); __global__ void MulKernel(const Matrix, const Matrix, Matrix); __global__ void MulKer...
3,193
// Streams #include <iostream> #include <sstream> #include <fstream> // Containers #include <string> #include <vector> // Time #include <chrono> // C headers #include <cmath> #include <cstdlib> #include <cstring> // CUDA headers #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> int ...
3,194
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand_kernel.h> extern "C" { __global__ void setup_kernel(curandState *state) { // Usual block/thread indexing... int myblock = blockIdx.x + blockIdx.y * gridDim.x; int blocksize = blockDim.x * blockDim.y * blockDim.z; int subthread ...
3,195
#include <cstdio> #include <cstdlib> #include <cuda_runtime_api.h> int main(int argc, char *argv[]) { cudaDeviceProp prop; cudaError_t status; int device_count; int min_v = 0; status = cudaGetDeviceCount(&device_count); if (status != cudaSuccess) { fprintf(stderr,"cudaGetDeviceCount() ...
3,196
#include <stdio.h> #include <stdlib.h> #include "cuda_runtime.h" //#include "cuda.h" //#include "cuda_runtime_api.h" //#include "cuda_device_runtime_api.h" // Each thread performs one pair-wise addition __global__ void vecAddKernel(const float* A, const float* B, float* C, int n) { int i = blockDim.x * blockIdx.x + th...
3,197
#include <stdlib.h> #include <unistd.h> #include <iostream> #include <string> #include <sstream> using namespace std; #include "cuda_runtime_api.h" #define SIZE_OF_MATRIX 1000 #define SIZE_OF_BLOCK 16 #define M SIZE_OF_MATRIX unsigned int m = SIZE_OF_MATRIX; #define idx(i,j,lda) ((j) + ((i)*(lda))) __global__ void ...
3,198
#include <stdio.h> #include <cuda.h> #include<sys/time.h> __global__ void dkernel(unsigned *vector, unsigned vectorsize,int N) { unsigned id = blockIdx.x * blockDim.x + threadIdx.x; if(id<vectorsize) vector[id]+=N; } #define BLOCKSIZE 1024 int main(int nn, char *str[]) { unsigned long long N...
3,199
#include "includes.h" __global__ void cuInsertionSort(float *dist, int dist_pitch, int *ind, int ind_pitch, int width, int height, int k){ // Variables int l, i, j; float *p_dist; int *p_ind; float curr_dist, max_dist; int curr_row, max_row; unsigned int xIndex = blockIdx.x * blockDim.x + threadIdx.x; if (xIndex...
3,200
#include <iostream> __global__ void helloWorldKernel() { printf("Hello from Device, thread: %d\n", threadIdx.x); } int main() { std::cout << "(1) Hello from Host" << std::endl; helloWorldKernel<<< 2, 8 >>>(); // asynchronous call std::cout << "(2) Hello from Host" << std::endl; cudaDeviceSynch...