serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
4,201
#include "includes.h" __global__ void init(int* U, int* F, int* d, int startNode, size_t gSize) { int globalThreadId = blockIdx.x * blockDim.x + threadIdx.x; if (globalThreadId < gSize) { U[globalThreadId] = 1; F[globalThreadId] = 0; d[globalThreadId] = INT_MAX; } if(globalThreadId == 0) { d[globalThreadId] = 0; U[gl...
4,202
#define DIM 64 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <math.h> #include <stdio.h> #include <cuda.h> #include <time.h> #include <cuda_runtime_api.h> #include <stdio.h> #include <assert.h> #include <stdlib.h> #include <chrono> #define TILE_DIM 32 __global__ void MatrixMulKernel(doubl...
4,203
#include "includes.h" __global__ void Substep1Kernel (double *Pressure, double *Dens, double *VradInt, double *invdiffRmed, double *Potential, double *Rinf, double *invRinf, double *Vrad, double *VthetaInt, double *Vtheta, double *Rmed, double dt, int nrad, int nsec, double OmegaFrame, int ZMPlus, double IMPOSEDDISKDRI...
4,204
#include <stdlib.h> #include <stdio.h> #define SIZE 1365 __global__ void func(int* a, int s) { int i = (blockIdx.x * 1024) + threadIdx.x; if(i > s) return; a[i] = i; return; } int main(int argc, char** argv) { int* a; int i, s, s2; s = SIZE; if(s > 1024) s2 = 1024; else s...
4,205
#include "../include/object.cuh" #include "../include/math_utils.cuh" __host__ __device__ Object::Object(const Material &mat): mat{mat} {} __host__ __device__ Sphere::Sphere(const vec3 &center, float radius, const Material &mat): Object{mat}, center{center}, radius{radius} {} __host__ __device__ bool Sphere::in...
4,206
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda.h> #include <sys/time.h> /* Aim : To benchmark the GPU in terms of Read and Write Bandwidth with different types of block sizes. Description : This program finds Read and Write Memory Bandwidth of GPU. The main function ...
4,207
#include "includes.h" __global__ void MatrixAdd_CUDA(int *A, int *B, int *C) { int i= blockIdx.y*blockDim.y+ threadIdx.y; int j = blockIdx.x*blockDim.x+ threadIdx.x; *(C + i*N + j) = *(A + i*N + j)+ *(B + i*N + j); }
4,208
#include <iostream> #include <chrono> #include <vector> inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { std::cerr << "GPUassert: " << cudaGetErrorString(code) << " " << file << " " << line << std::endl; if (abort) exit(code); } } ...
4,209
#include <stdio.h> #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); if (abort) exit(code);...
4,210
#include "includes.h" __global__ void tanh(float *inout, float *bias, int rows, int cols) { int j = blockIdx.x * blockDim.x + threadIdx.x; int i = blockIdx.y * blockDim.y + threadIdx.y; if (j >= cols || i >= rows) return; inout[i * cols + j] = tanhf(inout[i * cols + j]) + bias[i]; }
4,211
__global__ void kernel(int * vals, int size){ int tid = blockDim.x * blockIdx.x + threadIdx.x; int stride = blockDim.x * gridDim.x; for (; tid < size; tid += stride) { vals[tid] *= 2; } } extern "C" int foo(int size){ int * vals; int * devVals; cudaMallocHost((void**)&vals, size * sizeof(vals[0])); cudaM...
4,212
#include <assert.h> extern "C" __device__ void exit(int ret) __THROW { assert(0); }
4,213
#include <cuda_runtime.h> #include <stdio.h> #include <iostream> using namespace std; __global__ void checkIndex(void) { // printf("- thread idx is : "); printf( "thread idx: %d, %d, %d\n" , threadIdx.x , threadIdx.y , threadIdx.z ); printf( "block idx: %d , %d, %d\n", blockIdx.x , blockIdx.y , blockI...
4,214
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <complex> #include <iostream> #include <algorithm> #include <stdio.h> #include <cufft.h> #include <fstream> #include <vector> #include <numeric> #include <math.h> #define PI 3.14159265359 using namespace std; __device__ cufftComplex com_exp(cu...
4,215
#include "includes.h" //*************inclución de librerias*************** //************variables globales*************** int N=93, dimx=1920, dimy=2560, tam_imag=1920*2560; //**********KERNEL************** float *leerMatrizVarianza(int d); //*****************función main********************** __global__ void k...
4,216
// Include header files #include <bits/stdc++.h> #include <cuda.h> #include <cmath> #define ll long long int #define THREADS 32 typedef float2 Complex; const long long ARRAY_SIZE = 1024; const long long ARRAY_BYTES = ARRAY_SIZE * sizeof(Complex); // Parallelized reordering (Doesn't this count as pre-processing?) __...
4,217
extern "C"{ __global__ void globalForwardReduction(const double *a_d, const double *b_d, const double *c_d, double *d_d, const double *k1_d, const double *k2_d,...
4,218
#include <stdio.h> #include <cuda.h> #include <cuda_runtime.h> #define LOG_INPUT if(0) #define LOG_OUTPUT if(1) #define LOG if(0) __global__ void hadamard(float *A, float *B, float *C, int M, int N) { // Complete the kernel code snippet int i = threadIdx.x + blockDim.x * blockIdx.x; if(i < M*N) C[i]...
4,219
#include <cstdio> #include <vector> #include <iostream> #include <cmath> #include <cstdlib> #include <chrono> using namespace std; const int nx = 41; const int ny = 41; //const int nt = 10; const int nit = 50; //const int c = 1; __global__ void build_up_b(float *b, int rho, float dt, float dx, float dy, float *u , fl...
4,220
#include <cuda_fp16.h> #define ELEMENT_SIZE 64 #define BLOCK_SIZE 64 #define WEIGHT_MAX_LENGTH 2048 extern "C" //use constant memory for weights if needs to be faster __global__ void weighted_sum_kernel(__half *ret, const long *input, const __half...
4,221
// in this code we do not use sparsity because the matrices are small // all matrices therefore are full // we assume that all the matrices are stored in a linear array, in a column major form // the maximum graph size is set to 12 in the variable MAX_N_PERM but it can be increased if the GPU is more powerfull // TO-D...
4,222
#include <cuda.h> #include <stdio.h> #include <sys/time.h> #include <stdio.h> #define N 128 #define NELEMS (N * N) #define SCHEME 1 #define TRANSP 1 #define CUDA_CHECK_RETURN(value) \ { \ cudaError_t _m_cudaStat =...
4,223
 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void addArrays(int* A, int* B, int* C) { int i = blockIdx.x * blockDim.x + threadIdx.x; C[i] = A[i] + B[i]; } int main(void) { int N = 1024; int *A, *B, *C; // Crea los buffer, con Unified Memory, para los datos de...
4,224
__device__ float relu (float x) { return fmaxf(x, 0.0); } extern "C" __global__ void reluKernel (int length, float *source, float *destination) { int index = blockDim.x * blockIdx.x + threadIdx.x; if(index < length) { destination[index] = relu(source[index]); } }
4,225
#include <stdio.h> extern "C" void test() { printf("success!\n"); }
4,226
#include <stdio.h> __global__ void UpdatePositions( int N,double L, double2* r, double2* r5){ int i= threadIdx.x + blockIdx.x*blockDim.x; if (i<N){ r[i].x = r5[i].x; r[i].y = r5[i].y; if (r[i].x*r[i].x + r[i].y*r[i].y > L*L) printf("%d is outside region. %1.4f %1.4f\n",i,r[i].x,r[i].y); } }
4,227
// 1D convolution example using CUDA C++ // Each block takes in a bunch of elements and computes a 1D convolution using multiple threads #include <iostream> // Global parameters #define NUMBLOCKS 8 #define BLOCKSIZE 4 #define RADIUS 1 #define NUMELEMENTS (NUMBLOCKS * BLOCKSIZE) // Function and macro to handle CUDA...
4,228
#include <stdio.h> #include <stdlib.h> #include <time.h> void init(float *A, int wA, int hA) { for (int h=0; h<hA; h++) for (int w=0; w<wA; w++) A[w+h*wA] = (float)rand() / (float)RAND_MAX; } void compute(float *A, float *B, float *C, int wA, int hA, int wB) { for (int h=0; h<hA; h++) { ...
4,229
#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 :...
4,230
#include <stdio.h> #include <stdlib.h> #define N 10 #define THREADS_PER_BLOCK 10 __global__ void gpuSum(int *a, int *b, int *c, int n) { int idx = threadIdx.x + (blockIdx.x * blockDim.x); while (idx < n) { c[idx] = a[idx] + b[idx]; idx += blockDim.x * gridDim.x; } } void fill_matrix(int *arr) { for (...
4,231
#include <stdio.h> /* * Refactor firstParallel so that it can run on the GPU. */ __global__ void firstParallel() { printf("This should be running in parallel.\n"); } int main() { firstParallel<<<1, 5>>>(); cudaDeviceSynchronize(); }
4,232
#include <cuda_runtime.h> #include <stdio.h> __global__ void checkDimension(){ 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.z,blockDim.x,blockDim.y,blockDim.z, gridDim.x,gridDim.y,gridDim.z); ...
4,233
#include <cstdio> #include <cstdlib> #include <iostream> #include <fstream> int* d; int* graph; __constant__ int cuda_bf; __constant__ int cuda_total_vertex; __constant__ int cuda_tempVertex; #define INF 1e9 #define H2D cudaMemcpyHostToDevice #define D2H cudaMemcpyDeviceToHost using namespace std; int init_devi...
4,234
#include <iostream> __global__ void add(int *a, int *b, int *c){ int index = threadIdx.x + blockIdx.x * blockDim.x; //if (index < n) c[index] = a[index] + b[index]; } void random_ints(int *p, int s){ for(int i=0; i < s; i++){ p[i] = rand(); } } #define N (2048*2048) #define THREADS_PER_BLOCK 512 int ma...
4,235
#include <fstream> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <ctype.h> #include <math.h> #include <unistd.h> #include <time.h> #include <assert.h> #include <cuda.h> // number of amino acids...
4,236
#include "includes.h" // Type your code here, or load an example. __global__ void square(int *array, int n) { int tid = blockIdx.x; if (tid < n) array[tid] = array[tid] * array[tid]; }
4,237
#include <stdio.h> #include <cuda.h> const int N = 10; __global__ void square(int * matrix, int * result, int size) { unsigned id = blockIdx.x * blockDim.x + threadIdx.x; unsigned ii = id / size; unsigned jj = id % size; for (unsigned kk = 0; kk < size; ++kk) { result[ii * siz...
4,238
// Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.width + col) //Since this is matrix multiplication, A.width must be equal to B.height and the final matrix has height A.height and width B.width #include <stdio.h> #include <math.h> #include <stdlib.h> typedef struct { int width; ...
4,239
// Copyright (c) 2017 Madhavan Seshadri // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) extern "C" { __global__ void dgemm(double *A, double *B, double *C, int *m, int *n, int *k, double *alpha, double *be...
4,240
#include "includes.h" __global__ void saxpy_float4s_shmem_doublebuffer ( float* y, float* x, float a, clock_t * timer_vals) { volatile __shared__ float sdata_x0_0 [COMPUTE_THREADS_PER_CTA]; volatile __shared__ float sdata_x1_0 [COMPUTE_THREADS_PER_CTA]; volatile __shared__ float sdata_x2_0 [COMPUTE_THREADS_PER_CTA]; vo...
4,241
#include <cstdio> #include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/iterator/constant_iterator.h> #include <vector> #include <thrust/iterator/zip_iterator.h> typedef thrust::tuple<double, double> D2; typedef thrust::device_vector<double>::iterator DIter; typedef thrust::tuple<DIter, DI...
4,242
/* 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,float var_2,float 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 ...
4,243
#include <stdio.h> __global__ void perm(int pad[]) { int t = threadIdx.x; int dxN; if ( t >= 0 ) { dxN = pad[0]; } if ( t < 14 ) { if ( t >= 0 ) { // The following branch is the reason // comment it out to get the correct behavior if (dxN + 1 =...
4,244
#include <cuda.h> __global__ void foo(int *p) { p[threadIdx.x] = threadIdx.x; }
4,245
#include<ctime> #include <cmath> #include<iostream> #include <cstdlib> using namespace std; #define BLOCK_SIZE 1024 __global__ void gpuSum(int *prices,int *sumpricesout,int days,int seconds,int N) { int currentday = blockIdx.x*blockDim.x + threadIdx.x; if(currentday<days) { int start = currentday *...
4,246
#include "includes.h" __global__ void dot(float *a, float *b, float *c) { __shared__ float cache[threadsPerBlock]; int cacheIndex = threadIdx.x; float temp = 0.0; for (int tid = threadIdx.x + blockIdx.x*blockDim.x; tid<N; tid += blockDim.x*gridDim.x) { temp += a[tid]*b[tid]; } cache[cacheIndex] = temp; __syncthreads...
4,247
/* * Université Pierre et Marie Curie * Calcul de transport de neutrons * Version séquentielle */ //nvcc -o exec neutron-par.cu -O3 --generate-code arch =compute_35, code=sm_35 && ./exec //nvcc -o exec neutron-par.cu -O3 --generate-code arch=compute_35,code=sm_35 && ./exec #include <stdlib.h> #include <stdio.h> #...
4,248
#include <stdio.h> #include <cuda_runtime.h> __global__ void print(int *test) { int id = threadIdx.x; printf("%d: %d\n", id, test[id]); __syncthreads(); } int main() { int test_h[20], *test_d; for(int i = 0; i < 20; i++){ test_h[i] = i; } size_t pitch = 0; cudaError_t result = cudaMallocPitch((void**)&te...
4,249
#include <stdio.h> #include <stdlib.h> int main(void) { cudaDeviceProp prop; int whichDevice; cudaGetDevice(&whichDevice); cudaGetDeviceProperties(&prop, whichDevice); if (! prop.deviceOverlap) { printf("Le GPU ne gère pas les recouvrement !\n"); printf("Pas d'accélération possible avec les flux...\n"); ...
4,250
#include "includes.h" // Optimized using shared memory and on chip memory // Compile source: $- nvcc src/TokamakSimulation.cu -o nBody -lglut -lm -lGLU -lGL // Run Executable: $- ./nBody //To stop hit "control c" in the window you launched it from. //Make movies https://gist.github.com/JPEGtheDev/db078e1b066543ce405800...
4,251
//////////////////////////////////////////////////////////// //Ho Thien Luan -> History Tracking! // 1. multi_pat_asm_naive_cpu.cu // 2. // // // //////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <time.h> #define FILEN...
4,252
// Constant memory __constant__ int legendU[2500]; // upper legends, concatenated __constant__ int sizesOfLegendsU[100]; // sizes of each of upper legends __constant__ int shiftsOfLegendsU[100]; // prefix sums of sizes, e.g. where legends begins __constant__ int legendL[2500]; // left legends, concatenated __constant...
4,253
#include <cuda.h> #include <stdio.h> #include <chrono> #include <random> __global__ void calc_kernel(int a, int *dA, int dim) { int t_x = threadIdx.x; int b_x = blockIdx.x; dA[(dim * b_x) + t_x] = a * t_x + b_x; } int random_int() { // randomize the seed, create distribution auto seed = std::chro...
4,254
#include <iostream> #include <math.h> #include <cuda.h> #include <cuda_runtime.h> #include <sys/time.h> #include <cufft.h> #define NX 2048 using namespace std; int main(int argc, char *argv[]) { struct timeval tt1, tt2; int ms; float fms; // create cufft plan cufftHandle plan; ...
4,255
#include <stdio.h> #define N 10000 __global__ void add(int *a, int *b, int *c) //tidak ada operasi di CPU. Ada 10 threads { int tID= threadIdx.x; //tID = selalu 1, namun blockID = menyesuaikan if (tID < N) { c[tID] = a[tID] + b[tID]; //blockID=0, tID=0, menjumlahkan a[0] dan b[0], //blockID=1, tID=0,...
4,256
#include <stdio.h> #include <stdlib.h> #include <string.h> void meanFilterCPU(unsigned char *image, unsigned char *filteredImage, int imgWidth, int imgHeight, short bitsPerPixel, int window) { int bottomBoundaryOfWindow, topBoundaryOfWindow, leftBoundaryOfWindow, rightBoundaryOfWindow; int halfOfWindowSize = ...
4,257
#define N 1024 #include<stdio.h> #include<stdlib.h> #include<iostream> //#include<curand_kernel.h> using namespace std; /* __device__ int getRand(curandState *s, int a, int b){ float rand_int = curand_uniform(s); rand_int = rand_int * (b - a) + a; return rand_int; } */ __global__ void add_array(int *a, int *b, i...
4,258
#include <stdio.h> #include <string.h> #include <math.h> #include <cuda_runtime.h> __device__ char key[] = "$1&1234-1234-123456"; __device__ int f(int n, int byte, int c) { for (int bitIndex = 0; bitIndex <= 7; bitIndex++) { int bit = (byte >> bitIndex) & 1; if (bit + ((n - bit) & ~1) == n) { n = (n -...
4,259
#include "includes.h" __global__ void vecAdd(float * in1, float * in2, float * out, int len) { //@@ Insert code to implement vector addition here int i = blockIdx.x * blockDim.x+ threadIdx.x; if( i<len ) out[i] = in1[i]+in2[i]; }
4,260
#include<iostream> #include<stdio.h> #include<stdlib.h> #include <cuda.h> #include <math.h> #include <thrust/scan.h> #include <thrust/device_ptr.h> int checkResults(float*res, float* cudaRes,int length) { int nDiffs=0; const float smallVal = 0.2f; // Keeping this extra high as we have repetitive addition and sequen...
4,261
#include <stdio.h> void init(int *a, int N) { int i; for (i = 0; i < N; ++i) { a[i] = i; } } __global__ void doubleElements(int *a, int N) { int i; i = blockIdx.x * blockDim.x + threadIdx.x; if (i < N) { a[i] *= 2; } } bool checkElementsAreDoubled(int *a, int N) { int i; for (i = 0; i <...
4,262
//********************************************// // MAC0219/5742 - EP3 // // EP3 - Mandelbrot // // Bruna Bazaluk, Felipe Serras, Ricardo Kojo // //********************************************// //*Arquivo que contem as funções para processamento em gpu.*// #include <i...
4,263
typedef int2 Record; __global__ void mapImpl_kernel(Record *d_R, int delta, int rLen,int *d_output1, int *d_output2) { const int by = blockIdx.y; const int bx = blockIdx.x; const int tx = threadIdx.x; const int ty = threadIdx.y; const int tid=tx+ty*blockDim.x; const int bid=bx+by*gridDim.x; const int numThre...
4,264
#include <cuda.h> #include "cuda_runtime.h" // #include <cutil.h> #include "texture_fetch_functions.h" #include "device_functions.h" #include "device_launch_parameters.h" #include <cuda_profiler_api.h> #include <stdio.h> #include <iostream> #define DATATYPE int #define ARRAYLEN 1000000 inline void __getLastCudaErro...
4,265
__global__ void two_threads(int *A, int *B) { int tid = threadIdx.x; A[tid] += B[tid]; }
4,266
#include <iostream> #include <random> #include <cuda_runtime_api.h> double* InitializeArray(const int length,const int seed) { double* A = (double*)malloc(length * sizeof(double)); std::default_random_engine e; std::uniform_real_distribution<double> dist(0,10); e.seed(seed); ...
4,267
#include <iostream> #include <stdio.h> #include <sys/time.h> #include <string.h> using namespace std; #define IDX2C(i,j,ld) (((i)*(ld))+(j)) __global__ void load(float * mat,int channel_id, int channel_count, float * unroll, int height_stride,int width_stride, int mat_height,int...
4,268
#include <stdio.h> __global__ void kernel(int *d, int n){ __shared__ int s[64]; int tid = threadIdx.x; int tr = n - tid - 1; s[tid] = d[tid]; __syncthreads(); d[tid] = s[tr]; } int main(int argc, char* argv[]){ //initialization code int size; float total_time; cudaEvent_t start,stop; cudaEventCreate(&st...
4,269
#include <iostream> #include <cstdlib> #include <math.h> #include <chrono> // matrix multiply on gpu __global__ void dgem_gpu(int n, float *A, float *B, float *C) { int i = blockIdx.x*blockDim.x + threadIdx.x; int j = blockIdx.y*blockDim.y + threadIdx.y; // demo filler C[i+j*n] = B[i+j*n]; } void square_dgem...
4,270
#include <iostream> #include <chrono> #include <cassert> #include <cmath> #include <cstdlib> #include <vector> #include <algorithm> #define BLOCKSIZE 128 // MUST BE ASSOCIATIVE __device__ inline int f(int a, int b){ return a + b; } /** * Implements an inclusive prefix-scan algorithm ON EACH BLOCK using a recurs...
4,271
__global__ void deriv_entropy(int n_train, int n_classes, float* targets, float* sigma_o, float* d_entropy) { int tx = threadIdx.x; int bx = blockIdx.x; int stride = blockDim.x; int idx; for(idx=bx*n_classes+tx; idx<n_train*n_classes; idx+=stride) { if(idx < n_train*n_classes) d_entropy[idx] = -targets...
4,272
// Only thing we care about is that these headers are found #include <cuda.h> #include <cuda_runtime_api.h> int main(int argc, char** argv) { return 0; }
4,273
#include "includes.h" __device__ void updateU(const int nbrOfGrids, double *d_u1, double *d_u2, double *d_u3, const double *d_u1Temp, const double *d_u2Temp, const double *d_u3Temp) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x; for (int i = index; i < nbrOfGrids; i += stride) { if ((i > ...
4,274
#include <stdio.h> #include <future> #include <thread> #include <chrono> #include <iostream> #define N 1000000 __constant__ int factor = 0; __global__ void vectorAdd(int *a, int *b, int *c) { int i = blockIdx.x*blockDim.x + threadIdx.x; c[i] = factor*(a[i] + b[i]); } __global__ void matrixAdd(int **a,int *...
4,275
#include <stdio.h> #include <stdlib.h> #include <cuda.h> void initialize (int N, float *a, float *b, float *c){ for (int i = 0; i < N; i++){ if (i < N){ c[i] = 0; a[i] = 1 + i; b[i] = 1 - i; } } } void addVectors (int N, float *a, float *b, float *c){ for (int i = 0; i < N; i++){ if (i < N){ c[i]...
4,276
#include <vector> #include <iostream> #include "stdio.h" #include <cufft.h> #define cuda_safe_call(err) __cuda_safe_call(err, __FILE__, __LINE__) inline void __cuda_safe_call(cudaError err, const char *file, const int line) { if (cudaSuccess != err) printf("cudaSafeCall() failed at %s:%i : %s\n", file, lin...
4,277
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <iostream> #include <ctype.h> #include <cuda.h> #define CEIL(a,b) ((a+b-1)/b) #define SWAP(a,b,t) t=b; b=a; a=t; #define DATAMB(bytes) (bytes/1024/1024) #define DA...
4,278
#include <iostream> #include <ctime> #include <cstdlib> using namespace std; #define MTX_DIM 100 #define BLOCK_SIZE 10 __device__ __managed__ float *A, *B, *C; __global__ void calcGravity(const size_t n){ int row = threadIdx.x + blockDim.x * blockIdx.x; int col = blockIdx.x*BLOCK_SIZE + threadIdx.x; if(row<n ...
4,279
#include "includes.h" // Optimized using shared memory and on chip memory // Compile source: $- nvcc src/TokamakSimulation.cu -o nBody -lglut -lm -lGLU -lGL // Run Executable: $- ./nBody //To stop hit "control c" in the window you launched it from. //Make movies https://gist.github.com/JPEGtheDev/db078e1b066543ce405800...
4,280
#include <stdio.h> #include <math.h> #include <time.h> #include <cuda.h> //Code written by Alan Fleming //CONSTANTS #define MATRIXSIZE 131072 #define BLOCKSIZE 1024 //Code to preform sum reduction using the cpu int SumReductionCPU(int* x, int N){ int sum = 0; for(int i = 0; i < N; i++){ sum += x[i]; } return s...
4,281
// Note that in this model we do not check // the error codes and status of kernel call. #include <cstdio> #include <cmath> __global__ void set(int *A, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < N) A[idx] = idx; } int main(void) { const int N = 128; int *A; cudaMall...
4,282
#include <stdio.h> #include <cuda_runtime.h> #define N 64 __global__ void add(int *a, int *b, int *c) { int idx = blockIdx.x; if (idx < N) { c[idx] = a[idx] + b[idx]; } } int main() { int *a, *b, *c; int *dev_a, *dev_b, *dev_c; // Allocate memory space for host a, b, and c a = (int *)mal...
4,283
#include <stdio.h> #define N 24 #define THREADS 8 __global__ void reduce(float *A, float *results) { __shared__ float sdata[THREADS]; int i = blockDim.x*blockIdx.x+threadIdx.x; sdata[threadIdx.x] = A[i]; for(unsigned s = blockDim.x/2;s > 0; s>>=1) { if(threadIdx.x < s && sdata[threadIdx.x] < sda...
4,284
#include"stdio.h" #include<cuda_runtime.h> #include<curand.h> #include<curand_kernel.h> #include <sys/time.h> #define N 1024 // Kernel definition __global__ void random_gpu(double* C,long* time,curandState*state) { long i = threadIdx.x; long seed=(*time)*(i+1);//因为所有给定时间一定,所以我们只能通过对时间进行简单处理 int offset=0;//完全独立的...
4,285
#include "includes.h" __device__ void down_sweep_512(uint* data_block) { for (uint i = 512; i >= 2; i >>= 1) { for (uint j = 0; j < (511 + blockDim.x) / i; ++j) { const auto element = 511 - (j * blockDim.x + threadIdx.x) * i; if (element < 512) { const auto other_element = element - (i >> 1); const auto value = data_bl...
4,286
#include "includes.h" #define N 50 #define NewN 100 #define LifeN 500 #define numofthreads 512 int numofeles=0,capacity; struct chromosome { long long weight=0, value=0; bool chromo[100003]; }; chromosome chromoele[N],*cudaChromo,*cudaNewpopulation,newpopulation[NewN],res,x[2]; int weight[100001],value[100001],*devVa...
4,287
/*************************************************** * Module that adds a new row at the top of the matrix with all ones * Author: Alonso Vidales <alonso.vidales@tras2.es> * * To be compiled with nvcc -ptx matrix_add_bias_top.cu * Debug: nvcc -arch=sm_20 -ptx matrix_add_bias_top.cu * ****************************...
4,288
#include <cuda.h> #include <cuda_runtime.h> #include <iostream> #define size 4 using namespace std; __global__ void add(int *x,int *y,int *z){ const int tid = threadIdx.x + blockIdx.x * blockDim.x; if(tid<size){ z[tid] = x[tid] + y[tid]; } } __global__ void multiplyVectorAndMatrix(in...
4,289
#include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void vecAdd(double * a, double * b, double * c, int n) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < n) c[id] = a[id] + b[id]; } int main(int argc, char * argv[]) { int n = 100, i; double *h_a, *h_b, *h_c; dou...
4,290
#include "includes.h" __global__ void downSanple420_gpu(cudaTextureObject_t ch1, cudaTextureObject_t ch2, int16_t *downCh1, int16_t *downCh2, size_t width, size_t height) { int2 threadCoord = make_int2(blockIdx.x * blockDim.x + threadIdx.x, blockIdx.y * blockDim.y + threadIdx.y); if (threadCoord.x < width && (threadCoo...
4,291
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <math.h> #include <sys/time.h> #include <curand_kernel.h> #include <curand.h> #define SEED 921 #define NUM_ITER 25600000 #define TRIALS_PER_THREAD 100000 double cpuSecond() { struct timeval tp; gettimeofday(&tp, NULL);...
4,292
#include <cuda_runtime.h> #include <iostream> //grid has one blob, blob has 1024 threads // dim3 BlocksperGrid(1); // dim3 ThreadsperBlock(1024); __global__ void OneDimAdd(float *d_A, float *d_B, float *d_C, int numElements) { int i = threadIdx.x; if(i<numElements) { d_C[i] = d_A[i] + d_B[i]; } ...
4,293
#include <stdio.h> #include <inttypes.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #ifndef CONFIG_DEFINED #define CONFIG_DEFINED // Number of real digits per Digit stored. static const int PRECISION = 4; // 10 ^ PRECISION: Used in many calcs. static const int MAGNITUDE = 10000; // Maximum n...
4,294
#include <iostream> #include <sys/times.h> #include <unistd.h> __global__ void calcInterval (double * data, const long cntSteps, const long cntThreads, const double step) { double x; double sum=0.0; int idThread=blockDim.x * blockIdx.x + threadIdx.x;; long cntStepsPerThread = cntSteps / cntThreads; ...
4,295
#include "cuda.h" __global__ void addOneKernel(float* out, const float* in, int numElements) { int stride = blockDim.x * gridDim.x; int tidx = blockDim.x * blockIdx.x + threadIdx.x; for (; tidx < numElements; tidx += stride) { out[tidx] = in[tidx] + 1; } } // Kernel Wrapper void...
4,296
#include "includes.h" __global__ void vecAddKernel(float *A, float *B, float *C, int n){ int i = threadIdx.x+blockDim.x*blockIdx.x; if(i<n) C[i] = A[i]+B[i]; }
4,297
#include "includes.h" __global__ void simple_sinf(float* out, const size_t _data_size, int fnCode, const float _dx, const float _frange_start) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < _data_size) { float x = _frange_start + i * _dx; int idx = 2 * i; out[idx] = x; switch (fnCode) { case 0: out[idx + ...
4,298
#include <stdbool.h> #include <stdio.h> typedef unsigned char uchar; #define N_THREADS 32 #define N_BLOCKS 48 #define TOTAL_IDX (blockIdx.x * blockDim.x + threadIdx.x) #define PLAN_LEN_MAX 255 typedef uchar Direction; #define dir_reverse(dir) ((Direction)(3 - (dir))) #define DIR_N 4 #define DIR_FIRST 0 #define DIR_U...
4,299
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void helloCuda() { printf("Hello Aman and Sharach ..........\n"); } /* int main() { dim3 block(4); // 4 threads per block; dim3 grid(8); // 8x4 = 32 threads; 1 grid = 8 blocks; helloCuda << <grid, block >> > (); } *...
4,300
#include "includes.h" const int Nthreads = 1024, NrankMax = 3, nt0max = 71, NchanMax = 1024; ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////...