serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
20,301
#include <iostream> #include <cassert> __device__ void cube(double* xi) { *xi = (*xi) * (*xi) * (*xi); } __global__ void cube_kernel(double* x, int size) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if (tid < size) { cube(&x[tid]); } } int main(int argc, char* argv[]) { double* x = NULL; int ...
20,302
#include "includes.h" __device__ __forceinline__ size_t gpu_fieldn_index(unsigned int x, unsigned int y, unsigned int z, unsigned int d) { return (NX*(NY*(NZ*(d-1)+z)+y)+x); } __device__ __forceinline__ size_t gpu_scalar_index(unsigned int x, unsigned int y, unsigned int z) { return NX*(NY*z + y)+x; } __device__ __forc...
20,303
#include "Main.cuh" #include "Load.cuh" #include <iostream> #include <fstream> #include <sstream> #include <string> using namespace std; //Load the image void loadImage(int *image_array, int &width, int &height, int &grayscale, string &file) { string line; string dimensions[2]; int i = 0; cout << endl << "Loadin...
20,304
#include "includes.h" __global__ void kernel_push_atomic2( int *g_terminate, int *g_push_reser, int *s_push_reser, int *g_block_num, int width1) { int x = __umul24( blockIdx.x, blockDim.x ) + threadIdx.x ; int y = __umul24( blockIdx.y , blockDim.y ) + threadIdx.y ; int thid = __umul24( y , width1 ) + x ; if( s_push...
20,305
#include <png.h> #include <zlib.h> #include <cassert> #include <cmath> #include <cstdlib> #include <iostream> #define MASK_N 2 #define MASK_X 5 #define MASK_Y 5 #define SCALE 8 // clang-format off __device__ int mask[MASK_N][MASK_X][MASK_Y] = { {{ -1, -4, -6, -4, -1}, { -2, -8,-12, -8, -2}, { 0, 0, ...
20,306
#include <stdlib.h> #include <stdio.h> // Number of elements to put in the test array #define TEST_SIZE 16 #define NUM_BINS 10 //////////////////////////////////////////////////////////////// ////////////////// COPY EVERYTHING BELOW HERE ////////////////// /////////////////////////////////////////////////////////////...
20,307
/* * Copyright 1993-2015 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 related...
20,308
#include <stdio.h> //__device__ float Determinant(float *a,int n,float *temp); __device__ __shared__ float result[3]; __device__ void MatrixDeterminant(void *param) { float *input = (float *) param; int warp_size=32; int n = (int)input[0]; float* matrix = input+1; int thread = threadIdx.x % warp_si...
20,309
// #CSCS CUDA Training // // #Example 3 - transpose matrix // // #Author Ugo Varetto // // #Goal: compute the transpose of a matrix // // #Rationale: shows how to perform operations on a 2D grid and how to // use the GPU for data initializaion // // #Solution: straightworwad, simply compute the thread...
20,310
#if GOOGLE_CUDA #define EIGEN_USE_GPU extern "C" __global__ void default_function_kernel0(const float* __restrict__ Data, const float* __restrict__ K0, const float* __restrict__ K1, const float* __restrict__ K2, float* __restrict__ Output) { float Output_local[8]; __shared__ float pad_temp_shared...
20,311
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <time.h> #include <stdio.h> #include <stdlib.h> #define N 5 #define BLOCK_DIM 10 using namespace std; __global__ void sum_Matrices_Normal (int *a, int *b, int *c) { int columna = blockIdx.x * blockDim.x + threadIdx.x; int ...
20,312
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #include <numeric> #include <math.h> using namespace std; __global__ void max(int* input, int n) { const int tid = threadIdx.x; int step_size = 1; int number_of_threads = blockDim.x; while (number_of_threads > 0) { if (tid <...
20,313
#include "includes.h" #define THREADS 256 #define BLOCKS 32 #define NUM THREADS*BLOCKS int seed_var =1239; __global__ void work_efficient_scan_kernel(int *X, int *Y, int InputSize) { extern __shared__ int XY[]; int i= blockIdx.x*blockDim.x+ threadIdx.x; if (i < InputSize) { XY[threadIdx.x] = X[i]; } for (unsigned in...
20,314
#include <curand_kernel.h> #include <curand.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <iostream> // #define NUM_ITER 10000000000 //#define grid_size 1 // #define BLOCK_SIZE 1 #define MAX_THREADS 2048*12 __global__ void calc_pi(uint64_t *counts, int iterations, int block_size) { extern _...
20,315
///////////////////////// // matrixVecMult.cu // // Andrew Krepps // // Module 6 Assignment // // 3/12/2018 // ///////////////////////// #include <chrono> #include <stdio.h> #include <stdlib.h> #define MAX_SIZE 8192 /////////////////////////////////////////////////////////////////////////////// /...
20,316
#include <stdio.h> __global__ void print() { printf("block = %d, thread = %d\n", blockIdx.x, threadIdx.x); } int main() { print<<<3,3>>>(); cudaDeviceSynchronize(); }
20,317
#include "includes.h" __global__ void multiplyBy2_self(int size, long *inout) { const int ix = threadIdx.x + blockIdx.x * blockDim.x; if (ix < size) { inout[ix] = inout[ix] * 2; } }
20,318
#include <cuda.h> #include <thrust/device_vector.h> #include <thrust/fill.h> #include <thrust/host_vector.h> #include <thrust/sequence.h> #include <thrust/transform.h> #include <iostream> using namespace std; #define N 10 #define V 0.2 #define T 2 #define CUDA_CHECK_RETURN(value) ((cudaError_t)value != cudaSuccess) ...
20,319
struct boundingVolume{ float3 u_f_r; float3 u_f_l; float3 u_b_r; float3 u_b_l; float3 lo_f_r; float3 lo_f_l; float3 lo_b_r; float3 lo_b_l; }; // class CellIDs{ // public: // int *cellIDArray; // int *objectIDArray; // CellIDs(){ // cellIDArray = (int*)malloc(sizeof(int)*8*OBJECT_COUNT); // objectIDArra...
20,320
#include "includes.h" // fill an image with a chekcer_board (BGR) __global__ void replace_image_by_distance_kernel(const unsigned char *pImage, const float* pDepth, const unsigned char *pBackground, unsigned char *result, const float max_value, const unsigned int width, const unsigned int height, const unsigned int i...
20,321
#ifndef __UTEPOCH_CU__ #define __UTEPOCH_CU__ #include <stdio.h> #include "sac.cuh" long long int time2utepoch(int year,int jday,int hour,int min,int sec,int msec,int usec) { long long int kk=1000000; long long int k=1000; long long int utepoch; int a4=year/4-!(year & 3); int a100=a4/25; int a...
20,322
//pass //--blockDim=1024 --gridDim=1 --no-inline #include <cuda.h> #include <stdio.h> #define N 2 //1024 __global__ void definitions (int* A, unsigned int* B, unsigned long long int* C) { atomicMin(A,10); atomicMin(B,1); atomicMin(C,5); }
20,323
#include <fstream> #include <iostream> #include <string> #include <vector> #include <sstream> #include <algorithm> #include <cuda_runtime.h> #include <math.h> #include <device_launch_parameters.h> int* readfile(const char* filename, int* size); /***************************************************** while !stable prop...
20,324
/* Group Members : Jose Garcia Kameron Bush Collatz code for CS 4380 / CS 5351 Copyright (c) 2019 Texas State University. All rights reserved. Redistribution in source or binary form, with or without modification, is *not* permitted. Use in source and binary forms, with or without modification, is only permitted f...
20,325
#include <stdio.h> #include <stdlib.h> #include <math.h> // CUDA kernel. Each thread takes care of one element of c __global__ void matAdd(double *a, double *b, double *c, int n) { // Get our global thread ID int id = blockIdx.x*blockDim.x+threadIdx.x; // Make sure we do not go out of bounds - should be...
20,326
/* ============================================================================ Name : cuda.c Author : Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include<stdio.h> #inc...
20,327
/// @file /// @copyright 2016- The Science and Technology Facilities Council (STFC) /// @author Florent Lopez #include <stdio.h> #include <limits> #include <cuda_runtime.h> #include <cuda_runtime_api.h> // #define BLOCK_SIZE 128 // Number of threads // #define BLOCK_SIZE 16 // Number of threads #define BLOCK_SIZE ...
20,328
float h_A[]= { 0.6268283168399733, 0.5820438295956624, 0.7155419277465724, 0.6529364371559196, 0.9515301876238671, 0.5313043871151091, 0.6366937516486788, 0.5752237649250644, 0.6688301026236152, 0.7924564403991801, 0.7127780398297493, 0.8825410410557307, 0.7795304387612063, 0.5831883604271031, 0.7635014054558178, 0.584...
20,329
#include "includes.h" __global__ void fillZero(int *c_red, int size) { int id = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; for (int i = id; i < size; i+=stride) { c_red[i] = 0; } }
20,330
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <math.h> using namespace std; // Blocksize #define BLOCKSIZE 1024 //************************************************* // GLOBAL MEMORY VERSION OF THE ALGORITHM // ************************************************ __global__ void vectorNS(float *in, f...
20,331
// System includes #include <stdio.h> #include <assert.h> // CUDA runtime #include <cuda_runtime.h> // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.width + col) typedef struct { int width; int height; int stride; double* elements; } Matrix; // Thread block size #de...
20,332
#include <cuda.h> #include <cuComplex.h> #include <math_constants.h> // Use symmetry // Use max_half_support threads only // Perhaps it's not very cache friendly, but it is // very simple to perform work-distribution for this variant #define __SET_MAP \ const int ...
20,333
#include "includes.h" __global__ void calcSoftmaxDivForwardGPU(float *out, float *sum, int batch_size, int in_size_x, unsigned int n) { // int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; unsigned int index = threadIdx.x + blockIdx.x * blockDim.x; if(index<n && *(sum + blockIdx.x)>0.0){ // out[i...
20,334
//CUDA code for matrix multiplicationn . The values of a,b,c,q have to changed according to N #include<stdlib.h> #include<stdio.h> #include<iostream> #include<cuda_runtime.h> __global__ void Product (float *a, float *b, float *c) { // Out of all the threads created each one computes 1 value of C and stores into cval f...
20,335
#include <stdio.h> #include <stdlib.h> #include <thrust/sort.h> #define num_thread 64 #define thread 16 __global__ void count(int *data,int input, int *result) { int i = blockIdx.x * blockDim.x + threadIdx.x; if(data[i] == input) { int a = 1; atomicAdd(result,a); } } int main(int arg...
20,336
#include "includes.h" __global__ void LowPassColMulti(float *d_Result, float *d_Data, int width, int pitch, int height) { __shared__ float data[CONVCOL_W*(CONVCOL_H + 2*RADIUS)]; const int tx = threadIdx.x; const int ty = threadIdx.y; const int block = blockIdx.x/(NUM_SCALES+3); const int scale = blockIdx.x - (NUM_SCAL...
20,337
#include <stdio.h> #include <stdlib.h> #include <time.h> void printArr( int arr[], int n ) { int i; for ( i = 0; i < n; ++i ) printf( "%d ", arr[i] ); } __device__ int d_size; __global__ void partition (int *arr, int *arr_l, int *arr_h, int n) { int z = blockIdx.x*blockDim.x+threadIdx.x; d_siz...
20,338
#include <stdio.h> #include <string.h> #include <stdbool.h> #include <cuda.h> #include <cuda_runtime_api.h> #define V 9 #define E 14 long int* get_graph_dim(char* filename) { FILE* file; file = fopen(filename, "r"); if (file == NULL) { printf("Unable to read the CSR file: %s.", filename); exit(1); ...
20,339
/* 159.735 Semester 2, 2016. Ian Bond, 3/10/2016 Sequential version of the N-sphere counting problem for Assignment 5. Two alternative algorithms are presented. Note: a rethink will be needed when implementing a GPU version of this. You can't just cut and paste code. To compile: g++ -O3 -o nsphere nsphere.cpp (y...
20,340
#include <iostream> #include <stdlib.h> #include <math.h> #include <stdio.h> #define PI 3.141592654 using namespace std; const int nOrder = 3; const int nTimePreSnap = 100; typedef struct { int nx, nz; int Nx, Nz; int sx, sz; int npx, npz; float dx, dz; } dim; typedef struct { float *vp, *vs, *rho; } med...
20,341
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/random/linear_congruential_engine.h> #include <thrust/random/uniform_real_distribution.h> #include <iostream> // nvcc -std=c++14 -O3 tarefa6_multSeed.cu -o t6 && ./t6 struct raw_access { int SEED; __device__ __host__ double ...
20,342
#include <iostream> #include <math.h> #include <time.h> #include <stdlib.h> #include <random> #include <vector> #include <chrono> #define TILE_DIM 32 __global__ void multiplyNaive(const int *mat_1, const int *mat_2, int *mat_prod, const int n, const int m, const int p) { int x = blockIdx.x * blockDim.x + threadId...
20,343
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <time.h> #define N 10000 __global__ void add(int *d_a, int *d_b, int *d_c){ d_c[blockIdx.x] = d_a[blockIdx.x] + d_b[blockIdx.x]; } int main(){ int *a, *b, *c, *gold_c; int *d_a, *d_b, *d_c; int i; int pass = 1; a = (...
20,344
#include <cuda_runtime_api.h> #include <iostream> //////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// using namespace std; int main( int argc, char** argv) { int deviceCount = 0; cu...
20,345
#include "includes.h" __global__ void vecAddKernel(float* A, float* B, float* C, int n) { // Calculate global thread index based on the block and thread indices ---- //INSERT KERNEL CODE HERE int i = blockDim.x*blockIdx.x+threadIdx.x; // Use global index to determine which elements to read, add, and write --- //INS...
20,346
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <algorithm> #include <map> #include <iostream>
20,347
#include <iostream> using namespace std; #include <thrust/reduce.h> #include <thrust/sequence.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> int main() { const int N = 50000; thrust::device_vector<int> a(N); thrust::sequence(a.begin(), a.end(), 0); int sumA = thrust::reduce(a.begin(), a....
20,348
#include "includes.h" __global__ void sReduceSingle(int *idata,int *single,unsigned int ncols) { int i; unsigned int tid = threadIdx.x; extern __shared__ int sdata[]; unsigned int startPos = blockDim.x + threadIdx.x; int colsPerThread = ncols/blockDim.x; int myPart = 0; for(i=0;i<colsPerThread;i++) { myPart+=idata[star...
20,349
/* 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,int var_3,int var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float var_...
20,350
__global__ void dijkstra(int* V, int* E, int* W, int* n, int* vis, int* dist, int* predist){ const int u0 = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; const int offset = blockDim.x * blockDim.y * blockDim.z; __shared__ int quickBreak[1]; int u = -1; for(int i = 0;...
20,351
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <time.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...
20,352
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <device_functions.h> #include <device_launch_parameters.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <cuda.h> CUcontext hContext = 0; #define CUDA_CHECK( fn ) do { \ CUresult status = (fn); \ if ( CUDA_SUCCESS...
20,353
#include <cuda.h> #include <stdio.h> #include <iostream> #include <string> #include <cstdio> #include <cstdlib> __global__ void calc(int *dA){ int index = blockIdx.x * blockDim.x + threadIdx.x; dA[index] = blockIdx.x + threadIdx.x; } int main(void) { using namespace std; int *dA; int size = size...
20,354
#define _POSIX_C_SOURCE 200809L #include <stdio.h> #include <cuda.h> #include <string> #include <iostream> #include <fstream> #include "f_eval.cuh" using namespace std; __inline__ __host__ __device__ double f_eval(double* p_x, int m); double* readFile(string input, int *m, int *n); void writeFile(string output, doubl...
20,355
#include <stdlib.h> #include <stdio.h> #include <cuda.h> // allocate memory on gpu extern "C++" void cu_safe_falloc(float **g_f, size_t n_elem) { void *gptr; cudaError_t crc = cudaMalloc(&gptr, n_elem*sizeof(float)); if(crc) { printf("cudaMalloc Error=%d:%s\n", crc, cudaGetErrorString(crc)); ...
20,356
#include <stdio.h> #include <ctime> #define CUDA_KERNEL_LOOP(i, n) \ for (int i = blockIdx.x * blockDim.x + threadIdx.x; \ i < (n); \ i += blockDim.x * gridDim.x) __global__ void distance(float *xSquare, float *ySquare, int *result, int testNum) { // int tid = threadIdx.x; // int bid = blockIdx.x; // int...
20,357
#include "includes.h" #ifndef __CUDACC__ #define __CUDACC__ #endif // generate a random square matrix __global__ void matMulKernel4(float* P, float* M, float* N, int width) { __shared__ float Mds4[4][4]; __shared__ float Nds4[4][4]; int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x; int ty = threadIdx.y;...
20,358
#include <thrust/tuple.h> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/transform.h> #include <thrust/fill.h> #include <thrust/iterator/zip_iterator.h> #include <cstdio> #define N 32 struct rotate_tuple { __host__ __device__ thrust::tuple<float, float, float> operator()(thrust::t...
20,359
// CUDA programming // Exercise n. 02 #include <errno.h> #include <cuda.h> #include <stdio.h> #define BLOCKS 1 #define THREADS 1 // Prototype __global__ void add(int *a, int *b, int *c); int main(void) { int a, b, c; // host copies of a, b, c int *d_a, *d_b, *d_c; // device copies of a, b, c ...
20,360
#include <string.h> #include <stdlib.h> #include <math.h> #include <stdint.h> #include <stdio.h> #include <unistd.h> // ********************************************** // For floats vector on device // ********************************************** typedef struct { float x; float y; float z; } Vec; __device__ V...
20,361
#include <iostream> #include <cstdio> #include <cstring> #include <thrust/device_vector.h> // --------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------- Kernels ---------------------------------------...
20,362
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda.h> #include <cuda_runtime.h> #include <cuda.h> #include <device_launch_parameters.h> #define LIST_SIZE 100000 extern "C" __device__ unsigned long long zeroList[LIST_SIZE]; extern "C" __device__ unsigned long long oneList[LIST_...
20,363
#include <iostream> #include <string> #include <cassert> #include <ctime> using namespace std; struct cuda_exception { explicit cuda_exception(const char *err) : error_info(err) {} explicit cuda_exception(const string &err) : error_info(err) {} string what() const throw() { return error_info; } priva...
20,364
#include <stdio.h> #include <cuda_runtime_api.h> #include <time.h> /**************************************************************************** * An experiment with cuda kernel invocation parameters. 2x3x4 threads on * one block should yield 24 kernel invocations. * * Compile with: * nvcc -o cupass cupass.cu...
20,365
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/iterator/counting_iterator.h> #include <iostream> #if 0 typedef thrust::tuple<float,float,float> Float3; struct DotProduct : public thrust::binary_function<Float3,Float3,float> { const float params[4]; __host__ __device__ ...
20,366
/* * Face Factor Distance * (MP3, Fall 2019, GPU Programming/Yifan Liu) */ #include <assert.h> #include <cuda.h> #include <stdio.h> #include <math.h> #include <iostream> #include <fstream> #include <ctime> #include <string> #include <sstream> /* Usage message displayed when invali...
20,367
#include "includes.h" #define B 2 /* */ __global__ void cudaAcc_GetPowerSpectrum_kernel2( int NumDataPoints, float2* FreqData, float* PowerSpectrum) { const int i = blockIdx.x * blockDim.x*B + threadIdx.x; float ax[B]; float ay[B]; #pragma unroll for (int k=0;k<B;k++) { ax[k] = FreqData[i+k*blockDim.x].x; ay[k] = ...
20,368
#include "assignmentHPC1.cuh" #include <iostream> #include <cstdlib> #include <chrono> #include <limits> using namespace std; using namespace std::chrono; double find_max_cpu(double *arr_host, unsigned int N) { double result = numeric_limits<double>::min(); for(unsigned int i = 0; i < N; i++) { i...
20,369
#include <math.h> #include <stdio.h> #include <stdlib.h> /* * Wei Wu * CAAM 520 */ // TO compile: // nvcc -o hw04 hw04.c -lm // TO run with tolerance 1e-4 and 4x4 loop currents // ./hw04 4 1e-4 #define PI 3.14159265359 #define MAX(a,b) (((a)>(b))?(a):(b)) #define p_Nthreads 32 #define SERIAL false // kernel...
20,370
#include <cuda.h> #include <cuda_runtime.h> #include <iostream> #include <vector> #define N 10 __global__ void add(float *a, float *b, float *c) { c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x]; } void cuda_check(cudaError_t status) { if (status != cudaSuccess) { std::cout << "Error could not allocate memory ...
20,371
#include "includes.h" __global__ void convertKinectDisparityToRegularDisparity_kernel( float *d_regularDisparity, int d_regularDisparityPitch, const float *d_KinectDisparity, int d_KinectDisparityPitch, int width, int height) { const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y +...
20,372
#include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #include <ctime> #include <iostream> #define DATA_SIZE 1048576 #define THREAD_SIZE 256 #define BLOCK_SIZE 32 int data[DATA_SIZE]; void Generate(int* number, int size) { for (int i = 0; i < size; ++i) number[i] = rand() % 10; } __global__ static void ...
20,373
#include "includes.h" /* WRITE CUDA KERNEL FOR TRANSPOSE HERE */ const int CHUNK_SIZE = 32; const int CHUNK_ROWS = 8; __global__ void matrix_t(int* data, int* out, int* rows, int* cols){ __shared__ int chunk[CHUNK_SIZE][CHUNK_SIZE]; int x = blockIdx.x * CHUNK_SIZE + threadIdx.x; int y = blockIdx.y * CHUNK_SIZE + th...
20,374
#include <cuda.h> #include <cuda_runtime.h> #include <iostream> #include <vector> extern "C" __global__ void switch_test(long *src_ptr, long *dst_ptr, int num_rows, int* output_rows) { int idx; long val; int pos_start = blockIdx.x * blockDim.x + threadIdx.x; if(pos_start >= num_rows) return; val = ...
20,375
#include <iostream> using namespace std; int main() { cudaEvent_t start, stop, done_offload; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventCreate(&done_offload); void *p, *q; long size = 1024l * 1024 * 200; cudaMalloc(&p, size); cudaMallocHost(&q, size); cout << "without split by event\n...
20,376
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __device__ const char *STR = "HELLO WORLD!"; const char STR_LENGTH = 12; __global__ void hello() { printf("%c\n", STR[threadIdx.x]); } int main(void) { int num_threads = STR_LENGTH; int num_blocks = 1; hello <<< num_blocks, num_...
20,377
#include <stdio.h> #include <stdlib.h> #include <curand.h> #include <curand_kernel.h> #define MAX 100 /* this GPU kernel function calculates a random number and stores it in the parameter */ __global__ void random(float* result1, float* result2) { /* CUDA's random number library uses curandState_t to keep track o...
20,378
#include <stdio.h> #include <time.h> #include <sys/time.h> // GPU: Impressão dos índices __global__ void fIndice() { printf ("%d\t%d\t%d\n", threadIdx.x, blockIdx.x, blockDim.x); } // CPU: Função principal int main (int argc, char ** argv) { int nblocos = 0; int nthreads = 0; // Tratamento...
20,379
#include "includes.h" __global__ void refine_dilateFPPlaneDepthMapXpYp_kernel(float* fpPlaneDepthMap, int fpPlaneDepthMap_p, float* maskMap, int maskMap_p, int width, int height, int xp, int yp, float fpPlaneDepth) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if((x + ...
20,380
#include <cuda_runtime.h> #include <device_launch_parameters.h> __global__ void square(float* d_out, float* d_in) { int idx = threadIdx.x; float f = d_in[idx]; d_out[idx] = f * f; } void your_square(int array_size, float* d_out, float* d_in) { square<<<1, array_size >>> (d_out, d_in); }
20,381
#include "includes.h" __global__ void kernel_End( int *g_stochastic, int *g_count_blocks, int *g_counter) { int thid = blockIdx.x * blockDim.x + threadIdx.x ; if( thid < ( *g_counter ) ) { if( g_stochastic[thid] == 1 ) atomicAdd(g_count_blocks,1); //(*g_count_blocks) = (*g_count_blocks) + 1 ; } }
20,382
#include "includes.h" __global__ void conductance_move_spikes_towards_synapses_kernel( int* d_spikes_travelling_to_synapse, float current_time_in_seconds, int* circular_spikenum_buffer, int* spikeid_buffer, int bufferloc, int buffersize, int total_number_of_synapses, float* d_time_of_last_spike_to_reach_synapse, int* p...
20,383
#include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include <math.h> #include <cuda.h> #define PI (3.14159265358979323) #define BLOCK_DIM (32) #define vidx(rr, r, R) (((rr) + (r) < 0) ? 0 : (((rr) + (r) >= (R)) ? (R) - 1 : (rr) +...
20,384
/****************************************************************** File : lcsExclusiveScanForInt.cu Author : Mingcheng Chen Last Update : January 29th, 2013 *******************************************************************/ #include <stdio.h> #define BLOCK_SIZE 512 #define NUM_BANKS 32 #define LOG_NUM_BAN...
20,385
#include "includes.h" __global__ void mergeGPU1d( unsigned char *image1, unsigned char *image2, unsigned char *res, int pixels ) { int i = threadIdx.x + blockIdx.x*blockDim.x; if( i < pixels ) { int idx = 3*i; int r1 = image1[ idx+2 ]; int g1 = image1[ idx+1 ]; int b1 = image1[ idx ]; int r2 = image2[ idx+2 ]; int...
20,386
#include "includes.h" /*-----This is a vector addition--*/ /*---- @ Cuda/c ------*/ /*---- __NS__Bologna__2020__*/ __global__ void vectorAdd(int* a, int* b, int* c, int n){ // calculate index thread int tid = blockIdx.x * blockDim.x + threadIdx.x; // Make sure we stay in-bounds if(tid < n) // Vector add c[tid] = a[...
20,387
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <cstring> #include <time.h> __global__ void memtransf(int * arr) { int gid = blockIdx.x * blockDim.x + threadIdx.x; printf("tid : %d, gid : %d, value : %d\n", threadIdx.x, gid, arr[gid]); } int main...
20,388
template<typename T, typename U> __global__ void addCUDA(T *a, U *b, T *c){ *c = *a + *b; } template<typename T, typename U> __global__ void subCUDA(T *a, U *b, T *c){ *c = *a - *b; } template<typename T, typename U> __global__ void mulCUDA(T *a, U *b, T *c){ *c = *a * *b; } template<typename T, typename U> __glo...
20,389
__global__ void otp(int *v, int *k) { v[threadIdx.x] = v[threadIdx.x] ^ (*k); }
20,390
#include <math.h> #include <stdlib.h> #include <stdio.h> #include "unistd.h" #include "time.h" #include "string.h" // Stores output value computed in inner loop for each thread __shared__ float localvalue[4008]; // Stores temporary shift values __constant__ float dm_shifts[1024]; // -------------------------- The De...
20,391
#include "includes.h" __global__ void matrixAdd_A_Kernel(float* A, float* B, float* C, size_t pitch, int width){ //compute indexes int row = blockIdx.x * blockDim.x + threadIdx.x; int col = blockIdx.y * blockDim.y + threadIdx.y; int rowWidthWithPad = pitch/sizeof(float); if(row < width && col < width) C[row * rowWi...
20,392
#include <stdio.h> #include <stdlib.h> #include "cs_whm_encode.h" __global__ void d_do_a_pair_32_2_32( int *a, int size, int offset ) { int tid = blockIdx.x*blockDim.x + threadIdx.x; int f, ff ; if ( tid < ( size >> 1 )) { f = ( tid / offset ) * ( offset << 1 ) ; tid = f + tid % offset ; f = a[ tid ] ; ...
20,393
/* * Please write your name and net ID below * * Last name: Boran * First name: Tudor * Net ID: N13059231 * * I have attached a readme, you can also compile with make (which I used to get this in nsight, because I love IDEs) */ /* * This file contains the code for doing the heat distribution problem. *...
20,394
#include<iostream> #include <cuda.h> __global__ void matmul_kernel(const float* A, const float* B, float* C, unsigned int n) { extern __shared__ float sm[]; float *sA = &sm[0]; float *sB = &sA[blockDim.x*blockDim.x]; int r = blockIdx.y*blockDim.x+ threadIdx.y; int c = blockIdx.x*blockDi...
20,395
#include <stdio.h> #include <cstdlib> #include <iostream> #include <vector> #define BS 32 #define NUM_BLOCKS 1500 #define NUM_THREADS_PER_BLOCK 1500 #define SIZE NUM_BLOCKS*NUM_THREADS_PER_BLOCK using namespace std; cudaEvent_t start, stop; // These are specific to measure the execution of only the kernel execution...
20,396
#include <stdio.h> #include <stdlib.h> #include <cstdlib> #include <math.h> #define MATRIX_WIDTH 2025 #define MATRIX_HEIGHT 2025 #define MATRIX_SIZE MATRIX_WIDTH*MATRIX_HEIGHT #define TILE_WIDTH 45 #define TILE_HEIGHT 45 #define INIT_THREADS_PER_BLOCK 256 #define INIT_ELEMENTS_PER_THREAD 90 #define...
20,397
/* Troca os valores de posição em um vetor (inverte os valores no vetor). Exemplo da necessidade da sincronização de threads de um bloco. Exemplo para alocação dinâmica e estática de shared mem Quando a função __syncthreads() no kernel está comentada, o resultado fica errado. Os if's nos for's das saídas dos resultad...
20,398
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <iostream> #include <bitset> __global__ void block_reduction (int *a, int len) { __shared__ int smem[256]; assert(blockDim.x <= 256); smem[threadIdx.x] = threadIdx.x; __syncthreads(); for (int i = blockDim.x/2; i > 0; i = i/2) ...
20,399
#include "includes.h" __global__ void setDiffVolumeKernel(float *d_fv, unsigned char *d_picture1, unsigned char *d_picture2, unsigned picWidth, unsigned picHeight) { __shared__ float p1_section[10 * 10 * 4]; __shared__ float p2_section[10 * 10 * 4]; unsigned i; // This thread's position in its block's subsection of th...
20,400
#include <iostream> #include <cuda_runtime_api.h> #include <stdlib.h> using namespace std; #define LEN 100000000 __global__ void add_vec(int *v1, int *v2, int *res, size_t l) { // cudaError_t status; int i = blockIdx.x * blockDim.x + threadIdx.x; int step = gridDim.x * blockDim.x; for (; i < l; i+=...