serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
21,901
#include "includes.h" __device__ int glb_hist[COLORS]; __global__ void calc_histogram(unsigned char * img_in, int offset_start, int offset_end){ int ix = blockIdx.x * blockDim.x + threadIdx.x;; const int gridW = gridDim.x * blockDim.x; int Row, pos; __shared__ int hist[COLORS]; if (threadIdx.x < COLORS) { hist[thre...
21,902
#include <iostream> #include <stdlib.h> #include <fstream> #include <string> #include <vector> #include <set> using namespace std; vector<string> splitpath( const string& str, const set<char> delimiters) { vector<string> result; char const* pch = str.c_str(); char const* start = pch; for(; *pch; ++pch) { ...
21,903
// Compile with: // // nvcc -gencode arch=compute_50,code=compute_50 -rdc true -ptx jitlink.cu // // using the oldest supported toolkit version (10.2 at the time of writing). extern "C" __device__ int bar(int *out, int a) { *out = a * 2; return 0; } // The out argument is necessary due to Numba's CUDA calling ...
21,904
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h> const int INF = (1 << 30) - 1; int vertex_num, edge_num, matrix_size; int *dist; double cal_time(struct timespec start, struct timespec end) { struct timespec temp; if ((end.tv_nsec - start.tv_nsec) < 0) { temp.tv_sec = end.tv_sec - start...
21,905
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <cmath> #include <device_functions.h> #define N 1048576 #define THREADS_PER_BLOCK 1024 #define cudaCheckErrors(msg) \ do { \ cudaError_t __err = cudaGetLast...
21,906
#include "includes.h" #define BLOCK_SIZE 1024 #ifndef RADIUS #define RADIUS 3 #endif #ifndef ITERS #define ITERS 100 #endif #ifndef USE_L2 #define USE_L2 false #endif __global__ void stencil_no_shared(int *in, int *out) { int temp[BLOCK_SIZE + 2 * RADIUS]; int gindex = threadIdx.x + blockIdx.x * blockDim.x; i...
21,907
//This program checks if there is a CUDA capable graphics card //and selects the best one #include <stdio.h> #include <stdlib.h> //This function checks the device (devProp) against the specifications //It returns true if the device meets specifications, false otherwise bool matchSpecs(cudaDeviceProp devProp, int spec...
21,908
#include <cuda.h> #include <iostream> #include <stdio.h> using namespace std; #define cudaCheck(error) \ if (error != cudaSuccess) { \ printf("Fatal error: %s at %s:%d\n", \ cudaGetErrorString(error), \ __FILE__, __LINE__); \ exit(1); \ } __global__ void cudawbfs(int *distance, unsigned int *...
21,909
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <time.h> //#include <common.h> #define M 10 #define NR_BLOCK 1024 __global__ void compute(const float * a, float * b) { int i = blockIdx.x; int j; for (j = 0; j < M; j++) { if ((i + j * NR_BLOCK) > 0 && ...
21,910
#include "includes.h" __global__ void transposeUnroll4Col(int *in, int *out, const int nx, const int ny) { // set thread id. unsigned int ix = threadIdx.x + blockIdx.x * blockDim.x * 4; unsigned int iy = threadIdx.y + blockIdx.y * blockDim.y; unsigned int ti = iy * nx + ix; // access in rows. unsigned int to = ix * ny...
21,911
#include "includes.h" __global__ void copy_kernel(double *save, double *y) { const int threadID = (blockIdx.x * blockDim.x + threadIdx.x) << 1; save[threadID] = y[threadID]; save[threadID + 1] = y[threadID + 1]; }
21,912
#include <stdio.h> #include <assert.h> #define epsilon (float)1e-5 #define DATA double #define THREADxBLOCKalongXorY 4 void MatrixMulOnHost(DATA* M, DATA* N, DATA* P, int Width) { for (int i = 0; i < Width; ++i) { for (int j = 0; j < Width; ++j) { double pvalue = 0; for (int k = 0; ...
21,913
//pass //--blockDim=64 --gridDim=64 --no-inline #include <cuda.h> #include <assert.h> #define N 2//64 __global__ void foo(int* A) { //__assert(__all(threadIdx.x < blockDim.x)); assert(threadIdx.x < blockDim.x); } int main(){ int *a,*dev_a; a = (int*)malloc(N*sizeof(int)); cudaMalloc((void**)&dev_a,N*sizeo...
21,914
#include <stdio.h> #include <stdlib.h> #define SIZE 512 // This example is adapted from an example in Nvidia CUDA C Programming Guide 4.0 __global__ void demo(int * input,int* output) { int tid = threadIdx.x; int ref1 = input[tid]; //These two syncthreads call can make sure memoey coherence. //__syncthreads();...
21,915
#define d_vx(z,x) d_vx[(x)*(nz)+(z)] #define d_vz(z,x) d_vz[(x)*(nz)+(z)] #define d_sxx(z,x) d_sxx[(x)*(nz)+(z)] #define d_szz(z,x) d_szz[(x)*(nz)+(z)] #define d_sxz(z,x) d_sxz[(x)*(nz)+(z)] #define d_mem_dszz_dz(z,x) d_mem_dszz_dz[(x)*(nz)+(z)] #define d_mem_dsxz_dx(z,x) d_mem_dsxz_dx[(x)*(nz)+(z)] #define d_mem_dsx...
21,916
#include <iostream> using namespace std; __global__ void add_gpu(const int N, float *a, float *b, float *result) { int index = blockDim.x * blockIdx.x + threadIdx.x; // Stride style loop const int stride = gridDim.x * blockDim.x; for (; index < N; index += stride) { result[index] = a[inde...
21,917
#include "includes.h" // ERROR CHECKING MACROS ////////////////////////////////////////////////////// __global__ void buildGlobalQuadReg(int noPoints, int noDims, int dimRes, int nYears, int noControls, int year, int control, float* regCoeffs, float* xmins, float* xmaxes, float* regression) { // Global thread index ...
21,918
#include <stdio.h> #include <cuda.h> __global__ void MyKernel() { printf("blockIdx.x=%u,ThreadIdx.x=%u\n",blockIdx.x,threadIdx.x); return; } int main() { printf("Kernel (Blocks x Threads)\n"); MyKernel<<<1, 2>>>(); printf("\n\n****Kernel (1x2) launched****\n\n"); cudaDeviceSynchronize(); ...
21,919
#include "includes.h" __global__ void scatter(int *d_array , int *d_predicateArray, int *d_scanArray,int *d_compactedArray, int d_numberOfElements) { int index = blockIdx.x * blockDim.x + threadIdx.x; if(index < d_numberOfElements) { if(d_predicateArray[index]==1) { d_compactedArray[d_scanArray[index]-1] = d_array[inde...
21,920
#include <stdio.h> __global__ void add_kernel(int *a, int *b, int *c) { *c = *a + *b; } int main() { // on Host int a, b, c; // copy on Device int *d_a, *d_b, *d_c; int size = sizeof(int); // allocate memory on device //use a pointer to address to be populated cudaMalloc((void **)...
21,921
#include <stdio.h> int main ( int argc, char *argv[ ] ) { int arr[ 6 ] = { 0, 1, 2, 3, 5, 8 }; char *filename = argv[ 1 ]; FILE *fp; fp = fopen( filename, "w" ); int x = 0; while( x < 6 ) { fprintf( fp, " %d ", arr[ x ] ); x++; } printf( "\n File %s was created and written with data \n\n", filename ); }
21,922
#include <stdlib.h> #include <stdio.h> //AQUEST ÉS EL CODI PROPORCIONAT PELS NOSTRES COMPANYS __device__ void mergeDevice(int *list, int *sorted, int start, int mid, int end) { int ti=start, i=start, j=mid; while (i<mid || j<end) { if (j==end) sorted[ti] = list[i++]; else if (i==mid) sorte...
21,923
/** Homework 3 question 2 code * * \file q2.cu * \author Utkarsh Vardan <uvardan@utexas.edu> * \author Jose Carlos Martinez Garcia-Vaso <carlosgvaso@utexas.edu> */ #include <cstdio> // standard I/O #include <string> // strings #include <fstream> // streams #include <vector> // std::vector #include <sstre...
21,924
#include <stdio.h> #include <stdlib.h> #include <math.h> #define M 1024 __global__ void sumMatrixes(int* A, int* B, int* C, int n){ int index = threadIdx.x + blockIdx.x * blockDim.x; if(index < n){ C[index] = A[index] + B[index]; } } int main(void){ int *A, *B, *C; int i, j; ...
21,925
#include <cuda.h> #include <stdio.h> #include <stdlib.h> __global__ void mandelKernel(int* d_img, const int maxIter, const float stepX, const float stepY, const float lowerX, const float lowerY) { // To avoid error caused by the floating number, use the following pseudo code // // float x = lowerX + thisX *...
21,926
#include "bp.cuh" void update_fc2_b() { for(int i=0;i<FC2_SIZE;i++) { fc2_delta[i]=alpha*C[i]*(fc2_a[i]*(1.0-fc2_a[i])); fc2_db[i]+=fc2_delta[i]; } } void update_fc2_w() { for(int i=0;i<FC2_SIZE;i++) for(int j=0;j<FC1_SIZE;j++) fc2_dw[i][j]+=fc2_delta[i]*fc1_a[j]; } void u...
21,927
#include "includes.h" __global__ void dotProduct_CUDA(double *sum, long size, double *vector1, double *vector2){ long idx = blockIdx.x*blockDim.x+threadIdx.x; // Sequential thread index across the blocks if(idx < size){ //printf("Before idx%d : %lf\n",idx,sum[idx]); sum[idx] = (vector2[idx]) * (vector1[idx]); //printf...
21,928
#include "includes.h" __global__ void average_snips(const double *Params, const int *ioff, const int *id, const float *uproj, const float *cmax, const int *iList, float *cf, float *WU){ int tid, bid, ind, Nspikes, Nfeatures, NfeatW, Nnearest, t; float xsum = 0.0f, pm; Nspikes = (int) Params[0]; Nfeature...
21,929
/* * @author Connie Shi * Lab 3: Write a reduction program in CUDA that finds the maximum * of an array of M integers. * Part 2: Write a CUDA version that DOES take thread divergence * into account. Uses sequential addressing. * * Should be run on cuda1 machine with 1024 max threads per block...
21,930
// To compile: nvcc CPUAndGPUVectorAdditionClass.cu -o temp2 // To run: ./temp2 #include <sys/time.h> #include <stdio.h> //This is the CUDA kernel that will add the two vectors. __global__ void Addition(unsigned char *A, unsigned char *B, unsigned char *C){ unsigned long id = (blockIdx.x * blockDim.x) + threadIdx.x; ...
21,931
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" __device__ int isPrimeGPU(long x) { long long i; for (i = 2; i * i < x + 1; i++) { if (x % i == 0) { return 0; } } return 1; } __hos...
21,932
 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> #include <chrono> #define BLOCKS 1024 * 1024 #define THREADS 256 __global__ void FindKey(uint64_t aPlainText, uint64_t aKeyMax, uint64_t aCipherExpected, uint64_t* aResult) { int index = blockIdx.x * THREAD...
21,933
#include <iostream> #include <math.h> struct index { int x; int y; int z; }; __device__ struct index unravel_idx(int idx, int n){ struct index unravel; int x, y, z; z = idx % n; y = (idx / n) % n; x = (idx / n) / n; unravel = {.x = x, .y = y, .z = z}; return unravel; } __device__ int ravel...
21,934
#include <cuda.h> #include <stdio.h> int main(int argc, char** argv) { cudaError_t e; e = cudaPointerGetAttributes((struct cudaPointerAttributes*) 0, (void*) 0); printf("Error: %d\n", e); return 0; }
21,935
#include "includes.h" using namespace std; #define MAX_ARRAY_SIZE 1024 #define RANDOM_MAX 1000 #define TILE_DIM 16 #define BLOCK_ROWS 8 #define EPSILON 0.000001 #define NUM_BLOCKS (MAX_ARRAY_SIZE/TILE_DIM) float A[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE]; float C[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE]; void serial(); void init_F(...
21,936
#include <cstdio> #if defined(NDEBUG) #define CUDA_CHECK(x) (x) #else #define CUDA_CHECK(x) do {\ (x); \ cudaError_t e = cudaGetLastError(); \ if (cudaSuccess != e) { \ printf("cuda failure \"%s\" at %s:%d\n", \ cudaGetErrorString(e), \ __FILE__, __LINE__); \ exit(1); \ } \ } while (...
21,937
#include <stdio.h> #include <cuda_runtime.h> __device__ char xx[23]; __shared__ char s2[23]; __global__ void cuCopyTest( char *s1, int start, int end) { char out[23]; char * dest; char * src; int n = end; // initialize shared memory s2 from xxx; dest = &s2[start]; n = end; src = &xx[sta...
21,938
#include <stdio.h> #include <cuda.h> #define N 100 #define BLOCKSIZE 32 __global__ void init(int *input) { unsigned id = blockDim.x * blockIdx.x + threadIdx.x; if (id < N) input[id] = id + 1; } __global__ void print(int *output) { for (unsigned ii = 0; ii < N; ++ii) printf("%d ", output[ii]); printf("\n"); } ...
21,939
#include <stdbool.h> #include <stdio.h> #include <string.h> #include <getopt.h> #include <curand_kernel.h> #include <stdlib.h> #include <cuda.h> #include <sys/time.h> #include "Corrector_gpu.cu" #include<chrono> #include<iostream> using namespace std; using namespace std::chrono; int blocks_[20][2] = {{8,8},{16,16},{24...
21,940
// Note that in this model we do not check // the error codes and status of kernel call. #include <cstdio> #include <cmath> __global__ void hello() { printf("Greetings from your GPU\n"); } int main(void) { int count, device; cudaGetDeviceCount(&count); cudaGetDevice(&device); printf("You have in total %d ...
21,941
/* Copiar traspuesta de matriz h_a[F][C] en matriz h_b[C][F] aunque el n.º de hebras de los bloques no divida al n.º de componentes de las matrices */ #include <stdio.h> #define F 25 #define C 43 // matriz original de F filas y C columnas #define H 16 // bloques de H x H hebras (HxH<=512, capacidad cpto. 1.3) __...
21,942
#include "includes.h" extern "C" { } __global__ void vdivupdate(const int lengthA, const double alpha, const double *a, const double *b, double *c) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i<lengthA) { c[i] += alpha*a[i] / b[i]; } }
21,943
#include"stdio.h" #include<cuda_runtime.h> #include <sys/time.h> #define len 1 #define WIDTH 128 // Kernel definition __device__ float& getPos(float *T,int x,int y,int w) { return *(T+y*w+x); } // 处理:正方形,二维热流场 // dN // dW dT dE // dS __global__ void Calc_Cell(float* T0) { float dW,dE,dN,dS,d...
21,944
#include <cuda_runtime_api.h> // FIXME(20160123): commentng out for cuda 7.0. //#include <cuda_fp16.h> #include <assert.h> #include <stdint.h> #include <stdio.h> typedef uint16_t half; #define BANK_OFFSET(idx) ({ __typeof__ (idx) _idx = idx; ((_idx) + ((_idx) / 32)); }) __global__ void map_print_i32_kernel( con...
21,945
#include "includes.h" __global__ void PoissonImageCloningIteration( const float *fixed, const float *mask, const float *buf1, float *buf2, const int wt, const int ht ) { const int yt = blockIdx.y * blockDim.y + threadIdx.y; const int xt = blockIdx.x * blockDim.x + threadIdx.x; const int curt = wt*yt+xt; if (yt < ht and...
21,946
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <vector> /** * This file is about the cuda code for the strig match:sunday algorithm. * This main idea to use GPU(cuda) to accelerate the speed of the sunday algori...
21,947
#include "includes.h" //============================================================================ // Name : PoissonEquationJacobiCuda.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //=================================================...
21,948
__global__ void vectorSwap(float *A,float *B,const int size) { int i = blockDim.x*blockIdx.x + threadIdx.x; int l = sqrt((float)size); if (i < size) { int j = i/l; int k = i%l; float temp; if((k%2)==0 && k!=l-1){ temp = A[i]; A[i] = A[i+1]; A[i+1]...
21,949
#include "includes.h" __global__ void computeMoment(int8_t *readArr, int8_t *writeArr, float *weightArr, int n, int tileSize){ int row_init = blockIdx.x*(blockDim.x*tileSize) + threadIdx.x*tileSize; int col_init = blockIdx.y*(blockDim.y*tileSize) + threadIdx.y*tileSize; // Assign each thread a tileSizeXtileSize tile f...
21,950
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #define N 8 __global__ void reduceVector(float *a, int thread){ int id = blockIdx.x*blockDim.x+threadIdx.x; for(int s=N/2; s>=1; s/=2){ if(id<s) *(a+id) += *(a+id+s); __syncthreads(); } } int main() { int memsize = size...
21,951
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <sys/resource.h> #include <math.h> double dwalltime(){ double sec; struct timeval tv; gettimeofday(&tv,NULL); sec = tv.tv_sec + tv.tv_usec/1000000.0; return sec; } __global__ void matDet(double *d_matA, double *detM){ int global_id = b...
21,952
# include <stdio.h> # include <stdlib.h> # include <cuda.h> # include <sys/time.h> # include <unistd.h> # define BLOCK_SIZE (32) //# define n 128 //# define n 256 //# define n 512 //# define n 1024 //# define n 2048 //# define n 4096 # define n 8192 # define threshold 1e-8 double rtclock(void) { struct tim...
21,953
#include <stdio.h> // For use of the printf function #define N 256 // Number of threads to use #define TPB 256 // Threads PER block /** * Function launched from the CPU and run on the GPU that will display a message * of the format `Hello World! My threadId is x` where x is the the threadId of * the thread found ...
21,954
#include "includes.h" __global__ void matrixMul(int* A, int* B, int* C, int aF, int aC, int bF, int bC, int cF, int cC) { // Compute each thread's global row and column index int row = (blockIdx.y * blockDim.y) + threadIdx.y; int col = (blockIdx.x * blockDim.x) + threadIdx.x; // Iterate over row, and down column ////c...
21,955
// // include files // #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda_runtime.h> #include <time.h> #define N (2048*2048) #define THREADS_PER_BLOCK 512 // // kernel routine // __global__ void dot_product(const int *a, const int *b, int *c) { // each thread in a block ...
21,956
#include<time.h> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<cuda.h> /* Macro for mapping three dimensional index (ix,iy,iz) to * linear index. The vertical index (z) is running fastest so * that vertical columns are always kept together in memory. */ #define LINIDX(n, ix,iy,iz) ((n.z)*(n.y)*(i...
21,957
// testing gpu queue (compacted array) #include <cuda.h> #include <cuda_runtime.h> #include <thrust/device_vector.h> #include <thrust/device_ptr.h> #include <thrust/copy.h> #include <stdio.h> #define WARP_SIZE 32 #define NUM_WARPS 16 // blocksize: threads should be less than 1024. #define BLOCK_SIZE (WARP_SIZE * NUM_...
21,958
#include "includes.h" /** * Programma che simula il comportamento del gpdt per * la risoluzione di un kernel di una serie di * valori di dimensione variabile utilizzando la * tecnologia cuda. * compilare con: * nvcc -o simil_gpdt_si_cuda simil_gpdt_si_cuda.cu * lanciare con: * ./simil_gpdt_si_cuda [numero vettori] [num...
21,959
// http://cuda-programming.blogspot.com/2013/01/what-is-constant-memory-in-cuda.html //STL #include <iostream> __constant__ float d_angle[ 360 ]; //constant memory LUT candidate __global__ void test_kernel( float* d_array ); int main( int argc, char** argv ) { unsigned size = 3200; float* d_array; float...
21,960
#include <stdio.h> #include <math.h> #define N 8 #define THREAD_PER_BLOCK 2 __global__ void multiply(int * in1, int * in2, int * out, int size) { int index = threadIdx.x + blockIdx.x * blockDim.x; int startrow = (index / size) * size; int startcol = index % size; int i; int sum = 0; for(i = 0;...
21,961
#include <stdlib.h> #include <stdio.h> #define NUM_BLOCKS 20 __device__ int* dataptr[NUM_BLOCKS]; // Per-block pointer __global__ void allocmem() { // Only the first thread in the block does the allocation // since we want only one allocation per block. if (threadIdx.x == 0) dataptr[blockIdx.x] =...
21,962
#include "includes.h" __global__ void createLookupKernel(const int* inds, int total, int* output) { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < total) output[inds[idx]] = idx; }
21,963
/* The MIT License (MIT) Copyright (c) 2017 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitatio...
21,964
#include "cuda_runtime.h" #include "device_launch_parameters.h" #define __CUDACC_RTC__ #define __CUDACC__ #include <device_functions.h> #include <iostream> #include <cstdio> #include <cstdlib> #include <stdio.h> #include <stdlib.h> #include <algorithm> typedef struct { int width; int height; float* elements; int st...
21,965
#include <stdio.h> __global__ void decode (char *originalMessage, char *decodedMessage); int main (int argc, char *argv[]) { //-------- Testing parameters --------// if (argc != 2){ printf("Incorrect number of parameters :(\n"); printf("Try: \"./DecodeEmail2FULP <filename>\"\n"); exit(0); } //...
21,966
#include "includes.h" __global__ void cu_minMaxLoc(const float* src, float* minValue, float* maxValue, int* minLoc, int* maxLoc, float* minValCache, float* maxValCache, int* minLocCache, int* maxLocCache, const int n){ int tid = threadIdx.x + blockIdx.x * blockDim.x; //int stride = blockDim.x * gridDim.x; float val...
21,967
/* 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,int var_2,int 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 var_...
21,968
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #define MINREAL -1024.0 #define MAXREAL 1024.0 #define FAST_RED #define ACCURACY 0.0001 #define NUM_OF_GPU_THREADS 256 void checkCUDAError(const char *msg) { cudaError_t err =...
21,969
#include "includes.h" __global__ void solution_inter(float *z, float *g, float lambda, int nx, int ny) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; int idx = x + y*nx; if (x<nx && y<ny) g[idx] = -z[3 * idx + 2] * lambda; }
21,970
// Write a CUDA program to compute the sum of two arrays. Input: Number of elements in the array. Output: Array of sums // Used the Error Handler function written by Dr. Rama in his Colab shared to us on google classroom #include<stdio.h> #include<stdlib.h> #include<time.h> #define HANDLE_ERROR( err ) ( HandleError...
21,971
#include <stdio.h> #include <cuda_runtime.h> #include <time.h> void llenaAleatorio(float arreglo[], int n); void ImprimeArreglo(float arreglo[], float arreglo2[], float arreglo3[], int n); __global__ void VecAdd(float* A, float* B, float* C, int N){ int i = blockDim.x * blockIdx.x + threadIdx.x; if(i < N) ...
21,972
#include<cuda.h> #include<stdio.h> void initializeArray(int*,int); void stampaMatriceArray(int*, int, int); void equalArray(int*, int*, int); void sommaMatriciCompPerCompCPU(int *, int *, int *, int); //specifica il tipo di funzione kernel __global__ void sommaMatriciCompPerCompGPU(int*, int*, int*, int); int main(i...
21,973
#include <assert.h> // assert() is only supported // for devices of compute capability 2.0 and higher #if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 200) #undef assert #define assert(arg) #endif __global__ void testAssert(void) { int is_one = 1; int should_be_one = 0; // This will have no effect ass...
21,974
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #include <string.h> #include "spiky25.cu" #define neurons_per_thread 50 #define no_input_neurons 12 #define no_output_neurons 3 #define clock_cycle 10 int **getNeighbors(char *file); //This is an optimised queue for this ...
21,975
#include <iostream> #include <vector> __global__ void fill( int * v, std::size_t size ) { auto tid = threadIdx.x; v[ tid ] = tid; } int main() { std::vector< int > v( 100 ); int * v_d = nullptr; cudaMalloc( &v_d, v.size() * sizeof( int ) ); fill<<< 1, 1025 >>>( v_d, v.size() ); cudaDeviceSynchroni...
21,976
#include <iostream> #include "bounding_box.cuh" int main(){ BoundingBox box; float2 p1 = make_float2(0.5f,0.5f); float2 p2 = make_float2(10.0f, 10.0f); std::cout << "Does point 1 lie in the box? " << box.contains(p1) <<"" << std::endl; std::cout << "Does point 2 lie in the box? " << box.con...
21,977
#include <algorithm> #include <cassert> #include <iostream> #include <vector> //CUDA kernel for vector addition // __global__ means this called from the CPU, and runs on the GPU __global__ void vectorAdd(const int *__restrict a, const int *__restrict b, int *__restrict c, int N) { //Calc...
21,978
#include <stdio.h> #include <cuda_runtime_api.h> #include <time.h> // nvcc -o CudaPasswordCracking CudaPasswordCracking.cu __device__ int passcrack(char *crack){ char pass1[]="SH2973"; char pass2[]="KR3097"; char pass3[]="PK9736"; char pass4[]="BM4397"; char *s1 = crack; char *s2 = crack; char ...
21,979
#include <iostream> #include "../include/lglist.h" #include <thrust/device_vector.h> #define def_dvec(t) thrust::device_vector<t> #define to_ptr(x) thrust::raw_pointer_cast(&x[0]) using namespace std; __global__ void test(float *output){ gpu_linearized_stl::list<float,100> list; int idx = 0; output[idx++]...
21,980
#include <cuda.h> #include <stdio.h> __global__ void simpleKernel() { printf("Hello World!\n"); } int main() { const int numThreads = 4; // invoke GPU kernel, with one block that has four threads simpleKernel<<<1, numThreads>>>(); cudaDeviceSynchronize(); return 0; }
21,981
#include "includes.h" __global__ void kernelNormalizeMotionEnergyAsync(int bsx, int bsy, int n, float alphaPNorm, float alphaQNorm, float betaNorm, float sigmaNorm, float* gpuEnergyBuffer) { int bufferPos = threadIdx.x + blockIdx.x * blockDim.x; float sigmaNorm2_2 = 2*sigmaNorm*sigmaNorm; if(bufferPos < n) { int bx,by;...
21,982
#include <stdio.h> #include <time.h> __global__ void ken(double *a) { int id=blockIdx.x*blockDim.x+threadIdx.x; a[id]=pow((double)(4*id+1),-1)-pow((double)(4*id+3),-1); } __global__ void ken2(double *a,double *b,int *dcount) { int id=blockIdx.x*blockDim.x+threadIdx.x; int count=*dcount; if(count%2==0) { ...
21,983
#include <iostream> #include <math.h> #include <stdio.h> //function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { int index = blockIdx.x* blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; /*printf("threadIdx.x = %d threadIdx.y = %d threadIdx.z = %d\ blockIdx.x = ...
21,984
#include<iostream> #include<cstdio> using namespace std; __global__ void printDevice() { int x; x = threadIdx.x; printf(" Thread %d says Hello\n", x); } int main() { printDevice<<<2,10>>>(); }
21,985
#include <stdio.h> static void HandleError( cudaError_t err, const char *file, int line ) { if (err != cudaSuccess) { ::printf( "%s in %s at line %d\n", cudaGetErrorString( err ), file, line ); ::exit( EXIT_FAILURE ); } } #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__...
21,986
/** * Copyright 1993-2014 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...
21,987
#include "includes.h" __global__ void init(int *vector, int N, int val) { int i = threadIdx.x + blockIdx.x*blockDim.x; if (i < N) { vector[i] = val; } }
21,988
extern "C" __global__ void testKernel( float **inputPointers, float **outputPointers, int numPointers) { int tid = threadIdx.x + blockDim.x * blockIdx.x; if (tid < numPointers) { outputPointers[tid] = inputPointers[tid]; } }
21,989
#include"cuda_runtime.h" #include"device_launch_parameters.h" #include<stdio.h> #include<string.h> __global__ void convert(char *s, int n) { int id,r=0,k=0; id = threadIdx.x; int z; z=s[id]; while(z>0) { r = z%10; z=z/10; k = k*10+r; } s[id]=(char)k; } int main(void) { int n,i; char s[100]; ...
21,990
#include <iostream> #include <numeric> #include <stdlib.h> #include <stdio.h> typedef struct{ int width; int height; float* elements; } Matrix; #define BLOCK_SIZE 3 __global__ void MatMulKernel(const Matrix, const Matrix, Matrix); void MatMul(const Matrix A, const Matrix B, Matrix C) { Matrix d_A; d_A.width...
21,991
#include <stdio.h> #define N 10000 #define THREADS 100 __global__ void saxpy(float *A, float*B, float X, float Y){ int i = blockDim.x*blockIdx.x+threadIdx.x; B[i] = A[i]*X; B[i] += Y; } int main() { float A[N], B[N], B2[N], X, Y; float *A_d, *B_d; int i; dim3 dimBlock(THREADS); dim3 dimGrid(...
21,992
#include "includes.h" __global__ void conv(float *t, float *tk, float *out, int t_rows, int t_columns, int n_channels, int k_rows, int k_columns, int n_kernels) { const int i_out = blockDim.y * blockIdx.y + threadIdx.y, j_out = blockDim.x * blockIdx.x + threadIdx.x; int i0 = i_out - k_rows/2, j0 = j_out - k_columns/2;...
21,993
// wave 1D GPU // compile: nvcc -arch=sm_70 -O3 wave_1D.cu // run: ./a.out #include "stdio.h" #include "stdlib.h" #include "math.h" #include "cuda.h" #define DAT double #define GPU_ID 0 // typically 4 (0-3) on machines at stanford #define BLOCK_X 100 #define GRID_X 1 #define OVERLENGTH 1 //needed for extra ...
21,994
#include "includes.h" __global__ void NormalizationExecutionKernel(unsigned char* src, float* dst, const int size, const float alpha, const float beta, const float bias) { int index = blockIdx.x * blockDim.x + threadIdx.x; if(index < size){ dst[index] = (float)(src[index] - alpha) / beta + bias; } }
21,995
//pass //--gridDim=128 --blockDim=128 #include <cuda.h> __global__ void uniformAdd(float *g_data, float *uniforms, int n, int blockOffset, int baseIndex) { __shared__ float uni[1]; if (threadIdx.x =...
21,996
#include <iostream> #include <cstdlib> #include <cstdio> #include <curand_kernel.h> #include <thrust/reduce.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> #include <thrust/extrema.h> #include <thrust/device_ptr.h> #define N 10 using namespace std; struct node{ int base; int data; node ...
21,997
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #define ARRAY_SIZE 5000000 #define TPB 256 void fill_data(float *var) { int i; if(var == NULL) return; for(i=0; i<ARRAY_SIZE; i++) { var[i] = 100 * (float)((float)rand()/RAND_MAX); } } void saxpy_cpu(float *x, float *y, float A) { struct ti...
21,998
#include "includes.h" __global__ void set_carr(float br, float bi, float * c, int N) { int idx=blockIdx.x*blockDim.x+threadIdx.x; if(idx>=N) return; int idc=idx*2; c[idc]=br;c[idc+1]=bi; }
21,999
#include <stdio.h> #include <cuda_runtime.h> #define RANGESTART 40000000 #define RANGEEND 50000000 __device__ int is_prime(const int p) { for (int i = 3; i <= sqrtf(p); i++) { if (p % i == 0) { return 0; } } return 1; } __global__ void goldbach(int* result) { int id = blockIdx.x*blo...
22,000
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #define MIN -1024 #define MAX 1024 #define FALSE 0 #define TRUE 1 #include <unistd.h> #include <stdint.h> #include <stdlib.h> // #define BENCH_PRINT /*----------- using cycl...