serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
1,801
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <cuda.h> #define BLOCKSIZE 512 __global__ void gpu_phi(float *r, float *m, float *phi, int N) { int i; i = threadIdx.x + blockIdx.x*blockDim.x; if (i < N) { phi[i] = 0.0; for (int j=0; j<i; ++j) phi[i] -= m[j]/r[i]; ...
1,802
#include "includes.h" __global__ void func(void){ }
1,803
#include <stdio.h> int main(void) { cudaDeviceProp deviceProp; int dev = 0; cudaGetDeviceProperties(&deviceProp, dev); printf("Device number %d has name %s\n", dev, deviceProp.name); printf("Clock freq. (KHz): %d\n", deviceProp.clockRate); printf("The max grid size in x: %d, y: %d, z: %d\n", deviceProp.max...
1,804
#include "includes.h" __global__ void zupdate2_SoA(float *z1, float *z2, float *f, float tau, 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; float fc = f[i...
1,805
#include "includes.h" __device__ float sigmoid(float x) { return 1 / (1 + expf(-x)); } __global__ void produceState2(const float* arguments, const int argsSize, const float* weights, const int* topology, const int topSize, float* outStates) { const int tid = threadIdx.x; const int dim = argsSize + topSize; extern __sh...
1,806
#include "cuda_runtime.h" #include "device_launch_parameters.h" // #include <vld.h> #include <algorithm> #include <chrono> #include <iostream> #include <exception> #include <random> typedef double type_t; const size_t size = 2000; const size_t blockSize = 32; type_t* matrixCreate(); void matrixRelease(type_t *matri...
1,807
/* hello.cu */ #include <stdio.h> int main(){ printf("Hello World!\n"); return 0; }
1,808
#include<stdio.h> #define N 10 __global__ void suma_vect(int *a, int *b, int *c){ int tid = blockIdx.x; if(tid<N) c[tid] = a[tid]+b[tid]; } int main(void){ int a[N], b[N],c[N]; int *device_a, *device_b, *device_c; int i; //alojando en device cudaMalloc((void **)&device_a, sizeof(int)*N); cudaMalloc((void **)&...
1,809
#include <math.h> #include <stdio.h> const double EPSILON = 1.0e-15; const double a = 1.23; const double b = 2.34; const double c = 3.57; void __global__ add(const double *x, const double *y, double *z); void check(const double *z, const int N); int main(void) { const int N = 100000000; const int M = sizeof(...
1,810
#include "includes.h" __global__ void LowPassRowMulti(float *d_Result, float *d_Data, int width, int pitch, int height) { __shared__ float data[CONVROW_W + 2*RADIUS]; const int tx = threadIdx.x; const int block = blockIdx.x/(NUM_SCALES+3); const int scale = blockIdx.x - (NUM_SCALES+3)*block; const int xout = block*CONV...
1,811
#include "golden.cuh" #include "slicer.cuh" #include <thrust/sort.h> #include <thrust/functional.h> #include <stdio.h> long checkOutput(triangle* triangles_dev, size_t num_triangles, bool* in) { bool* expected = (bool*)malloc(NUM_LAYERS * X_DIM * Y_DIM * sizeof(bool)); std::cout << "executing golden model" << ...
1,812
#include <stdio.h> #include <math.h> #define N 10000000 #define THREADS_PER_BLOCK 1000 //cambia todos los numeros pares excepto el 2 __global__ void pares(char *a, int raiz) { //calcular index que este thread revisara int index = blockIdx.x * blockDim.x + (threadIdx.x * 2); //para que se salte el 2 if (...
1,813
#include "includes.h" __global__ void MultiplicarMatrices(float *m1, float *m2, float *mr, int columna1, int fila1, int columna2, int fila2) { int fila_r = blockIdx.y*blockDim.y+threadIdx.y; int columna_r = blockIdx.x*blockDim.x+threadIdx.x; float tmp_mult = 0; if ((fila_r < fila2) && (columna_r < columna1)) { for (in...
1,814
/* * file name: TilingMatrix.cu * NOTE: * squareMatrixMult is much more efficent than the regular multiplier * currently compiling with: nvcc TilingMatrix.cu -o tileTest * Device Standards for: GeForce GTX 1060 6GB * total global mem size: 6078 MBytes (6373572608 bytes) * t...
1,815
#include <cuda_runtime.h> #include <sys/time.h> #include <stdlib.h> #include <stdio.h> #define CUDA_CHECK(call) \ { \ const cudaError_t error = call; ...
1,816
#include <iostream> #include <vector> using namespace std; __global__ void mult(const int *pA, const int *pB, int *pC, int N) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < N) pC[i] = pA[i] * pB[i]; } int main(void) { const int N = 8192; vector<int> a(N), b(N), c(N); for (int i = 0 ; i < N ; i++) ...
1,817
#include <bits/stdc++.h> #define N 16 using namespace std; __global__ void RGBtoGray(float img[], float gray_img[]) { int ID = threadIdx.x + blockIdx.x * blockDim.x; for(int i = ID ; i < N * N; i += gridDim.x * blockIdx.x) { gray_img[i] = 0.21 * img[i * 3] + 0.71 * img[i * 3 +...
1,818
#include "includes.h" __global__ void knapsackKernel(int *profits, int *weights, int *input_f, int *output_f, int capacity, int c_min, int k){ int c = blockIdx.x*512 + threadIdx.x; if(c<c_min || c>capacity){return;} if(input_f[c] < input_f[c-weights[k-1]]+profits[k-1]){ output_f[c] = input_f[c-weights[k-1]]+profits[k-...
1,819
// Compile: nvcc -arch=sm_61 -std=c++11 assignment5-p2.cu -o assignment5-p2 #include <cmath> #include <cstdint> #include <iostream> #include <sys/time.h> #define THRESHOLD (0.000001) #define SIZE1 4096 #define SIZE2 4097 #define ITER 100 #define BLOCK_SIZE 16 using namespace std; #define gpuErrchk(ans) { gpuAssert...
1,820
#include "includes.h" __global__ void KernelVersionShim() { }
1,821
#include "includes.h" __global__ void reduction_kernel_complete_unrolling8_1(int * input, int * temp, int size) { int tid = threadIdx.x; int index = blockDim.x * blockIdx.x * 8 + threadIdx.x; int * i_data = input + blockDim.x * blockIdx.x * 8; if ((index + 7 * blockDim.x) < size) { int a1 = input[index]; int a2 = inp...
1,822
#include <iostream> #include <fstream> #include <cstdio> #include <chrono> #include <cmath> void init(double* const __restrict__ a, double* const __restrict__ at, const int ncells) { for (int i=0; i<ncells; ++i) { a[i] = pow(i,2)/pow(i+1,2); at[i] = 0.; } } void diff(double* const __restri...
1,823
#include "includes.h" __global__ void init_check(int *d_check, int nz) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i >= nz) { return; } d_check[i] = -1; }
1,824
#include "includes.h" __global__ void __dds0(int nrows, int ncols, float *A, float *B, int *Cir, int *Cjc, float *P) {}
1,825
#include <stdlib.h> #include <stdio.h> #include <cuda.h> __global__ void helloWorld(){ int threadIndex = threadIdx.x; int blockIndex = blockIdx.x; if(threadIndex%2 == 1) printf("Hello World from thread %d of block %d\n", threadIndex, blockIndex); else{ printf("hello from the other threads\n"...
1,826
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <cuda.h> #include <time.h> /* * Monte Carlo Pi Estimation Algorithm in CUDA * * This Project uses Cuda and thread * topology to estimate Pi. * * Author: Clayton Glenn */ #define MAX_THREAD 16 #define MIN_THREAD 8 #define MAX_...
1,827
#include "includes.h" __global__ void recombiner( double * rands , unsigned int * parents , unsigned int parent_rows , unsigned int parent_cols , unsigned int * off , unsigned int cols , unsigned int seq_offset ) { double id_offset = rands[ seq_offset + blockIdx.y ]; __syncthreads(); unsigned int col_offset = (blockId...
1,828
#pragma once #include "Vector3.cuh.cu" namespace RayTracing { class Ray { public: Point3 origin; Vector3 direction; public: __host__ __device__ Ray() {} __host__ __device__ Ray(const Point3 &origin, const Vector3 &direction) : origin(origin), direction(direction) {} __host__ __device__...
1,829
#include <stdio.h> void print_matrix(int *s, int N){ for(int i = 0; i < N; ++i){ printf("%i | ", s[i]); } } void init_matrix(int *m, int val, int N){ for(int i = 0; i < N; ++i){ m[i] = val; } } // kernel for run in GPU // This is a device code beacuse run in GPU __global__ void saxpy_CUDA(int...
1,830
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <math.h> #include <iostream> const int N = 1000000; const int blocksize = 256; __global__ void add_two_tab(unsigned int *a, unsigned int *b, unsigned int *c, unsigned int n) { ...
1,831
#include <stdio.h> // by lectures and "CUDA by Example" book // device code: array sum calculation: c = a + b __global__ void sum_arrays_kernel(float* a, float* b, float* c, int array_len) { printf("blockId, threadId: %d, %d\n", blockIdx.x, threadIdx.x); // element index that corresponds to current thread ...
1,832
#include<stdio.h> //gpu code __global__ void square(float * d_out,float *d_in) // arguments are pointers to input and the return is a value to the pointer in the argument list { int idx=threadIdx.x; float f= d_in[idx]; d_out[idx]=f*f; } //cpu code int main() { //generate input array const int ARRAY_...
1,833
#include <cuda_runtime.h> #include <stdio.h> __global__ void checkIndex(void) { printf("threadIdx: (%d, %d, %d) blockIdx: (%d, %d, %d) blockDim: (%d, %d, %d)" "gridDim: (%d, %d, %d)\n", threadIdx.x, threadIdx.y, threadIdx.z, blockIdx.x, blockIdx.y, blockIdx.y, blockIdx.z, blockDim.x, blockDim.y, blockDim.z, gridD...
1,834
// This program computes matrix multiplication on the GPU using CUDA // By: Nick from CoffeeBeforeArch #include <cstdlib> #include <cassert> #include <iostream> using namespace std; __global__ void matrixMul(int *a, int *b, int *c, int N){ // Calculate the global row and column for each thread int row = bloc...
1,835
#include <iostream> #include <stdlib.h> #include <string.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), f...
1,836
#include <stdio.h> #include <stdlib.h> #include "cuda.h" // This is my deviece function // __global__ means this function is visible to the host __global__ void kernelHelloWorld() { printf("Hello World!\n"); } int main(int argc, char** argv) { int Nblocks = 10; // number of blocks int Nthreads = 3; //number of t...
1,837
// Actually, there are no rounding errors due to results being accumulated in an arbitrary order.. // Therefore EPSILON = 0.0f is OK #define EPSILON 0.001f #define EPSILOND 0.0000001 extern "C" __global__ void compare(float *C, int *faultyElems, size_t iters) { size_t iterStep = blockDim.x*blockDim.y*gridDim.x*gridDi...
1,838
#include <stdio.h> __global__ void thread_per(float* a, float * b) { int index = threadIdx.x + blockIdx.x * blockDim.x; b[index] = sinf(a[index]); } void thread_per_block(int count) { float a[] = {0.0, 1.57, 2.57, 3.14}; float *b = (float*) malloc(sizeof(float) * 4); float *d_a; float *d_b; cudaMalloc((void...
1,839
#include <stdio.h> #include <time.h> #define SIZE 1024 __global__ void VectorAdd(float *a, float *b, float *c, int n) { int i = threadIdx.x; if (i < n) c[i] = a[i] + b[i]; } int main() { float *a, *b, *c; float *d_a, *d_b, *d_c; clock_t start, end; double cpu_time_used; a = (float *)malloc(SIZE*sizeof(floa...
1,840
__global__ void tsort1(int *input0,int *result0){ unsigned int tid = threadIdx.x; unsigned int bid = blockIdx.x; extern __shared__ __attribute__ ((aligned (16))) unsigned char sbase[]; (( int *)sbase)[tid] = ((tid&1)==0) ? min(input0[((bid*512)+tid)],input0[((bid*512)+(tid^1))]) : max(input0[((bid*512)+tid)],in...
1,841
#include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ char *arr; char *d_arr; unsigned long long size = atoll(argv[1]); arr = (char*)malloc(size); cudaMalloc(&d_arr,size); if(!arr){ printf("malloc error\n"); return 0; } cudaMemcpy(d_arr,arr,size,cudaMemcpyHostToDevice); free(arr); cu...
1,842
/*author: Zeke Elkins *date: 3/27/2014 *description: a simple hello world program -- introducing CUDA device syntax */ #include <iostream> using namespace std; __global__ void mykernel(void){ } int main(void) { mykernel<<<1,1>>>(); cout << "Hello World" << endl; return 0; }
1,843
__global__ void mat_hadamard(float *a, float *b, float *c, int rows, int columns) { const int i = blockDim.y * blockIdx.y + threadIdx.y, j = blockDim.x * blockIdx.x + threadIdx.x; if (i < rows && j < columns) { int k = i * columns + j; c[k] = a[k] * b[k]; } }
1,844
#include <stdlib.h> #include <stdio.h> #include <stdarg.h> #include <math.h> #include <time.h> #define SRC_LINES 10000 // 40 #define CMP_LINES 1000 // 4 #define LINE_MAXLEN 13000 // 100 #define BLOCK_SIZE 1000 // 4 /* Print error message and exit with error status. If PERR is not 0, display current errno status....
1,845
#include "includes.h" extern "C" { } #define TB 256 #define EPS 0.1 #undef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) #undef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) __global__ void patchmatch_r_conv_kernel( float *input, float *target, float *conv, int patch, int stride, int c1, int h1, int w1, int h2, ...
1,846
#include<iostream> #include<vector> #include<fstream> #include<sstream> #include<string> #include<iterator> #include<ctype.h> #include <iomanip> #include <math.h> #include <fstream> #include<cuda_runtime.h> using namespace std; vector<string> parFile; vector<string> particleConfig; __global__ void updateVel (double...
1,847
#ifndef GPUPRIMITIVE_DEF_CU #define GPUPRIMITIVE_DEF_CU #include "stdlib.h" #include <stdio.h> #include <cuda_runtime.h> //unsigned int gpuMemSize = 0; # define CUDA_SAFE_CALL( call) { \ cudaError err = call; \ if( cudaSuc...
1,848
/** * Copyright 2019 Matthew Oliver * * 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...
1,849
#include <stdio.h> const int N = 1; const int blocksize = 1; __global__ void kernelFunc() { } int main() { int b[N] = {4}; int *bd; const int isize = N*sizeof(int); printf("%i", *b); cudaMalloc( (void**)&bd, isize ); cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice ); // Allocate a big chunk of m...
1,850
#include "includes.h" __global__ void cuda_multi_matrix_on_vector(int *matrix, int *vector, int *new_vector, int numElements){ __shared__ int cache[threadsPerBlock]; const int idx = blockDim.x*blockIdx.x + threadIdx.x;//глобальный индекс const int tIdx = threadIdx.x;//индекс нити const int k = (numElements - 1 + thread...
1,851
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<time.h> #define NThreads 64 #define NBlocks 16 #define Num NThreads*NBlocks __global__ void bitonic_sort_step(int *arr, int i, int j) { unsigned int tid = blockIdx.x * blockDim.x + threadIdx.x; unsigned int tid_comp = tid ^ j; if (tid_comp > tid) { ...
1,852
#include "includes.h" __global__ void cn_pnpoly_reference_kernel(int *bitmap, float2 *points, float2 *vertices, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { int c = 0; float2 p = points[i]; // DO NOT MODIFY THIS KERNEL int k = VERTICES-1; for (int j=0; j<VERTICES; k = j++) { float2 vj = vertic...
1,853
//Submitted by GAutham M 15co118 and yashwanth 15co154 #include <stdio.h> int main() { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("Device Number: %d\n", i); printf(" Device name: %s\n", prop.name); p...
1,854
#include <assert.h> int IDX(const int r, const int z, const int NrTotal, const int NzTotal) { // Check for overflow: uncomment if sure. assert(r < NrTotal); assert(z < NzTotal); return r * NzTotal + z; } int nnz_calculator(const int NrInterior, const int NzInterior) { return 5 * NrInterior * NzInterior + 6 * NrI...
1,855
//pass //--blockDim=128 --gridDim=128 --warp-sync=32 --no-inline __global__ void foo(int* A) { A[ blockIdx.x*blockDim.x + threadIdx.x ] += (A[ (blockIdx.x + 1)*blockDim.x + threadIdx.x ]); }
1,856
#include "stdio.h" #include "stdlib.h" void print_array(int* array, int size) { for (int i = 0; i < size; ++i) { printf("%d ", array[i]); } } void generate_random_array(int* arr, int size) { for (int i = 0; i < size; ++i) { arr[i] = rand() % (size * 10); } }
1,857
//============================================================================= // // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // ...
1,858
#include <stdio.h> #include <string.h> #define THREADS_PER_BLOCK 32 __global__ void minA_cuda(int* a, int* b, int len, int n_output) { int b_index = threadIdx.x + blockIdx.x * THREADS_PER_BLOCK; int a_index = b_index * 2; if (b_index < n_output && a_index < len) { if (a_index == len-1) { b[b_...
1,859
#include "includes.h" __global__ void kernelUpdateParticle(float *positions,float *velocities,float *pBests,float *gBest,float r1,float r2) { int i=blockIdx.x*blockDim.x+threadIdx.x; if(i>=NUM_OF_PARTICLES*NUM_OF_DIMENSIONS) return; float rp=r1; float rg=r2; velocities[i]=OMEGA*velocities[i]+c1*rp*(pBests[i]-posit...
1,860
#include <stdio.h> #include <sys/resource.h> #define TILE_SIZE 16 #define SIZE (TILE_SIZE * 256) #define MALLOC_MATRIX(n) (float*)malloc((n)*(n)*sizeof(float)) float* device_malloc(int n){ float* m; if(cudaMalloc(&m, n*n*sizeof(float)) == cudaErrorMemoryAllocation) return NULL; return m; } __global__ void gpuPowe...
1,861
/* * * Copyright 1993-2012 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 relat...
1,862
//data-racer #include <cuda.h> #include <stdio.h> #define SIZE 2 #define TILES 4 #define LENGTH (TILES * SIZE) #define N 2 __global__ void matrix_transpose(float* A) { __shared__ float tile [SIZE][SIZE]; int x = threadIdx.x; int y = threadIdx.y; int tile_x = blockIdx.x; int tile_y = blockIdx.y; tile[x...
1,863
#include <stdio.h> #include <stdlib.h> #define ROWS 4 #define COLUMNS 5 typedef struct mystruct { int a[ROWS]; int **data; }mystruct; __global__ void printKernel(mystruct *d_var) { int i, j; for(i = 0; i < ROWS; i++) { for(j = 0; j < COLUMNS; j++) { printf("%d\t", d_var->data[i][j]); } printf("\n"); ...
1,864
#include <iostream> #include <algorithm> #include <cstdlib> #include <ctime> #include <cuda.h> #include <stdio.h> #include <cassert> //define the chunk sizes that each threadblock will work on #define BLKXSIZE 32 #define BLKYSIZE 4 #define BLKZSIZE 4 #define Q 19 #define lx 10 #define ly 10 #define lz 5 // for cuda er...
1,865
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <cuda.h> __global__ void image_conversion(unsigned char *colorImage, unsigned char *grayImage, int imageWidth, int imageHeight) { int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDi...
1,866
#include <stdio.h> #include <cuda.h> #define MAX_TESS_POINTS 32 struct BezierLine{ float2 CP[3];//control points for the line float2 vertexPos[MAX_TESS_POINTS];//Vertex position array to tessellate into //Number of tessellated vertices int nVertices; }; __forceinli...
1,867
#include "includes.h" typedef float dtype; #define N_ (8 * 1024 * 1024) #define MAX_THREADS 256 // threads per block #define MAX_BLOCKS 64 #define MIN(x,y) ((x < y) ? x : y) /* return the next power of 2 number that is larger than x */ __global__ void kernel5(dtype *g_idata, dtype *g_odata, unsigned int n) { _...
1,868
/* CSC691 GPU programming Project 3: Pi Time Jiajie Xiao Oct 23, 2017 */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define CHUNK 100000 __global__ void partialHist(char *input, int len, int *hist) { int i = threadIdx.x + blockDim.x*blockIdx.x; int number = input[i]-'0'; //printf("%c\t%d\...
1,869
/* * This sample implements a separable convolution * of a 2D image with an arbitrary filter. */ #include <stdio.h> #include <stdlib.h> #include <time.h> unsigned int filter_radius; #define FILTER_LENGTH (2 * filter_radius + 1) #define ABS(val) ((val) < 0.0 ? (-(val)) : (val)) #define accuracy 0.00005 #define ArrayS...
1,870
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <string.h> #include "scrImagePgmPpmPackage.h" void get_string_nocomments( FILE* fdin, char* s ) { int i,done; done=0; while( !done ) { fscanf( fdin, "%s", s ); for( i=0; !done; ++i ) { if( (s)[i] == '#' ) { fge...
1,871
#include "includes.h" __global__ void cuSort(float* data,int bucketSize,int* startPoint) { // int L= blockIdx.x * blockDim.x; int L= blockIdx.x*bucketSize; int U= L + bucketSize; int j; float tmp; startPoint[blockIdx.x] = L; for(int i=L+1; i < U; i++) { tmp=data[i]; j = i-1; while(tmp<data[j] && j>=0) { data[j+1] = da...
1,872
__device__ float sigmoid(float x) { return 1 / (1 + expf(-x)); } extern "C" __global__ void produceState2(const float* arguments, const int argsSize, const float* weights, const int* topology, const int topSize, float* outStates) { const int tid = threadIdx.x; const int di...
1,873
#include <stdlib.h> #include <stdio.h> void fill_matrix(double *mat, unsigned numRows, unsigned numCols) { for(unsigned i=0; i < numRows; i++) for(unsigned j=0; j < numCols; j++) { mat[i*numCols + j] = i*2.1f + j*3.2f; } } void print_matrix_to_file(double *mat, unsigned numRows, unsi...
1,874
#include <stdio.h> //////////////////////////float3//////////////////////////////// inline __device__ float3 operator+(float3 a, float b) { return make_float3(a.x + b, a.y + b, a.z + b); } inline __device__ float3 operator-(float3 a, float b) { return make_float3(a.x - b, a.y - b, a.z - b); } inline __device__ fl...
1,875
//#define TILE_DIM 1024 // //template<typename T> //__device__ void reverse(const T* vector, T* result, const int length) { //// __shared__ T tile[TILE_DIM]; //// __shared__ T anti_tile[TILE_DIM]; // extern __shared__ char m[]; // T* tile = (T*)m; // T* anti_tile = (T*)(m + blockDim.x * sizeof(T)); // // int bx =...
1,876
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <bits/stdc++.h> #include <curand.h> #include <curand_kernel.h> using namespace std; const int MAX_FES = 50000; int NL = 10; int LS = 4; int dim1 = 20; int dim2 = 1...
1,877
#include <stdio.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <cmath> #include <cstring> #define NSTREAM 4 #define BDIM 128 void initialData(float *ip, int size) { for (int i = 0; i < size; i++) { ip[i] = (float)(rand() & 0xFF) / 10.0f; } } void sumArraysOnHost(float *A, float *B, ...
1,878
// GPU kernel __global__ void process(float * data_out, int gap) { float res = 0.; int numthread = blockIdx.x * blockDim.x + threadIdx.x; bool pair = (((numthread*gap + gap-1) % 2) ==0); for(int i = (numthread*gap+gap-1); i >= (numthread*gap); i--){ res += (pair?1.:-1.)/(i+1.); pair = !pair; } data_out[numth...
1,879
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <iostream> using namespace std; void find_alive(){ } int main(){ int worldX, worldY; printf("Please enter the width of the array : "); scanf("%d", &worldX); printf("Please ent...
1,880
/* * Copyright 2019 Australian National University * * 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 applic...
1,881
#include <cuda.h> #include <stdio.h> #include <stdlib.h> __global__ void mandelKernel(int* d_data, int width, float stepX, float stepY, float lowerX, float lowerY, int count) { // To avoid error caused by the floating number, use the following pseudo code // // float x = lowerX + thisX * stepX; // floa...
1,882
/******************** * * CUDA Kernel: row gradient computing * */ /* ================================================== * * sub2ind - Column-major indexing of 2D arrays * */ template <typename T> __device__ __forceinline__ T sub2ind( T i, T j, T height) { return (i + height*j); } // end function 'sub2ind' ...
1,883
#include<stdio.h> #include<cuda.h> #include<curand.h> #include<iostream> #include<stdlib.h> #include<time.h> #include<cstdio> #include <assert.h> #define M 6 #define N 4000 #define K 9 #define C 1000 using namespace std; __global__ void multi_kernel(int *mn,int *m, int *n){ int xbidx = blockIdx.x; int ybidx = blo...
1,884
#include "includes.h" __global__ void inverse_variance_kernel(int size, float *src, float *dst, float epsilon) { int index = blockIdx.x*blockDim.x + threadIdx.x; if (index < size) dst[index] = 1.0f / sqrtf(src[index] + epsilon); }
1,885
#include "includes.h" __global__ void power_spectrum_kernel(int row_length, float *A_in, int32_t ldi, float *A_out, int32_t ldo) { int thread_id = threadIdx.x; int block_id = blockIdx.x; float *Ar = A_in + block_id * ldi; float *Aw = A_out + block_id * ldo; int half_length = row_length / 2; for (int idx = thread_id; i...
1,886
/** * 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 char * read_input_file( char * filename, int * size ) { char * buf ; off_t fsize; int fd = 0 ; ...
1,887
// // findCutoff.cu // //This file contains the function that determines the most //efficient number of assemblies to perform on the gpu #include <cuda.h> #include <iostream> void cudaAssemble(double Zs[],double Xs[], int num, double nZs[], double nXs[], int odd, int newlen); void cudaDisassemble(double OldAF[], dou...
1,888
#include "includes.h" __global__ void compute_potential_gpu(float *m, float *x, float *y, float *z, float *phi, int N, int N1) { int i,j; float rijx, rijy, rijz; float xi, yi, zi; float potential; i = threadIdx.x + blockIdx.x*blockDim.x; if (i < (N1 == 0 ? N : N1)) { xi = x[i]; yi = y[i]; zi = z[i]; for (j = (N1 == 0 ...
1,889
#include<stdio.h> #include<stdlib.h> /*the gpu kernel, to be launched on threads + blocks + grid heirarchy*/ __global__ void KERNEL_max(float *d_out, float *d_in, int DIM) { int idx = threadIdx.x; //threadIdx is a struct with 3 members, x,y, and z. int max_value = *(d_in + idx*DIM + 0); ...
1,890
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <assert.h> #include <cuda.h> #define u32 unsigned int #define u64 unsigned long #define uchar unsigned char #define BLOCK_SIZE 64 #define CREATE_RAND_ARR(arr, size, min, max) \ do { \ time_t t; ...
1,891
#include "includes.h" __global__ void devFillAffectedIndex(int nRemove, int maxTriPerVert, int *pTriangleAffectedIndex) { int n = blockIdx.x*blockDim.x + threadIdx.x; while (n < nRemove) { for (int i = 0; i < maxTriPerVert; i++) { pTriangleAffectedIndex[i + n*maxTriPerVert] = n; pTriangleAffectedIndex[i + n*maxTriPerV...
1,892
#include <stdio.h> int main(){ int nDevices; cudaGetDeviceCount(&nDevices); printf("%d devices found supporting CUDA\n", nDevices); for(int i = 0; i < nDevices; i++){ cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("----------------------------------\n"); printf("Device %s\n", prop.name); ...
1,893
#include<iostream> #include<stdlib.h> #include <cuda.h> #include <math.h> #define RADIUS 3 int checkResults(int startElem, int endElem, float* cudaRes, float* res) { int nDiffs=0; const float smallVal = 0.0001f; for(int i=startElem; i<endElem; i++) if(fabs(cudaRes[i]-res[i])>smallVal) ...
1,894
/* * dotproduct.cu * includes setup funtion called from "driver" program * also includes kernel function 'kernel_dotproduct[2]()' * largely inspired in the pdf http://www.cuvilib.com/Reduction.pdf */ #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define BLOCK_SIZE 1024 struct timeval tp1, tp2; #...
1,895
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> // includes, project #include <cuda.h> #define CUDA_SAFE_CALL_NO_SYNC( call) do { \ cudaError err = call; \ if( cudaSuccess != err) { ...
1,896
#include "includes.h" __global__ void set_bin(int *d_row_nz, int *d_bin_size, int *d_max, int M, int min, int mmin) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i >= M) { return; } int nz_per_row = d_row_nz[i]; atomicMax(d_max, nz_per_row); int j = 0; for (j = 0; j < BIN_NUM - 2; j++) { if (nz_per_row <= (min...
1,897
#include "includes.h" __global__ void PD_INPLACE_GPU_KERNEL(float *d_input, float *d_temp, unsigned char *d_output_taps, float *d_MSD, int maxTaps, int nTimesamples) { extern __shared__ float s_input[]; //dynamically allocated memory for now int f, i, gpos_y, gpos_x, spos, itemp; float res_SNR[PD_NWINDOWS], SNR, temp_...
1,898
#define COALESCED_NUM 16 #define blockDimX 256 #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 (threadId...
1,899
#include "cuda_runtime.h" #include <cstdio> template <typename T> using uCat = T(*)(T); template <typename T> using mCat = T(*)(T, T); __device__ int square(int a) { return a * a; } __device__ int mult(int a, int b) { return a * b; } template <typename T> __device__ T mult(T a, T b) { return a * b; } ...
1,900
__global__ void rectify_back_kernel(float *d_a, float *d_error, float *d_out, int size) { // Get the id and make sure it is within bounds const int id = threadIdx.x + blockIdx.x * blockDim.x; if (id >= size) { return; } const float x = d_a[id]; if (x > 0) { d_out[id] = d_error[i...