serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
3,701
#include<stdio.h> #include<stdlib.h> #define N 4 int main(void) { int arr[N][N] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16}}; printf("Original 2D array: \n"); for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ printf("%d ", arr[i][j]); } printf("\n"); } pr...
3,702
/* -------------------------------------------------------------------- OPTIMIZED CODE MAKING USE OF REGISTERS + SHARED MEMORY ----------------------------------------------------------------------*/ #include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x)...
3,703
/** * APPROXIMATE PATTERN MATCHING * * INF560 */ #include <string.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/time.h> #define APM_DEBUG 0 #define CHECK(x) \ do { \ if (!(x)) { \ fprintf(stderr, "%s:%d: ", __func__, __LINE__); \ perror(#x);...
3,704
 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> __global__ void addKernel(int *c, const int *a, const int *b) { int i = threadIdx.x; c[i] = a[i] + b[i]; } void printDeviceNames() { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = ...
3,705
/*** Implementation of Spatial Transformer Networks[1] Under Simplified BSD License by Che-Wei Lin [1] Max Jaderberg et al. Spatial Transformer Networks. NIPS 2015 ***/ __global__ void AffineForward(const float* bottom_data, const int* bs, const float* affine, const int len, float* top_data) { // bs ...
3,706
#include "includes.h" __device__ int index(int x, int y, int width) { return (y * width) + x; } __device__ const int FILTER_SIZE = 9; __device__ const int FILTER_HALFSIZE = FILTER_SIZE >> 1; __device__ void sort_bubble(float *x, int n_size) { for (int i = 0; i < n_size - 1; i++) { for(int j = 0; j < n_size - i - 1; j+...
3,707
#include "includes.h" __global__ void kernel_add_regularization_term(double * d_input_vector, int dimension, double regularization_parameter, double * d_rv) { if (threadIdx.x == 0) { double sum = 0; for (int i = 1; i < dimension; ++i) { sum += 0.5 * d_input_vector[i] * d_input_vector[i] * regula...
3,708
#include "includes.h" __device__ __host__ int maximum( int a, int b, int c){ int k; if( a <= b ) k = b; else k = a; if( k <=c ) return(c); else return(k); } __global__ void lower_right(int *dst, int *input_itemsets, int *reference, int max_rows, int max_cols, int i, int penalty) { int r, c; r = blockIdx.y*blockDim.y+...
3,709
#include "includes.h" __global__ void add(int *fData, int *sData, int *oData, int x, int y){ int index = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; for(int i = index; i < x*y; i += stride) { oData[i] = fData[i] + sData[i]; } }
3,710
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <math.h> #include <time.h> #include <curand_kernel.h> #include <curand.h> #include <sys/time.h> #define SEED 921 #define TPB 256 #define NUM_ITER 100000000 #define NUM_THREADS 10000 #define NUM_ITER_THREADS (NUM_ITER/NUM_THR...
3,711
#include <stdio.h> #include <stdlib.h> #include <math.h> #define BLOCK_SIZE 16 #define MAX(i,j) ( (i)<(j) ? (j):(i) ) #define MIN(i,j) ( (i)<(j) ? (i):(j) ) #define SubArrayA(x,y) subArrayA[(x)*BLOCK_SIZE+(y)] #define InputArrayA(x,y) inputArrayA[(x)*BLOCK_SIZE+(y)] #define ImageOut(x,y) imageOut[(x)*imageSize+(y)] ...
3,712
#include "includes.h" __global__ void square_i32 (int* vector, int* output, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { output[idx] = vector[idx] * vector[idx]; } }
3,713
#include <iostream> #include <iomanip> #include <sys/time.h> #include <cuda.h> // (*) include curand device library #include <curand_kernel.h> using namespace std; __global__ void setup_kernel(curandState *state, int init) { int id = threadIdx.x + blockIdx.x * blockDim.x; // (*) initialize curand generator //...
3,714
/*********************************************************************** ! Version 1: 04/16 SCR * ! * ! CUDA/C optimization of: * ! ...
3,715
#include <stdio.h> __global__ void testFunc() { //int x = blockIdx.x*blockDim.x + threadIdx.x; return; } __global__ void modifyMeshGPU(float a_fpTime, float* a_pfpMesh) { int x = blockIdx.x*blockDim.x + threadIdx.x; if(x<9) { if(0 == x%3) { a_pfpMesh[x] = a_pfpMesh[x] ...
3,716
#include "includes.h" __global__ void VecAdd() { }
3,717
#include <stdio.h> #include <cuda.h> __global__ void dkernel() { printf("Hello World!"); } int main() { dkernel<<<1, 1>>>(); cudaDeviceSynchronize(); return 0; }
3,718
#include<iostream> #include<fstream> #include<math.h> #include<stdlib.h> #include<curand_kernel.h> #include<curand.h> #include<time.h> #define MAX_CITIES 29 #define MAX_ANTS 14 #define Q 80 #define ALPHA 0.5 #define BETA 0.8 #define RHO 0.5 using namespace std; int n=0; int NC = 0; int t = 0; struct cities { ...
3,719
#include "includes.h" __global__ void ComputeCubes2Kernel( float *pointsCoordinates, float *vertexData, int quadOffset, float cubeSide, float *cubeOperation, float *cubeTexCoordinates, int *activityFlag, float textureWidth, int maxCells ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row ...
3,720
#include "includes.h" __global__ void CopyRectangleKernel( float *src, int srcOffset, int srcWidth, int srcRectX, int srcRectY, int rectWidth, int rectHeight, float *dest, int destOffset, int destWidth, int destRectX, int destRectY ) { int id = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blo...
3,721
#include <stdio.h> #include <stdlib.h> __device__ int smallerDst (int a, int b){ if(a < b){ return a; } else { return b; } } /*ending of device funtion */ __global__ void strongestNeighborScan_gpu(int * src, int * oldDst, int * newDst, int * oldWeight, int * newWeight, int * madeChanges, int distance, int n...
3,722
#include "includes.h" __global__ void unaccumulatedPartSizesKernel(int size, int *accumulatedSize, int *sizes) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx == 0) sizes[idx] = accumulatedSize[0]; else if (idx < size) { sizes[idx] = accumulatedSize[idx] - accumulatedSize[idx - 1]; } }
3,723
#include <iostream> #include <stdio.h> #include <cuda.h> #define BLOCK_SIZE 1024 #define checkCudaErrors(val) check( (val), #val, __FILE__, __LINE__) template<typename T> void check(T err, const char* const func, const char* const file, const int line) { if (err != cudaSuccess) { std::cerr << "CUDA error at: ...
3,724
#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 :...
3,725
/*************************************************************************** ************************************************************************** Spherical Harmonic Transform Kit 2.7 Copyright 1997-2003 Sean Moore, Dennis Healy, Dan Rockmore, Peter Kostelec Copyright 2004...
3,726
#include <iostream> #include <stdlib.h> #include <cuda_runtime.h> #include <stdio.h> using namespace std; typedef struct { int width; int height; float* data; } Matrix; #define BLOCK_SIZE 2 __global__ void MatMulKernel(const Matrix, const Matrix, Matrix); void showMatrix(Matrix m); void MatMaul(const ...
3,727
// nvcc jcaobi.cu -o jacobi #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define NBLOCKS 32 __global__ void compute_xnext(double *r, double *d, double *x, double *x_next, double *b, int size) { // Size defined as third arg in <<< >>> thing extern __shared__ double x_copy[]; // Copy x to multipl...
3,728
#include "includes.h" //#define ITEM_COUNT 2 #define _PI 3.14159265358979323846 #define _PI2 1.57079632679489661923 #define _RAD 6372795 using namespace std; cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); __global__ void geo_invert(double2* d_dot1, double2* d_dot2, double* d_d...
3,729
#include <cuda_runtime.h> #include <stdio.h> #include <time.h> #define CHECK(call)\ {\ const cudaError_t error = call;\ if (error != cudaSuccess)\ {\ printf("Error: %s:%d, ", __FILE__, __LINE__);\ printf("code: %d, reason: %s\n", error, cudaGetErrorString(error));\ exit(1);\ }\ }\ void sumArrayOnHost(flo...
3,730
#include <stdlib.h> #include <stdio.h> //#include <mpi.h> #include <png.h> #define checkCuda(error) __checkCuda(error, __FILE__, __LINE__) typedef struct { int r; int g; int b; int a; } RGBA; typedef struct{ int size; int width, height; png_byte color_type; png_byte bit_depth; png...
3,731
//pass //--blockDim=64 --gridDim=64 --no-inline #include "cuda.h" __device__ int f(int x) { return x + 1; } __global__ void foo() { int y = f(2); }
3,732
#include "includes.h" __global__ void histogram_kernel(unsigned int* input, unsigned int* bins, unsigned int num_elements, unsigned int num_bins){ extern __shared__ unsigned int bins_s[]; //Shared Memory int thid = threadIdx.x; while(thid < num_bins){ bins_s[thid] = 0u; thid += blockDim.x; } __syncthreads(); //His...
3,733
#include<stdio.h> __global__ void foo() {} int main(){ foo<<<1,1>>>(); cudaDeviceSynchronize(); printf("CUDA error: %s\n", cudaGetErrorString(cudaGetLastError())); return 0; }
3,734
#include "includes.h" # include <bits/stdc++.h> # include <cuda.h> #define SIZE 60// Global Size #define BLOCK_SIZE 1024 using namespace std; //::::::::::::::::::::::::::::::::::::::::::GPU:::::::::::::::::::::::::::::::: // :::: Kernel // :::: Calls __global__ void kernel_prefix_sum_inefficient(double *g_idata,...
3,735
#include <stdio.h> #include <cuda.h> #include <iostream> using std::cout; using std::endl; __global__ void square(float *a, int N) { int threadId = blockIdx.x * blockDim.x + threadIdx.x; if (threadId < N) a[threadId] = a[threadId] * a[threadId]; } int main(void) { float *h_a, *d_a; const int N = 50; siz...
3,736
#include "includes.h" __global__ void dummy() { }
3,737
// reference: https://gist.github.com/dpiponi/1502434 // compile: nvcc ./main.cu -o cuda // NOTES // - sudo apt-get install nvidia-cuda-toolkit // - must use .cu suffix to compile properly // - must have nVidia GPU with CUDA capabilities #define N 1000 #include <stdio.h> __global__ void fn( int *input, int *outpu...
3,738
#include "includes.h" __global__ void InitComputeAccelKernel (double *CellAbscissa, double *CellOrdinate, double *Rmed, int nsec, int nrad) { int j = threadIdx.x + blockDim.x*blockIdx.x; int i = threadIdx.y + blockDim.y*blockIdx.y; if (i<nrad && j<nsec){ CellAbscissa[i*nsec+j] = Rmed[i] * cos((2.0*PI*(double)j)/(doub...
3,739
#include "includes.h" #define FALSE 0 #define TRUE !FALSE #define NUMTHREADS 16 #define THREADWORK 32 __global__ void gpuSD(const float * vectsA, size_t na, const float * vectsB, size_t nb, size_t dim, const float * means, const float * numPairs, float * sds) { size_t offset, stride, tx = threadIdx.x, bx = blo...
3,740
__global__ void update_uo_multi_kernel0(double * d0_u, double * d0_uo, int N){ int i = blockIdx.x * blockDim.x + threadIdx.x + 1; int j = blockIdx.y * blockDim.y + threadIdx.y + 1; d0_uo[i*N + j] = d0_u[i*N + j]; } __global__ void update_uo_multi_kernel1(double * d1_u, double * d1_uo, int N){ int i = blockIdx.x ...
3,741
#include "includes.h" __global__ void rotateArray(int *c, int numThreads) { int nextIndex = (threadIdx.x + 1)%numThreads; int val = c[nextIndex]; __syncthreads(); c[threadIdx.x] = val; }
3,742
#include "includes.h" __global__ void activate_array_normalize_channels_kernel(float *x, int size, int batch, int channels, int wh_step, float *output_gpu) { int i = blockIdx.x * blockDim.x + threadIdx.x; int wh_i = i % wh_step; int b = i / wh_step; const float eps = 0.0001; if (i < size) { float sum = eps; int k; fo...
3,743
// //#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]; //} // //int mai...
3,744
#include<stdio.h> #include<stdlib.h> #define N 512 void host_add(int *a, int *b, int *c) { for(int idx=0;idx<N;idx++) c[idx] = a[idx] + b[idx]; } //basically just fills the array with index. void fill_array(int *data) { for(int idx=0;idx<N;idx++) data[idx] = idx; } void print_output(int *a, int *b, int*c) { ...
3,745
__global__ void transposeOptimized(float *input, float *output, int m, int n){ int colID_input = threadIdx.x + blockDim.x*blockIdx.x; int rowID_input = threadIdx.y + blockDim.y*blockIdx.y; __shared__ float sdata[32][33]; // bank ~ 一次传32 words,32次访问 ~ 32次unit time,所以希望存在shared memory里的数据尽可能多地分布在不同bank上 // 希望share...
3,746
#include "includes.h" __global__ void reduction_interleaved_unrolling_blocks2_1(int * input, int * temp, int size) { int tid = threadIdx.x; //start index for this thread int index = blockDim.x * blockIdx.x * 2 + threadIdx.x; //local index for this block int * i_data = input + blockDim.x * blockIdx.x * 2; //unrolling...
3,747
#include <stdio.h> #include <time.h> #include <unistd.h> #include <stdlib.h> #include <math.h> using namespace std; __global__ void _copy_dr_to_de(int *d_e,int *d_r,int X,int Y){ int x,y; x = threadIdx.x + (blockIdx.x*blockDim.x); y = threadIdx.y + (blockIdx.y*blockDim.y); int h_r_i = x + ( y * (X) ); ...
3,748
#include <bits/stdc++.h> #include <cuda.h> using namespace std; #define N ((int)1e3) #define TILE 32 #define CEIL(a, b) ((a-1)/b +1) __global__ void multiply(float *d_a, float *d_b, float *d_c) { int x = blockIdx.x*blockDim.x + threadIdx.x; int y = blockIdx.y*blockDim.y + threadIdx.y; __shared__ float a[TILE][TI...
3,749
#include <cstdio> #include <cstdlib> #include <cuda_runtime.h> #include <sys/time.h> #define random(a, b) (rand() % (b - a) + a) #define index(i, j, col) (((i) * (col)) + (j)) void PrintMatrix(float *A, int row, int col); void FillMatrix(float *matrix, int row, int col, int padding); __global__ void im2col(float *ma...
3,750
#include <stdio.h> __global__ void gpu_shared_memory(float *d_a) { int i, index = threadIdx.x; float average, sum = 0.0f; // Defining shared memory __shared__ float sh_arr[10]; sh_arr[index] = d_a[index]; // This directive ensure all the writes to shared memory have completed __syncthreads(); for (i ...
3,751
// compute.cu // // driver and kernel call #include <stdio.h> // for printf #include <stdlib.h> // for malloc #include <string.h> // for memcpy() #include <unistd.h> // for sleep() #include <math.h> // for pow() #include <stdbool.h> // for bool #define THREADS_PER_BLOCK 512 __global__ void compute_d (double...
3,752
/* * cuda_flow_recog8u_binary.c * * Created on: Jan 27, 2016 * Author: sled */ // // Threshold-based Contrasting GPU implementation // #include <unistd.h> #include <stdlib.h> #include <stdint.h> #include <math.h> #define THREADS_PER_BLOCK 128 // CUDA kernel declaration __global__ void cuda_flow_binary_ke...
3,753
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <cuda.h> static void checkCudaCall(cudaError_t result) { if (result != cudaSuccess) { printf("cuda error \n"); exit(1); } } __global__ void vectorAddKernel(float* deviceA, float* deviceB, float* deviceResult...
3,754
__device__ double f(double x) { return cos(x); }
3,755
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define N 2 __global__ void foo() { __shared__ int A[8]; A[0] = threadIdx.x; }
3,756
#include "includes.h" __global__ void Step(float * x, size_t idx, size_t N) { for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < N; i += blockDim.x * gridDim.x) { if (x[(idx-1)*N+i] > 0 ) x[(idx-1)*N+i] = 1.0 ; else x[(idx-1)*N+i] = 0.0 ; } return; }
3,757
#include <stdio.h> #include <cuda_runtime_api.h> #include <time.h> /***************************************************************************** * * * * * * Compile with: * nvcc -o cudapassword 2initialpass_cuda.cu * * Dr Kevan Buckley, University of Wolverhampton, 2018 *****************************...
3,758
#include <iostream> #include <cuda_runtime.h> #include <stdlib.h> #include <time.h> // Variables globales GPU y CPU #define l_kernel 3 #define stride 3 /****************************** * Procesamiento Matriz CPU * ******************************/ /* * Funcion Max */ float MaxCPU(float A, float B){ float result...
3,759
#include "includes.h" __global__ void set_chunk_data( int x, int y, double dx, double dy, double* cell_x, double* cell_y, double* cell_dx, double* cell_dy, double* vertex_x, double* vertex_y, double* volume, double* x_area, double* y_area) { const int gid = blockIdx.x*blockDim.x+threadIdx.x; if(gid < x) { cell_x[gid] ...
3,760
#include <iostream> #include <cmath> __global__ void add(int n, float* x, float* y) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; for (int i = index; i < n; i += stride) { y[i] = x[i] + y[i]; } } int main() { int N = 1 << 28; size_t size = N * sizeof(float); flo...
3,761
#include<bits/stdc++.h> using namespace std; #define pi (2.0*acos(0.0)) #define eps 1e-6 #define ll long long #define inf (1<<29) #define vi vector<int> #define vll vector<ll> #define sc(x) scanf("%d",&x) #define scl(x) scanf("%lld",&x) #define all(v) v.begin() , v.end() #define me(a,val) memset( a , val ,sizeof(a) ) #...
3,762
#include "includes.h" __global__ void CircumPlanetaryMassKernel (double *Dens, double *Surf, double *CellAbscissa, double *CellOrdinate, double xpl, double ypl, int nrad, int nsec, double HillRadius, double *mdcp0) /* LISTA */ { int j = threadIdx.x + blockDim.x*blockIdx.x; int i = threadIdx.y + blockDim.y*blockIdx.y; ...
3,763
#include <iostream> extern "C" __global__ void count_frequency(int * input, int * output, unsigned width, unsigned height) { int baseX = blockIdx.x * blockDim.x + threadIdx.x; int totalThreads = blockDim.x * gridDim.x; for(int elementIndex = baseX; elementIndex < width; elementIndex += totalThreads) { int i =...
3,764
#include <stdio.h> int main() { cudaDeviceProp prop; int count; cudaGetDeviceCount(&count); printf("Number of CUDA-enabled GPU devices: %d\n", count); for(int i=0; i<count; i++) { cudaGetDeviceProperties(&prop, i); printf("Device %d: \"%s\"\n", i, prop.name); printf(" Compute Capability: ...
3,765
#include <stdio.h> #include <time.h> void onCPU(float* A, float* B, float* xNow, float* xNext, int Ni) { int i,j; float sum; for (i=0; i<Ni; i++) { sum = 0.0; for (j=0; j<Ni; j++) { if (i != j) { sum += A[i*Ni + j] * xNow[j]; } } xNex...
3,766
#include<stdio.h> __global__ void hello_from_gpu() { int gDim = gridDim.x; int bDim = blockDim.x; int bid = blockIdx.x; int tid = threadIdx.x; printf("Hello World from block %d/%d and thread %d/%d!\n", bid, gDim , tid, bDim); } int main(void) { hello_from_gpu<<<2, 3>>>(); cudaDeviceReset();...
3,767
// Copyright (c) 2020 Saurabh Yadav // // This software is released under the MIT License. // https://opensource.org/licenses/MIT /* --------------------------------------------------- My Hello world for CUDA programming --------------------------------------------------- */ #include <stdio.h> #include...
3,768
#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...
3,769
#include "includes.h" #define N 10000000 #define MAX_ERR 1e-6 __global__ void vector_add(float* out,float* a,float* b,int n){ int index = threadIdx.x; int stride = blockDim.x; for(int i=index ; i<n ;i=i+stride){ out[i]=a[i]+b[i]; } }
3,770
#include<stdio.h> int main() { int dev; cudaDeviceProp devprop; cudaGetDevice(&dev); cudaGetDeviceProperties(&devprop,dev); printf("name = %s\ntotal global mem = %1fM\nshared mem per block = %1fK\nregs per block = %d\nwarp size = %d\nclock rate = %1fGHz\nmax threads per block= %d\ntotal const mem = %1fK\nmultipro...
3,771
//http://stackoverflow.com/questions/22217628/integral-image-or-summed-area-table-of-2d-matrix-using-cuda-c #include <iostream> #include <cuda_runtime.h> #include <stdlib.h> #include <stdio.h> #define BLOCK_DIM_X 16 #define BLOCK_DIM_Y 16 using namespace std; __global__ void sat(int *a, int*b, int rowsTotal,int colsT...
3,772
#include "includes.h" __global__ void sax_kernel(const float a, const float* x, float* result, unsigned int len) { unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) result[idx] = a * x[idx]; }
3,773
__global__ void kernel_initial(float *img, int nx, int ny, int nz, float value){ int ix = 16 * blockIdx.x + threadIdx.x; int iy = 16 * blockIdx.y + threadIdx.y; int iz = 4 * blockIdx.z + threadIdx.z; if (ix >= nx || iy >= ny || iz >= nz) return; img[ix + iy * nx + iz * nx * ny] = value; }
3,774
/*The number of threads per block and the number of blocks per grid specified in the <<<...>>> syntax can be of type int or dim3. Two-dimensional blocks or grids can be specified as in the example above. Each block within the grid can be identified by a one-dimensional, two-dimensional, or three-dimensional index acc...
3,775
// Author: Ayush Kumar // Roll No: 170195 // Compile: nvcc -g -G -arch=sm_61 -std=c++11 assignment5-p1.cu -o assignment5-p1 #include <cmath> #include <cstdint> #include <cuda.h> #include <iostream> #include <new> #include <sys/time.h> #define THRESHOLD (0.000001) #define SIZE1 8192 #define SIZE2 8200 #define ITER 10...
3,776
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]){ cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, 0); printf(" Device: \"%s\"\n", deviceProp.name); printf(" Compute Capability: %d.%d\n", devicePro...
3,777
/* * Last name: Gupta * First name: Vaibhav * Net ID: vvg239 * */ #include <stdlib.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <time.h> void seq_gen_primes(int); __global__ void remove_for_divisor(bool*, unsigned int, int); __global__ void remove_all(bool*, unsigned i...
3,778
#include <cuda.h> #include <stdio.h> #include <stdlib.h> __device__ int mandel(float c_re, float c_im, int count) { float z_re = c_re, z_im = c_im; int i; for (i = 0; i < count; ++i) { if (z_re * z_re + z_im * z_im > 4.f) break; float new_re = z_re * z_re - z_im * z_im; float new_im = 2.f *...
3,779
#include <stdlib.h> #include <stdio.h> #include <time.h> #define THREADS 1024 #define BLOCKS 65536 #define NUM_VALS THREADS*BLOCKS #define ASCENDING 1 #define DESCENDING 0 void rand_nums(int *values, unsigned long length) { int i; for (i = 0; i < length; ++i) { values[i] = rand() % INT_MAX + 1;; }...
3,780
#include "includes.h" __global__ void vecAdd(float* d_A, float* d_B, float* d_C) { int i = blockDim.x * blockIdx.x + threadIdx.x; if(i<TAM) d_C[i] = d_A[i] + d_B[i]; }
3,781
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <stdio.h> #include <iostream> using namespace std; __global__ void matrixMultiply(int *d_a, size_t pitch_a, int *d_b, size_t pitch_b, int *d_c, size_t pitch_c, const int N, const...
3,782
#include<iostream> #include<cmath> #include<thrust/host_vector.h> using namespace std; void populate_ac_angles(float* ac_angles, int num_actions); void populate_ac_angles(float* ac_angles, int num_actions){ //fills array with equally spaced angles in radians for (int i = 0; i < num_actions; i++) ac_ang...
3,783
#include "includes.h" __global__ void histKernel(char *inData, long size, unsigned int *histo) { __shared__ unsigned int temp[BIN_COUNT][BIN_COUNT]; __shared__ unsigned int blockSum[BIN_COUNT]; int i = 0; while(i < BIN_COUNT) temp[i++][threadIdx.x] = 0; __syncthreads(); int tid = threadIdx.x + blockIdx.x * blockDim....
3,784
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void gpuAdd(int *d_a, int *d_b, int *d_c) { *d_c = *d_a + *d_b; } int main() { //Defining host variables int h_a, h_b, h_c; //Defining Device Pointers int *d_a, *d_b, *d_c; //Initializing host variables h_a = 1; h_b ...
3,785
/* College: University of Massachusetts Lowell EECE 7110:High-Performance Comp. on GPUs Semester: Spring 2018 Student : 01639617 Project : Assignment_2 Professor : Dr.Hang Liu Due date: 2/12/2017 Authors : Sai Sri Devesh Kadambari */ #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> using n...
3,786
#include <stdio.h> #include <cuda_runtime.h> /** * CUDA Kernel Device code * done nothing */ __global__ void kernel(void) {} /** * Host main routine */ int main(void) { kernel<<<1,1>>>(); printf("Hello World\n"); return 0; }
3,787
// tests cuEventCreate #include <iostream> #include <memory> using namespace std; #include <cuda.h> __global__ void longKernel(float *data, int N, float value) { for(int i = 0; i < N; i++) { data[i] += value; } } void test1() { int N = 102400; CUstream stream; cuStreamCreate(&stream, 0...
3,788
#include <cstdio> #include <iostream> const int size = 5; __global__ void add(int *a, int *b, int *c){ int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; int idx = i + size * j; if(i < size && j < size){ c[idx] = a[idx] + b[idx]; } } int main(){ ...
3,789
#include <cstddef> #include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <time.h> #define BLOCK_SIZE 32 #define BIG_BLOCK 64 const int INF = ((1 << 30) - 1); __global__ void cal_phase1(int* Dist, int numOfVertex, int round){ int newDist; int big_ty = threadIdx.y * 2; int big_tx = thre...
3,790
#include "includes.h" __global__ static void pack(const int* prefix_sum, const int* src, int* dst, const int nb_vert) { const int p = blockIdx.x * blockDim.x + threadIdx.x; if(p < nb_vert){ const int elt = src[p]; if(elt >= 0) dst[ prefix_sum[p] ] = elt; } }
3,791
/** * Given some kernel with positional arguments (n -> columns, m -> rows), below * is how to calculate the row/col being worked on and the index into a * linearized matrix. See also http://en.wikipedia.org/wiki/Row-major_order */ __global__ void SomeKernel(float * d_in, float * d_out, int cols, int rows) { int ...
3,792
//#pragma once //#include "cuda_runtime.h" //#include "vector_operations.cuh" // //__device__ float3 operator+(float3 f1, float3 f2) //{ // return make_float3(f1.x + f2.x, f1.y + f2.y, f1.z + f2.z); //} // //__device__ float3 operator-(float3 f1, float3 f2) //{ // return make_float3(f1.x - f2.x, f1.y - f2.y, f1.z - f2....
3,793
#include <stdio.h> #include <cuda_runtime.h> /** * @brief * * @param m * @param n * @param A * @param lda * @param name */ void printMatrix(int m, int n, const float *A, int lda, const char *name) { for (int row = 0; row < m; row++) { for (int col = 0; col < n; col++) { float Areg = A[row + ...
3,794
#include<stdio.h> #include<iostream> //using the struct of cudaDeviceProp getting the information of gpu void printDeviceProp(cudaDeviceProp devProp){ printf("Name: %s\n", devProp.name); printf("Maximum thread per block: %d\n", devProp.maxThreadsPerBlock); for(int i = 0; i < 3; i++) printf("Maximum dimension...
3,795
#include "includes.h" __global__ void expMinus(float* out, float* in, int size){ int id = blockIdx.x * blockDim.x + threadIdx.x; if(id < size) out[id] = __expf(-in[id]); }
3,796
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <unistd.h> #include <sys/time.h> /* Problem size */ #define M 1024 #define N 1024 #define FLOAT_N 3214212.01 void init_arrays(double* data) { int i, j; for (i = 1; i < (M+1); i++) { for (j = 1; j < (N+1); j++) { data[i*(N+...
3,797
#include <stdlib.h> #include <stdio.h> #include <time.h> #define THREADS 16 #define BLOCKS 32 #define WIDTH (THREADS * BLOCKS) int size = WIDTH * WIDTH * sizeof(float); float *M, *N, *P; float *gpuM, *gpuN, *gpuP; time_t seed; void initGPU(int devNum){ cudaSetDevice(devNum); cudaMalloc((void**)&gpuM, size); c...
3,798
#include <stdio.h> #include <stdlib.h> #include <cuda.h> __global__ void hello_kernel(char *odata, int num) { char hello_str[480] = "#######################################\n _ _ _ \n | | | | | | \n | |__| | ___ _ __ __ _| | ___ ___ \n | __ |/ _ \\ '_...
3,799
#include <stdio.h> #include <stdlib.h> #define SIZE 10 int main(int argc , char **argv){ int * p; cudaError_t err; err=cudaMalloc((void**)&p,SIZE*sizeof(int)); if( err != cudaSuccess) { printf("CUDA error: %s\n", cudaGetErrorString(err)); exit(-1); } int i; for(i=0;i<SIZE;i++){ //Accessing vari...
3,800
#include <stdio.h> #include <stdlib.h> #define BLOCK_SIZE 32 extern "C" { __global__ void mul_matrix(int *A, int *B, int *C, int n){ unsigned int i; int product = 0; int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; if(row < n && col < n){ for (i = 0; i...