serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
16,701
#include "includes.h" // ERROR CHECKING MACROS ////////////////////////////////////////////////////// __global__ void matrixMultiplicationKernelNaive(const float* A, const float* B, float* C, int a, int b, int c, int d) { int ROW = blockIdx.y*blockDim.y+threadIdx.y; int COL = blockIdx.x*blockDim.x+threadIdx.x; floa...
16,702
/******************************************************************************* * serveral useful gpu functions will be defined in this file to facilitate * the set calculus toolbox scheme, i.e., to calculate gradients,normal vectors, * curvatures, Heaviside function and Dirac_Delta function *********************...
16,703
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #define CUDA_ERROR_EXIT(str) do{\ cudaError err = cudaGetLastError();\ if( err != cudaSuccess){\ printf("Cuda Error: '%s' for %s\n", cudaGetErrorString(err), str);\ exit(-1);\ }\ }while(0); __global__ void Xor(int *dX,int num) { ...
16,704
extern "C" { __device__ long computeCell(const long *A, const long *B, long *C, int row, int col, long n) { long v=0; if (row < n && col < n) { for (long i=0; i<n; i++) { v += A[i + row*n] * B[col + i*n]; } } return v; } __global__ void MatrixMultiply( const long *A,...
16,705
//general parts #include <stdio.h> #include <vector> #include <memory> #include <string.h> #include <chrono> #include <thread> #include <iostream> #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif #include <inttypes.h> //CUDA parts #include "cuda_runtime.h" #include "device_launch_parameters.h" #include...
16,706
#include <thrust/sort.h> #include <iostream> #include <cstdlib> #include <ctime> int main() { /* initialize random seed: */ srand ( time(NULL) ); const int N = 100; int A[N]; for (int i = 0 ; i < N; i++) { /* generate secret number: */ A[i] = rand() % 10 + 1; } thrust::sort(A, A+N); for (int i = 0...
16,707
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <time.h> #define N 600 #define DIMS 2 #define epsilon 0.1 #define ss 1 #define blocksize 16 #define BLK (blocksize*blocksize) #define dimGrid (N / BLK + 1) __device__ float distance(float *a, float *b) { int i; float d = 0.0,...
16,708
#include<stdio.h> #include<string> #include<fstream> #include<iostream> #include <curand_kernel.h> #include <vector> #include <sstream> #define p 334214459 #define TABLESIZE 100000 #define maxiterations 10 #define KEYEMPTY -1 #define NOTFOUND -100 __device__ unsigned long long table[TABLESIZE]; __device__ unsig...
16,709
// System includes #include <stdio.h> // CUDA runtime #include <cuda_runtime.h> extern const int rrmax=16; void matvec_serial(double *A, double *x, double *y, int n) { printf("hello in subroutine \n"); for(int j=0;j<n;++j){ y[j] = 0; for(int i=0;i<n;++i){ y[j] = y[j] + A[i + n*j] * x[i]; }...
16,710
#include "includes.h" __global__ void sortAtomsGenCellListsAlt(unsigned int natoms, const float4 *xyzr_d, const float4 *color_d, const unsigned int *atomIndex_d, unsigned int *sorted_atomIndex_d, const unsigned int *atomHash_d, float4 *sorted_xyzr_d, float4 *sorted_color_d, uint2 *cellStartEnd_d) { extern __shared__ un...
16,711
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <cuda_runtime.h> #define WIDTH 1024 #define THREADSPERBLOCK 16 #define BLOCKSPERGRID 1 int M[WIDTH][WIDTH] = {0}; int N[WIDTH][WIDTH] = {0}; int P[WIDTH][WIDTH] = {0}; int MxN[WIDTH][WIDTH] = {0}; __global__ void mat_mul(int *Md, int *Nd, int *Pd);...
16,712
#include "includes.h" __global__ void gpu_sobel_kernel_naive(u_char *Source, u_char *Resultat, unsigned width, unsigned height) { int j = blockIdx.x*blockDim.x + threadIdx.x; int i = blockIdx.y*blockDim.y + threadIdx.y; u_char val; int globalIndex = i*width+j; if ((i==0)||(i>=height-1)||(j==0)||(j>=width-1)) {Resultat[...
16,713
// Array add example, 2D #include <iostream> #include <iomanip> const size_t array_size_x = 32; const size_t array_size_y = 16; // Good macro for making sure we know where things went wrong... #define checkCudaErrors(val) check_cuda( (val), #val, __FILE__, __LINE__ ) void check_cuda(cudaError_t result, char const *c...
16,714
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> using namespace std; #define i_size 6//image size #define o_size 6 #define k_size 3//kernel size int input[i_size][i_size]; int kernel[k_size][k_size]; int output[i_size][i_size]; typedef int itype[i_size]; typedef ...
16,715
#define MAT1 4 #define MAT2 MAT1*MAT1 #define TINY 1.0e-40 #define a(i,j) a[(i)*MAT1+(j)] #define GO 1 #define NOGO 0 __device__ void d_pivot_decomp(float *a, int *p, int *q){ int i,j,k; int n=MAT1; int pi,pj,tmp; float max; float ftmp; for (k=0;k<n;k++){ pi=-1,pj=-1,max=0.0; //find pivot in subma...
16,716
#include "includes.h" __global__ void magnitudeCopy(float *mag_vec, float *vec, const int n) { unsigned int xIndex = blockDim.x * blockIdx.x + threadIdx.x; if (xIndex < n) { mag_vec[xIndex] = abs(vec[xIndex]); } }
16,717
#include <stdio.h> __global__ void kernel() { int num = threadIdx.x + blockIdx.x * blockDim.x; printf("Thread index: %d\n",num); } int main() { kernel<<<4, 2>>>(); cudaDeviceSynchronize(); return 0; }
16,718
#include "includes.h" __global__ void kAccumulateColumns(float* mat, float* indices, float* target, int mat_width, int target_width, int height, float mult, int avg){ const int row = gridDim.x * blockIdx.y + blockIdx.x; const int column = threadIdx.x; if (row < height && column < target_width) { float cur_sum = 0.0; un...
16,719
#include "includes.h" __global__ void calc_output(unsigned char * img_out, unsigned char * img_in, int * lut, int img_size){ /* Get the result image */ int ix = blockIdx.x * blockDim.x + threadIdx.x; int iy = blockIdx.y * blockDim.y + threadIdx.y; const int gridW = gridDim.x * blockDim.x; int img_position1 = iy * gridW...
16,720
#include "matrix/Matrix.cuh" #include "matrix_utils/svd.cuh" #include <stdio.h> #include <chrono> // CATCH_CUDA_ERR(cudaMalloc(&dev_array, sizeof(int) * used_n)); // CATCH_CUDA_ERR(cudaMemcpy(dev_array, array, sizeof(int) * used_n, cudaMemcpyHostToDevice)); int main() { // int i1 = 10, i2 = 10, i3 = 10, i4 = 10, i...
16,721
#include<stdio.h> long int getimageinfo(FILE *fp,long int start, long int total_bytes) { int j; long int i; unsigned char c; long int total=0; fseek(fp,start,SEEK_SET); for(j=0,i=start;i<(start+total_bytes);i++,j++) { fread(&c,sizeof(unsigned char),1,fp); total+=pow(256,j)*(int)c; } return total; } vo...
16,722
#include "includes.h" __global__ void returnStatistic ( const int dim, const int nwl, const float *xx, float *s ) { int i = threadIdx.x + blockDim.x * blockIdx.x; int j = threadIdx.y + blockDim.y * blockIdx.y; int t = i + j * dim; if ( i < dim && j < nwl ) { s[t] = powf ( xx[t], 2. ); } }
16,723
// CUDA by Example // Ch10.4: using a single CUDA stream #include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #define N (1024*1024) #define FULL_DATA_SIZE (N*20) static void HandleError(cudaError_t err, const char *file, int line) { if (err != cudaSucces...
16,724
#include<stdio.h> #define W 16 #define H 16 #define Mask 3 __global__ void Conv(int *input, int *output, int *mask) { int x= blockIdx.x * Mask + threadIdx.x; // Thread Column Index. int y= blockIdx.y * Mask + threadIdx.y; // Thread Row Index. int Sum=0; for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++) ...
16,725
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <time.h> #define TILE_SIZE 16 // buffers for gpu processing unsigned char *d_input; unsigned char *d_output_blur; unsigned char *d_output_sobel; unsigned char *d_output_nms; unsigned char *d_output_thresh; unsigned char *d_output; double *d_edge_direct...
16,726
#include <stdio.h> #include <stdint.h> #include <string> #include <cmath> #include <algorithm> using namespace std; #define CHECK(call)\ {\ const cudaError_t error = call;\ if (error != cudaSuccess)\ {\ fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__);\ fprintf(stderr, "code: %d, reas...
16,727
/********************************************************* File : lcsGetGroupsForBlocks.cu Author : Mingcheng Chen Last Update : January 29th, 2013 **********************************************************/ #include <stdio.h> #define BLOCK_SIZE 1024 __global__ void GetNumOfGroupsForBlocksKernel(int *startOffsetIn...
16,728
#include <stdio.h> #include <cuda.h> #include <cuda_runtime.h> void print_array(float *A, int N) { for(int i=0;i<N;i++) printf("%.2f ",A[i]); printf("\n"); } __global__ void process_kernel1(float *input1, float *input2, float *output, int datasize) { int numElements = datasize / sizeof(float); ...
16,729
/* primer practica Moi */ #include <stdlib.h> #include <stdio.h> #include <math.h> /* Definicion de bloques y threads por bloque */ #define N 1000000 #define THREADS_PER_BLOCK 1000 /* Números a evaluar */ #define max 1000000 //kernel de CUDA __global__ void primos(int *n_c, int *raiz_c) { //sacamos el index int i...
16,730
/***************************************************************************** Example : cuda-prefix-sum.cu Objective : Write a CUDA program to find prefix sum of an given array. Input : None Output : Execution time in seconds , Gflops achieved ...
16,731
#include "random.cuh" /*線形合同法*/ __device__ static unsigned int randx = 1; __device__ void Srand(unsigned int s){ randx = s; } __device__ unsigned int Rand(){ randx = randx*1103515245+12345; return randx&2147483647; } /*XORSHIFT*/ __device__ static unsigned long xors_x = 123456789; __device__ static unsigne...
16,732
#include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define ceil(a,b) ((a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1) void check_error (const char* message) { cudaError_t error = cudaGetLastError (); if (error != cudaSuccess) { printf ("CUDA error :...
16,733
#include <stdio.h> #include <cuda_runtime.h> __global__ void add(int *c) { *c *= 2; printf("Hello, World!\n"); } int main(void) { int c = 2; int *dev_c; //cudaMalloc() cudaMalloc(&dev_c, sizeof(int)); cudaMemcpy(dev_c, &c, sizeof(int), cudaMemcpyHostToDevice); //核函数执行 add<<<1,1>>>(...
16,734
#include <assert.h> #include <limits.h> #include <stdio.h> #define ALLOC_SIZE 126 #define HTD_ROW_OFFSET 4 #define DTH_ROW_OFFSET 4 int main() { const unsigned int ALLOC_WIDTH_BYTES = ALLOC_SIZE*sizeof(int); cudaPitchedPtr devMem; cudaExtent extent = make_cudaExtent(ALLOC_WIDTH_BYTES, ALLOC_SIZE, 1); ...
16,735
#include "includes.h" __global__ void aggregateEnergies(double *energies, int numEnergies, int interval, int batchSize) { int idx = batchSize * interval * (blockIdx.x * blockDim.x + threadIdx.x), i; for (i = 1; i < batchSize; i++) { if (idx + i * interval < numEnergies) { energies[idx] += energies[idx + i * interval];...
16,736
#include "stdio.h" #define N 10 //Sum Arrays __global__ void add(int *x, int *y, int *z){ int tID = blockIdx.x; if (tID < N){ z[tID] = x[tID] + y[tID]; } } int main(){ int x[N], y[N], z[N]; int *dev_x, *dev_y, *dev_z; /*Allocates size bytes of linear memory on the device and returns in *devPtr a pointe...
16,737
#include <iostream> #include <string> //格式化输入输出 #include <iomanip> #include "cuda_runtime.h" #include "device_launch_parameters.h" //通过文件进行数据的输入输出 #include <fstream> // 使用字符串流读取文件中的数据 #include <sstream> /* 对于本机GTX850M来说,当Threads Per Block = 1024,registers per thread = 32, shared memory per blocks(bytes)=1024时可以...
16,738
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #define OPERATOR * #define OPERATOR_NAME "multiplication" #define DTYPE float void random_ints(int* a, int N) { int i; for (i = 0; i < N; ++i) a[i] = rand(); } void random_floats(float* a, int N) { for (int i = 0; i < N; ++i)...
16,739
// Copyright 2020 Marcel Wagenländer __global__ void divmv(float *X, float *y, int n, int m) { // n rows, i is blockIdx.x // m columns, j is threadIdx.x int idx = threadIdx.x * n + blockIdx.x; if (idx < n * m && y[blockIdx.x] != 0.0) { X[idx] = X[idx] / y[blockIdx.x]; } } void div_mat_vec(...
16,740
/* This program is designed to take the first derivative of a 3 dimensional function */ // includes, system #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <complex.h> // includes, project #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <cufft.h> #includ...
16,741
#include <thrust/device_vector.h> template <typename PairType> __device__ void load_pair_array(PairType* arr, PairType* pair_ptr) { if constexpr (sizeof(PairType) == 4) { auto const tmp = *reinterpret_cast<ushort4 const*>(pair_ptr); memcpy(&arr[0], &tmp, 2 * sizeof(PairType)); } else { auto const tmp =...
16,742
#include "thrust_all.cuh" //#ifndef __CUDACC_EXTENDED_LAMBDA__ //#error "please compile with --expt-extended-lambda" //#endif template <typename T> struct mul_const{ T const_val; mul_const(T input){const_val = input;} __host__ __device__ T operator()(T x){ return const_val*x; } }; int main(void) { c...
16,743
#include "includes.h" __global__ void simple_vbo_kernel(float4 *pos, unsigned int width, unsigned int height, float time) { unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; // calculate uv coordinates float u = x / (float) width; float v = y / (float) height; ...
16,744
#include <iostream> #include <cstdlib> #include <limits> using namespace std; #define Nparticles 30 #define T_MAX 1000 #define NFC_MAX 1000000 #define W_0 0.9 #define W_T 0.4 #define MAX_V 2.0 #define c1 2.0 #define c2 2.0 #define Nvariab...
16,745
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #define N 10000000 #define MAX_ERR 1e-6 __global__ void relu(double *out, double *in, int n) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if (tid < n){ out[tid] = (in[tid]>0)?...
16,746
extern "C" __global__ void exponentiationKernel (int length, float *source, float *destination) { int globalId = blockDim.x * blockIdx.x + threadIdx.x; if(globalId < length) { destination[globalId] = expf(source[globalId]); } }
16,747
#include <cuda.h> #include <stdio.h> #include <math.h> #define N 1<<20 #define BLOCK_SIZE 1<<7 __global__ void add(int* a, int* b, int* c) { size_t index = blockIdx.x * blockDim.x + threadIdx.x; size_t stride = blockDim.x * gridDim.x; for (size_t i = index; i < N; i += stride) { c[i] = a[i] + b[...
16,748
#include <stdio.h> #include <stdlib.h> #include <set> #include <sstream> #include <string> #include <fstream> #include <iostream> #include <cstring> #include <curand.h> #include <curand_kernel.h> using namespace std; //#include <device_vector.h> //cudaMallocManaged(& bins, numC*numV*sizeof(int)); /* __global__ vo...
16,749
inline __device__ int iterate(float re0, float im0, int count) { float re = re0; float im = im0; for (int i = 0; i < count; ++i) { if (re * re + im * im > 4.0) { return i; } float tmp = re * im; re = re * re - im * im + re0; im = tmp + tmp + im0; } ...
16,750
#include "includes.h" __global__ void transposeSmemPadDyn(float *out, float *in, int nx, int ny) { // static shared memory with padding extern __shared__ float tile[]; // coordinate in original matrix unsigned int ix, iy, ti, to; ix = blockDim.x * blockIdx.x + threadIdx.x; iy = blockDim.y * blockIdx.y + threadIdx.y; ...
16,751
__global__ void fillTwoIntegerArraysKernel( int numberRows, int numberEntries, int* firstArray, int firstConstant, int* secondArray, int secondConstant) { int index = blockIdx.x * numberEntries + blockIdx.y * numberRows + threadIdx.x; firstArray[index] = firstConstant; secondArray[...
16,752
// 16CO145 - Sumukha PK // 16CO234 - Prajval M #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/functional.h> #include <thrust/transform.h> #include <algorithm> #include <cstdlib> #include <iostream> #include <fstream> #include <vector> int main(int argc, char * argv[]){ std::if...
16,753
#include "includes.h" __global__ void float_to_color(uchar4 * pixels, float* in){ int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; int offset = x + y * blockDim.x * gridDim.x; float num = in[offset]; pixels[offset].x = (int)(num*255); pixels[offset].y = (int)(0); pixels[of...
16,754
//****************************************************** // Project // Names: Anthony Enem // Parallel Programming Date: 12/05/16 //****************************************************** // This program implements the cooley tukey fft algorithm // and computes the values fro X_k from 0 to N in parallel. //************...
16,755
#include <stdio.h> #include "math.h" #include <pthread.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #define PORT 2084 #define MAXLINE 1024 /* I will provide a word about tx,ty, and tz. tx does not, in fact move the actual poi...
16,756
#include <stdio.h> #include <cuda.h> #include <stdlib.h> #include <time.h> #include <string.h> __global__ void mul(float *Ad, float *Bd, float *Cd, int msize, int tilewidth); int main( int argc, char **argv){ clock_t start = clock(); int i, j; int tile; int msize; msize = atoi(argv[1]); //matrix size tile...
16,757
#include <stdio.h> __global__ void saxpy(int n, float a, float *x, float *y) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { y[i] = a * x[i] + y[i]; } } int main() { int n = 1000000; float a = 2.0; float *x, *y, *d_x, *d_y; size_t size = n * sizeof(float); // All...
16,758
#include "includes.h" __device__ double atomicAdd_dB(double* address, double val) { unsigned long long int* address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull, assumed; do { assumed = old; old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val + __longlong_as_dou...
16,759
#include "includes.h" __global__ void updZ(float *z, float *f, float tz, float beta, int nx, int ny) { int px = blockIdx.x * blockDim.x + threadIdx.x; int py = blockIdx.y * blockDim.y + threadIdx.y; int idx = px + py*nx; float a, b, t; if (px<nx && py<ny) { // compute the gradient a = 0; b = 0; if (px<(nx - 1)) a = f[...
16,760
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <cuda_runtime.h> #define N 1024*1024*1024 #define KERNELSIZE 9 #define THREADSPERBLOCK 1024 #define BLOCKSPERGRID (N+THREADSPERBLOCK-1)/THREADSPERBLOCK // 9 wide 1d kernel, no padding so it cuts out early // shift by 4 to align w...
16,761
__global__ void addExternalForces(const float dt, const float2 force, const float * d_levelset, const float * d_velIn_x, const float * d_velIn_y, float * d_velOut_x, float * d_velOut...
16,762
#include <stdio.h> __global__ void add( int *a, int *b, int *c ) { *c = *a + *b; } int main( void ) { int a=2, b=7, c; // host copies of a, b, c int *dev_a, *dev_b, *dev_c; // device copies of a, b, c int size = sizeof( int ); // we need space for an integer cudaMalloc( (void**)&dev_a, size ); cudaMallo...
16,763
// Uses multiple kernel calls keeping each node as source so that label of v won't get updated before it's block starts executing. // As might lead to the another iteration in the search and later v's potential might again get changed // by some other u giving inconsistent potential values(paths). #include <math.h> ...
16,764
__global__ void applyWallBoundaries(float *U, int m, int n) { // Wall boundaries are applied by mirroring the two cells nearest the // boundary and changing the sign of the normal discharge component // Calculate the row and column of the thread within the thread block int row = blockIdx.y * blockDim.y + thread...
16,765
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <sys/time.h> #define bufSize 700000 struct timeval startwtime,endwtime; float *h_a; // Table at host float *d_a; // Table at device int tsize=0; // number of rows or columns size_t size = 0 ; // size of table( tsize* tsize *...
16,766
#include "includes.h" /*********************************************************** By Huahua Wang, the University of Minnesota, twin cities ***********************************************************/ __global__ void zexp( float* Z, float* X, float* Y, unsigned int size) { const unsigned int idx = blockIdx....
16,767
#include "includes.h" __global__ void func (char* stringInput, int stringSize, int* integerInput, char* dummySpace) { int counter = 0; for (int i=0;i<stringSize;i++) dummySpace[counter++] = stringInput[i]; for (int i=0;i<sizeof(int);i++) dummySpace[counter++] = ((char*)integerInput)[i]; }
16,768
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> double get_time() { struct timeval tv; cudaThreadSynchronize(); gettimeofday(&tv, NULL); return double(tv.tv_sec+tv.tv_usec*1e-6); } int const N = 1000000; int const THREADS = 64; int const NCRIT = THREADS; float cons...
16,769
#include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define ceil(a,b) ((a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1) void check_error (const char* message) { cudaError_t error = cudaGetLastError (); if (error != cudaSuccess) { printf ("CUDA error :...
16,770
#define uchar unsigned char // 8-bit byte #define uint unsigned int // 32-bit word // DBL_INT_ADD treats two unsigned ints a and b as one 64-bit integer and adds c to it #define DBL_INT_ADD(a,b,c) if (a > 0xffffffff - (c)) ++b; a += c; #define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b)))) #define ROTRIGHT(a,b) (((a)...
16,771
#include<stdio.h> #include<stdlib.h> #include<cuda.h> __global__ void add(int *a, int *b, int *c) { int i= blockIdx.x*blockDim.x+threadIdx.x; c[i]= a[i]+b[i]; } int main() { // host pointers int *a; int *b; int *c; //device pointers int *d_a; int *d_b; int *d_c; a=(int *)malloc(10*sizeof(int)); b=(in...
16,772
#include <stdio.h> #include <cuda.h> void Output(float* a, int N) { for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++) fprintf(stdout, "%g\t",a[j + i * N]); fprintf(stdout, "\n"); } fprintf(stdout, "\n\n\n"); } __global__ void gInitializeStorage(float* storage_d) { int i = threadIdx.x + blockIdx.x * ...
16,773
/* * Alyxandra Spikerman * High Perfomance Computing * Homework 6 - Question 1 */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #define n 64 // taken from transpose.cu from HW5 #define TIMER_CREATE(t) \ cudaEvent_t t##_start, t##_end; \ cudaEventCreate(&t##_star...
16,774
#include <stdio.h> #include <cuda.h> #include <assert.h> #define N 10000000 #define UPPER N*4 #define LOWER 1 #define THREADS_PER_BLOCK 512 __global__ void lsearch(int *a, int n, int x, int *index); void rand_init_array(int *array, int n, int upper, int lower); void display_array(int *array, int n); int main(void) ...
16,775
/* ============================================================================ Filename : implementation.cu Author : Jonas Blanc, Mélissa Gehring SCIPER : 287508, 264265 ============================================================================ */ #include <iostream> #include <iomanip> #include <sys/ti...
16,776
#include "includes.h" __global__ void MinusMeanKernel (double *Dens, double *Energy, double SigmaMed, double mean_dens_r, double mean_dens_r2, double mean_energy_r,double mean_energy_r2, double EnergyMed, int nsec, int nrad, double SigmaMed2, double EnergyMed2) { int j = threadIdx.x + blockDim.x*blockIdx.x; int i = 0; ...
16,777
/* Write GPU kernels to compete the functionality of estimating the integral via the trapezoidal rule. */
16,778
#include "includes.h" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C" extern "C...
16,779
/* * testStream.cu * * Created on: Sep 17, 2017 * Author: zy */ #include <iostream> using namespace std; #include "cuda_runtime.h" #include "device_launch_parameters.h" void testDeviceGPU() { cudaDeviceProp prop; int whichdevice; cudaGetDevice(&whichdevice); cudaGetDeviceProperties(&prop,whichdevice);...
16,780
#include "includes.h" __global__ void calcSoftmaxSumForwardGPU(float *array, float *out, float *max, float *sum, int *mutex, int batch_size, int in_size_x, unsigned n) { unsigned int index = threadIdx.x + blockIdx.x * blockDim.x; unsigned int stride = gridDim.x * blockDim.x; unsigned int offset = 0; // __shared__ floa...
16,781
__global__ void scp(int *a, int *b, int gsize) { /*@ requires gsize == blockDim.x; ensures \forall i; 0 <= i && i < gsize -> b[i] == (i+1) % gsize; */ int tid = threadIdx.x; a[tid] = tid; __syncthreads(); b[tid] = a[(tid+1) % gsize]; }
16,782
#include "includes.h" // GPU¸¦ À§ÇÑ Ä¿³Î ÇÁ·Î±×·¥(NVCC°¡ ÄÄÆÄÀÏÇÔ) __global__ void addKernel(int* c, const int * a, const int * b) { int i = threadIdx.x; c[i] = a[i] + b[i]; }
16,783
#include <stdio.h> #include <stdlib.h> #include <math.h> #define TILE_WIDTH 16 __global__ void _gpu_m_add(int *a, int *b, int *c, int rows, int columns) { int i = TILE_WIDTH * blockIdx.y + threadIdx.y; int j = TILE_WIDTH * blockIdx.x + threadIdx.x; if (i < rows && j < columns) c[i * columns + j] ...
16,784
#include<iostream> #include<cstdlib> #include<fstream> #include<string> #include<sys/time.h> typedef unsigned long long int UINT; using namespace std; __global__ void GPU(int *dev_table, int startIdx, int curjobs, const int rowsize, int startx, int starty){ int thread = blockIdx.x * blockDim.x + threadIdx.x; if ...
16,785
#include "cuda_runtime.h" #include "vec_kernels.cuh" #include "stddef.h" #include <cmath> __global__ void mat_transpose(double *X, double *Xt, size_t m, size_t n) { size_t gid = threadIdx.x + blockIdx.x * blockDim.x; if (gid >= m*n) return; size_t row = gid / n; size_t col = gi...
16,786
/* This code will multiply two vectors and check the result. */ #include <cuda.h> #include <thrust/device_vector.h> #include <thrust/inner_product.h> #include <iostream> #include <stdio.h> #define CUDA_CHECK {cudaThreadSynchronize(); \ cudaError_t err = cudaGetLastError();\ if(err){\ std::cout << "Error: "...
16,787
//pass //--gridDim=1024 --blockDim=512 #include "common.h" __global__ void bitonicSortShared1( uint *d_DstKey, uint *d_DstVal, uint *d_SrcKey, uint *d_SrcVal ) { //Shared memory storage for current subarray __shared__ uint s_key[SHARED_SIZE_LIMIT]; __shared__ uint s_val[SHARED_...
16,788
//fail //--blockDim=64 --gridDim=64 --no-inline #include <cuda.h> #include <stdio.h> #include <assert.h> #define DIM 2//64 #define N 2 //DIM*DIM typedef struct { float x,y,z,w; } myfloat4; __global__ void k(float * i0) { myfloat4 f4; f4.x = 2; i0[threadIdx.x + blockDim.x*blockIdx.x] = f4.x; }
16,789
#include <stdio.h> /* * Refactor `loop` to be a CUDA Kernel. The new kernel should * only do the work of 1 iteration of the original loop. */ /** * cpu实现 */ void loop(int N) { for (int i = 0; i < N; ++i) { printf("CPU This is iteration number %d\n", i); } } /** * gpu实现 */ __global__ void loop() { ...
16,790
extern "C" { __device__ inline int threadIdx_x() { return threadIdx.x; } __device__ inline int threadIdx_y() { return threadIdx.y; } __device__ inline int threadIdx_z() { return threadIdx.z; } __device__ inline int blockIdx_x() { return blockIdx.x; } __device__ inline int blockIdx_y() { return blockIdx.y; } __device__ ...
16,791
#pragma once #ifdef __INTELLISENSE__ void __syncthreads(); #endif #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cuda.h> #include <stdio.h> #include <time.h> #include <ctime> #define BLOCK_DIM 4 #define ARRAY_SIZE 12 __global__ void reduction(int *d_in, int *d_out) { ...
16,792
#include "includes.h" __global__ void cuda_debug_kernel() { }
16,793
/**** Archivo: cuda.cu **/ #include <stdio.h> #include <unistd.h> #include <cuda.h> __global__ void kernel(int dato,int rank, int *gpu_dato){ *gpu_dato= dato + rank; } extern "C" int run_kernel(int dato, int rank) { int *gpu_dato; cudaMalloc( (void**)&gpu_dato, sizeof(int)); kernel<<<1,1>>>(dato, rank, gpu_dato); cuda...
16,794
#include "includes.h" __global__ void CopyInputToVisFieldKernel( float *input, float *visField, int inputSize ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blockDim.x*blockIdx.x //blocks preceeding current block + threadIdx.x; if(threadId < inputSize) { visField[thread...
16,795
#include "includes.h" __global__ void cu_repmat(const float *a, float* dst, const int rowsa, const int colsa, const int rowsdst, const int colsdst, const int n){ int tid = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; while(tid < n){ int c2 = tid % colsdst; int r2 = tid / colsdst; int ra =...
16,796
#include "includes.h" __global__ void bootstrap3(int bins, int num_els, int num_boots, float *g_idata, double *g_odata, unsigned int *g_irand) { float myResample; int constant = ( 4294967295 / ( bins ) ); int id = threadIdx.x + blockDim.x * blockIdx.x; int dmid = bins * ( blockDim.y * blockIdx.y + threadIdx.y ); for (...
16,797
#include <iostream> // Kernel function to add the elements of two arrays __global__ void add(int n, int *x, int *y, int a) { int tid = blockIdx.x*blockDim.x + threadIdx.x; if(tid<n) x[tid] = a*x[tid] + y[tid]; } int main(void) { int dNum = 1<<20; int *x, *y; // memory size for each array size_...
16,798
/********************************************************************************************** Source Code : sharedMemoryReadingSameWord.cu Objective : Example code to demonstrate the different access patterns of float3 array in the global memory the corresponding advantages in terms of ...
16,799
/* Copyright 2019 Cleuton Sampaio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in w...
16,800
#include "includes.h" __device__ __host__ float cpu_applyFilter(float *image, int stride, float *matrix, int filter_dim) { float pixel = 0.0f; for (int h = 0; h < filter_dim; h++) { int offset = h * stride; int offset_kernel = h * filter_dim; for (int w = 0; w < filter_dim; w++) { pixel += image[offset + w] * ...