serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
5,001
#include "includes.h" __global__ void cuda_dot(int N, double *a, double *b, double *c) { // __shared__ double localDot[threadsPerBlock]; /* Statically defined */ extern __shared__ double localDot[]; int ix = threadIdx.x + blockIdx.x * blockDim.x; int localIndex = threadIdx.x; double localSum = 0; while (ix < N) { loc...
5,002
__global__ void add2( double * v1, const double * v2 ) { int idx = threadIdx.x; v1[idx] += v2[idx]; }
5,003
#include<cuda_runtime.h> #include<device_launch_parameters.h> #include<stdio.h> #include<stdlib.h> #include<string.h> __global__ void add(char * d_resbuffer , char * d_buffer, int * d_length) { int id = threadIdx.x ; int start = id * (*d_length); for(int i = 0 ; i<=(*d_length)-1;i++) { d_resbuffer[start] = d_...
5,004
#include <cuda_runtime.h> #include <iostream> class CUDAdem { public: __device__ void add(int igdx) { printf("hello GPU = %d\n",igdx); } }; __global__ void add() { int igdx = threadIdx.x; CUDAdem cdmo; cdmo.add(igdx); } int main() { add<<<1,4>>>(); cudaDeviceReset(); printf("hello world!\n"); return 0; }
5,005
#include <iostream> #include <string> #include <stdio.h> #include <cuda.h> #include <fstream> using namespace std; __global__ void MatrixMulKernel(float *d_M, float *d_N, float *d_P,int width){ int Row = blockIdx.y*blockDim.y + threadIdx.y; int Col = blockIdx.x*blockDim.x + threadIdx.x; if ((Row < width)&&(Col <...
5,006
#include <stdio.h> __device__ void decipher(unsigned int, unsigned int*, unsigned int const*); __global__ void decrypt_bytes(unsigned int *decrypted, unsigned int *encrypted, unsigned char *key) { //Get thread const int tx = threadIdx.x + (blockIdx.x * blockDim.x); unsigned int deciphered[2]; de...
5,007
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <assert.h> #define BLOCK_SIZE 256 #define STR_SIZE 256 #define DEVICE 0 #define HALO 1 // halo width along one direction when advancing to the next iteration #define BENCH_PRINT void run(int argc, char** argv); int rows, cols; int* data; int** wall; ...
5,008
#include "includes.h" __global__ void Sum(float * A, float *B, float *C, int size) { int id = blockDim.x*blockIdx.y*gridDim.x + blockDim.x*blockIdx.x + threadIdx.x; if (id < size) { C[id] = A[id] + B[id]; } }
5,009
__global__ void thinEdgesGPU(int *mag, int *dir, int width, int height){ int y = blockIdx.y*blockDim.y + threadIdx.y + 1; int x = blockIdx.x*blockDim.x + threadIdx.x + 1; // Check whether thread is within image boundary if (x > width-2 || y > height-2) return; // Get gradient direction for current thre...
5,010
// System includes #include <stdio.h> #include <assert.h> #include <iostream> #include <numeric> #include <stdlib.h> // CUDA runtime #include <cuda.h> #include <cuda_runtime.h> #define CUDA_ERROR_CHECK #define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) #define CudaCheckError() __cudaCheckError...
5,011
#include "includes.h" __global__ void reduceUnrollWarps8 (int *g_idata, int *g_odata, unsigned int n) { // set thread ID unsigned int tid = threadIdx.x; unsigned int idx = blockIdx.x * blockDim.x * 8 + threadIdx.x; // convert global data pointer to the local pointer of this block int *idata = g_idata + blockIdx.x * bl...
5,012
//////////////////////////////////////////////////////////////////////////// // // 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 u...
5,013
//#include<iostream> //#include<cstring> //#include<algorithm> //#include<string> //#include<cassert> //#include<iomanip> //using namespace std; // //#define MAX 100 //#define for(i,a,b) for(i=a;i<b; i++) // //string gram[MAX][MAX]; //to store entered grammar //string dpr[MAX]; //int p, np; //np-> number of pr...
5,014
#include "model.cuh" float Model::train_batch(std::vector<Matrix>::iterator X_i, std::vector<Matrix>::iterator Y_i, const unsigned int batch_size, const float lr, const float momentum) { float loss = 0.0f; for (unsigned int i = 0; i < batch_size; i++) { // create the inputs Matrix tmp = *X_i; // feedforward ...
5,015
/****************************************************************************80 Array element addition using CUDA on GPUs Note: changes from the C++ / CPU-only file marked intentionally w/ "CUDA" supposed to be *annoyingly* commented for (self-)educational purposes "host" is assumed to be ...
5,016
#include<iostream> #include<cstdlib> #include<cmath> #include<time.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #define N 10000000 #define MAX_ERR 1e-6 using namespace std; __global__ void vector_add(float *out, float *a, float *b, int n) { int i = threadIdx.x + blockIdx.x * blockDim.x; ...
5,017
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<cuda.h> #define INPUT_SIZE 100000000 #define PRIME_RANGE 1000000 #define BLOCK_SIZE 32 typedef unsigned long long int uint64_c; void initializeInput(char* , int ); int generate_seed_primes(char*, int*, uint64_c); void copy_seed_primes(ui...
5,018
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <thrust/scan.h> #include <thrust/device_vector.h> #include <stdio.h> __global__ void voxelOccupancy(int* occupancy, int granularity) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; int...
5,019
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #include <cuda_runtime.h> #define BLOCKSIZE 256 __global__ void MatrixAddI(int *matrix1, int *matrix2, int *matrix3, int m, int n) { int x = blockIdx.x * blockDim.x + threadIdx.x; if (x < m*n) { matrix3[x] = matrix1[x] + matrix2[x];...
5,020
#include <stdio.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" __global__ void print_threadIds_blockIds_gridDim() { printf("threadIdx.x: %d, threadIdx.y: %d, threadIdx.z: %d,\ blockIdx.x: %d, blockIdx.y: %d, blockIdx.z: %d,\ gridDim.x: %d, gridDim.y: %d, gridDim.z: %d \n", threadId...
5,021
#include <cuda.h> #include <cuda_runtime_api.h> #include <device_launch_parameters.h> #include <iostream> __global__ void RankSortKernel(float* DataIn, float* DataOut, int* rank, int size) { // Retrieve our coordinates in the block int tx = (blockIdx.x * 512) + threadIdx.x; rank[tx] = 0; if(tx < size) { for(int...
5,022
#include "CNextStateLookupTable.cuh" #include "CStateLookupTable.cuh" CNextStateLookupTable::CNextStateLookupTable(unsigned int const p_cnK) : CStateLookupTable(p_cnK #ifdef _USE_CUDA_ , LookupTableType_Next // Set table type #endif ) { } CNextStateLookupTable::~CNextStateLookupTable(void) { } unsigned ...
5,023
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void convolution_1D(float *N , float *M , float *P , int Mask_width,int width) { int i = blockIdx.x*blockDim.x + threadIdx.x; float pvalue = 0.0; int N_start_point = i - ((Mask_width)/...
5,024
#include <iostream> #include <fstream> #include <stdlib.h> #include <cstring> #include <limits> // radi definiranja beskonačnosti #include <ctime> // radi mjerenja vremena izvršavanja #include <cmath> // radi "strop" funkcije using namespace std; /* Definiramo beskonačnost kao najveći mogući integer broj. */ #defin...
5,025
// compile with -std=c++11 -O3 -lcurand #include <iostream> #include <cstdio> #include <curand.h> using std::cout; using std::endl; #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { ...
5,026
#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 tarefa2.cu -o t2 && ./t2 struct fillRand { thrust::uniform_real_distribution<double> dist; thr...
5,027
#include <iostream> #include <string.h> #include <stdio.h> #include <math.h> using namespace std; namespace myNamespace_00_01{ static double* hmem_i; static double* hmem_o; static double* dmem_i; static double* dmem_o; static cudaStream_t stream; static int nb = 1; //1024*1024*64*2; // max 1024*1024*64*2 s...
5,028
#include "includes.h" using namespace std; //Check for edges valid to be part of augmented path //Update frontier __global__ void k2(const int N, bool* visited, int* frontier, bool* new_frontier) { int count = 0; for(int i=0;i<N;i++) { if(new_frontier[i]) { new_frontier[i] = false; frontier[++count] = i; visited[i]...
5,029
#include "csv_data.cuh" CSV_Data::CSV_Data(string fileName, bool printInfo) { (this->resultFile).open(fileName, ios::out); (this->resultFile) << "Target,#Threads,#ThreadBlks,ExecTime\n"; this->printInfo = printInfo; } CSV_Data::~CSV_Data() { resultFile.close(); } void CSV_Data::AddData(string Targe...
5,030
#include <stdio.h> #include <iostream> #include <vector> #define CUDA_CHECK(condition) \ /* Code block avoids redefinition of cudaError_t error */ \ do { \ cudaError_t error = condition; \ if (error != cudaSuccess) { \ std::cout << cudaGetErrorString(error) << std::endl; \ } \ } while (0) #de...
5,031
#include <stdio.h> #include "time.h" #include <stdlib.h> #include <limits.h> /* The old-fashioned CPU-only way to add two vectors */ void add_vectors_host(int *result, int *a, int *b, int n) { for (int i=0; i<n; i++) result[i] = a[i] + b[i]; } /* The kernel that will execute on the GPU */ __global__ vo...
5,032
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #define PI 3.1415 void gauss (int sigma, int gauss_matrix[][5]); void gpuComputing(int gauss_matrix[][5], int** image_matrix, int** final_matrix, int height, int width); __global__ void kernel(int* image, int* final, int* gauss, int pitch, in...
5,033
extern "C" __global__ void kernelFunction(int *input) { input[threadIdx.x] = 32 - threadIdx.x; }
5,034
#include "lsystem.cuh"
5,035
#include "includes.h" #define ITER 10000000000 // Number of bins #define NUMBLOCKS 13 // Number of thread blocks #define NUMTHREADS 192 // Number of threads per block int tid; float pi; // Kernel // Main __global__ void pic(float *sum, int nbin, float step, int nthreads, int nblocks) { int i; float x; int idx ...
5,036
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <assert.h> #include <sys/time.h> #define THREADS 512 #ifdef __cplusplus extern "C" { #endif int cuda_sort(int number_of_elements, float *a) { return 0; } #ifdef __cplusplus } #endif
5,037
// // Created by kindr on 2021/5/8. // #include "multiKernelConcurrent.cuh" #include "../../common/utils.cuh" #include <cstdio> const int N = 1 << 25; __global__ void math_kernel1(int n) { double sum = 0; for (int i = 0; i < n; i++) sum += tan(0.1) * tan(0.1); printf("sum=%g\n", sum); } __global__ void ...
5,038
/* CUDA finite difference wave equation solver, written by * Jeff Amelang, 2012 * * Modified by Kevin Yuh, 2013-14 */ #include <cstdio> #include <cuda_runtime.h> #include "Cuda1DFDWave_cuda.cuh" /* kernel to calculate new displacements */ __global__ void GenerateDisplacements(float* dev_Data, int oldStart, ...
5,039
// CUDA kernel in C extern "C" __global__ void sincos_kernel(int nx, int ny, int nz, float* x, float* y, float* xy) { int i = threadIdx.x + blockIdx.x * blockDim.x; int j = threadIdx.y + blockIdx.y * blockDim.y; int k = threadIdx.z + blockIdx.z * blockDim.z; if ((i >= nx) || (j >= ny) || (k >= nz)) return; int ...
5,040
#ifndef uint32_t #define uint32_t unsigned int #endif #define H0 0x6a09e667 #define H1 0xbb67ae85 #define H2 0x3c6ef372 #define H3 0xa54ff53a #define H4 0x510e527f #define H5 0x9b05688c #define H6 0x1f83d9ab #define H7 0x5be0cd19 __device__ uint rotr(uint x, int n) { if (n < 32) return (x >> n) | (x << (32 - n)); ...
5,041
extern "C" { __device__ int KerSobel(int a1, int a2, int a3, int a4, int a5, int a6) { return(a1 + 2 * a2 + a3 - (a4 + 2 * a5 + a6)); } __global__ void laplacian_filter(unsigned int *lpSrc,unsigned int *lpDst, int width, int height,int* gc_weight, int amplitude) { int x = blockIdx.x * blockDim.x + threadId...
5,042
#include "includes.h" __global__ void forwardDifference2DKernel(const int cols, const int rows, const float* data, float* dx, float* dy) { for (auto idy = blockIdx.y * blockDim.y + threadIdx.y + 1; idy < cols - 1; idy += blockDim.y * gridDim.y) { for (auto idx = blockIdx.x * blockDim.x + threadIdx.x + 1; idx < rows - 1...
5,043
#include "cuda_runtime.h" #include "device_launch_parameters.h" #define _USE_MATH_DEFINES #include <math.h> __global__ void kernel(unsigned char* src) { __shared__ float temp[16][16]; int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; int offset = x + y * bl...
5,044
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> /* struct CDP { char name[256]; size_t totalGlobalMem; size_t sharedMemPerBlock; int regsPerBlock; int warpSize; size_t memPitch; int maxThreadsPerBlock; int maxThreadsDim[3]; int maxGridSize[3]; size_t totalConstMem; int major; ...
5,045
__device__ void left_to_right(int j0, int j1, int *d_rows_mp, int *d_aux_mp, int *d_low, int m, int p){ // Compute symmetric difference of supp(j0) and supp(j1) and store in d_aux // If rows are initially sorted, this returns a sorted list int idx0 = j0*p; int idx1 = j1*p; int idx0_MAX = (j0+1)*p...
5,046
#include <stdio.h> // Exmple doesn't work __global__ void print_kernel() { if (threadIdx.x == 1) { printf("Hello from block %d, thread %d\n", blockIdx.x, threadIdx.x); } } int main() { print_kernel<<<100, 10>>>(); //cudaDeviceSynchronize(); }
5,047
#include "includes.h" __global__ void axpb_y_i32 (int a, int* x, int b, int* y, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { y[idx] *= a * x[idx] + b; } }
5,048
#include "includes.h" __global__ void MultiplyAdd(float *d_Result, float *d_Data, int width, int height) { const int x = __mul24(blockIdx.x, 16) + threadIdx.x; const int y = __mul24(blockIdx.y, 16) + threadIdx.y; int p = __mul24(y, width) + x; if (x<width && y<height) d_Result[p] = d_ConstantA[0]*d_Data[p] + d_Constant...
5,049
__global__ void kernel_add(float *proj1, float *proj, int iv, int na, int nb, float weight){ int ia = 16 * blockIdx.x + threadIdx.x; int ib = 16 * blockIdx.y + threadIdx.y; if (ia >= na || ib >= nb) return; proj1[ia + ib * na] += proj[ia + ib * na + iv * na * nb] * weight; } // __global__ void ...
5,050
/* * Device code */ __global__ void GaussSolve( int const Nsize, double* d_Aug, double* d_Piv) { // Assign matrix elements to blocks and threads int i = blockDim.x*blockIdx.x + threadIdx.x; // Parallel forward elimination for (int k = 0; k < Nsize-1; k++) { d...
5,051
#include<stdlib.h> #include<math.h> #include<iostream> #include<time.h> #define omega 1.5 using namespace std; __global__ void calculateU(double* u, double* f, double* pu, int N, double h2, int rb, double * e) { __shared__ double s_u[10][10]; e[0]=0; int i = blockIdx.x*blockDim.x + threadIdx.x; // "" int j = b...
5,052
#include "shared.cuh" struct ParticleRef { Point pos; Point dir; double nextdist; }; inline __device__ ParticleRef make_ref(const ParticleView &view, int i) { return {view.get_pos(i), view.get_dir(i), view.get_nextdist(i)}; } __device__ inline void saxpy(double *__restrict__ x, double *__restrict__ y, ...
5,053
#include "includes.h" __global__ void histDupeKernel(const float* data1, const float* data2, const float* confidence1, const float* confidence2, int* ids1, int* ids2, int* results_id1, int* results_id2, float* results_similarity, int* result_count, const int N1, const int N2, const int max_results) { const unsigned in...
5,054
/* * GPUKernels.cu * * Created on: Oct 19, 2010 * Author: yiding */ #include <cuda_runtime.h> #include <math.h> #include <cuda.h> #define NOID 0xFFFFFFFF #define CUDA_MAJOR_VER 1 #define CUDA_MINOR_VER 3 typedef unsigned int CoordType; typedef unsigned int IdType; typedef unsigned short CapType; typed...
5,055
#include <pthread.h> #include <stdio.h> #include <string.h> #include <math.h> #ifndef D #define D 10000 #endif #ifndef N_FILES #define N_FILES 21000 #endif #define ARG_COUNT 4 #define MAX_FILE_NAME 100 #define GMEM_GRANULARITY 128 #define INV_DICT_WIDTH ((unsigned int)(ceil(N_FILES / (float)(sizeof(int)...
5,056
#include "includes.h" __global__ void VecAdd(int *a, int *b, int *c, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; if(i < n) { c[i] = a[i] + b[i]; } }
5,057
/** * Copyright (c) 2017 Darius Rückert * Licensed under the MIT License. * See LICENSE file for more information. */ #include <iostream> #include <vector> #include <cuda_runtime.h> #include <thrust/device_vector.h> template <unsigned int BLOCK_SIZE> __global__ static void oob(int* data, int size) { auto id...
5,058
#include <stdio.h> #include <stdlib.h> inline void check_cuda_errors(const char *filename, const int line_number){ #ifdef DEBUG cudaThreadSynchronize(); cudaError_t error = cudaGetLastError(); if(error != cudaSuccess){ printf("CUDA error at %s:%i: %s\n", filename, line_number, cudaGetErrorString(error)); exit(-1); } #...
5,059
#include<stdio.h> #define NUM_THREADS_PER_BLOCK 256 __global__ void print_hello() { int idx = threadIdx.x; printf("Hello World! My threadId is %d\n", idx); } int main() { print_hello<<<1, NUM_THREADS_PER_BLOCK>>>(); cudaDeviceSynchronize(); return 0; }
5,060
// Array reversing in CUDA using shared memory. #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <chrono> #include <cstdlib> #include <iostream> __global__ void reverseKernel(float* A, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) { extern __shar...
5,061
/*------------vec_add.cu------------------------------------------------------// * * Purpose: This is a simple cuda file for vector addition * *-----------------------------------------------------------------------------*/ #include <iostream> #include <math.h> __global__ void vecAdd(double *a, double *b, double *c, ...
5,062
#include <stdio.h> #include <stdlib.h> //#include <sys/time.h> #define NUM_PARTICLES 10000 // Third argument #define NUM_ITERATIONS 100 // Second argument #define BLOCK_SIZE 16 // First argument typedef struct { float3 position; float3 velocity; } Particle; __global__ void timeStep(Particle *particles, int tim...
5,063
// #include <bits/stdc++.h> #include<stdio.h> #include<stdlib.h> #include<iostream> #include<vector> #include<algorithm> #include <climits> #include <thrust/swap.h> #include <thrust/extrema.h> #include <thrust/functional.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> using namespace std; typedef...
5,064
#include "includes.h" __global__ void kRotate180(float* filters, float* targets, const int filterSize) { // __shared__ float shFilter[16][16]; const int filtIdx = blockIdx.x; const int readStart = MUL24(MUL24(filterSize, filterSize), filtIdx); filters += readStart; targets += readStart; for(int y = threadIdx.y; y <...
5,065
#include "includes.h" __global__ void forwardDifference2DAdjointKernel(const int cols, const int rows, const float* dx, const float* dy, float* target) { for (auto idy = blockIdx.y * blockDim.y + threadIdx.y + 1; idy < cols - 1; idy += blockDim.y * gridDim.y) { for (auto idx = blockIdx.x * blockDim.x + threadIdx.x + 1;...
5,066
#include "cuda_runtime.h" #include "stdio.h" __device__ float devData[5]; __global__ void checkGlobalVariable(){ devData[threadIdx.x] += 2.0f; } int main(void){ float value[5] = {3.14, 3.14, 3.14, 3.14, 3.14}; cudaMemcpyToSymbol(devData, &value, sizeof(float)*5); printf("Copy \n"); checkGlobalVa...
5,067
#include <assert.h> #include <stdio.h> #include <stdlib.h> __device__ int iterate_pixel(float x, float y, float c_re, float c_im) { int c=0; float z_re=x; float z_im=y; while (c<255) { float re2=z_re*z_re; float im2=z_im*z_im; if ((re2+im2) > 4) break; z_im=2*z_re*z_im + c_im; z_re=re2-im2 + c_re; c++...
5,068
// Copyright (c) 2020 Saurabh Yadav // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include <stdio.h> #include <cuda_runtime.h> #define NUM_OF_ELEMENTS 40000U #define ARRAY_A_ELEMENT ((int) 'A') #define ARRAY_B_ELEMENT ((int) 'B') //Compute vector sum C = A+B //Each...
5,069
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <stdio.h> #include <iostream> #include <cstring> using namespace std; __global__ void multiplyDigits(char* d_str1, char* d_str2, int* d_matrix, int str1_len, int str2_len) { int row = blockDim.y * blockIdx.x + threadIdx.y; int col = blockDim.x...
5,070
#include "includes.h" __global__ void global_max(int *values, int *max, int *reg_maxes, int num_regions, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; int region = i % num_regions; if(i < n) { int val = values[i]; if(atomicMax(&reg_maxes[region], val) < val) { atomicMax(max, val); }//end of if statement }//en...
5,071
#include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <device_launch_parameters.h> #define ARRAY_SIZE 1024*1024 #define NUM_THREADS 1024 // Saxpi 1 - Versin en C void saxpi_c(int n, float a, float* x, float* y) { for (int i = 0; i < n; i++) y[i] = a * x[i] + y[i]; } ...
5,072
/**********************************************************************\ * Author: Jose A. Iglesias-Guitian * * C/C++ code * * Introduction to CUDA * /**********************************************************************/ // Instructions: How to compile this...
5,073
#include <cassert> #include <cstdlib> #include <iostream> #define MASK_DIM 7 #define MASK_OFFSET (MASK_DIM / 2) __constant__ int mask[7 * 7]; __global__ void conv2d(int *matrix, int *result, int N) { int y = blockIdx.y * blockDim.y + threadIdx.y; int x = blockIdx.x * blockDim.x + threadIdx.x; int s_y = y -...
5,074
#define NSTREAM 4 #include<stdio.h> __global__ void addVec(int* a, int* b, int* c, int const len){ int i = blockDim.x*blockIdx.x + threadIdx.x; if (i<len) c[i] = a[i] + b[i]; }; int main(){ int const totalLen = 1<<16; int const mSize = totalLen*sizeof(int); int* h_a; int* h_b; int* h_c;...
5,075
#include <stdio.h> #include <string.h> #include <cmath> #include <iostream> #include <fstream> #include <ctime> #include <random> using namespace std; //use seed from time to generate random values std::mt19937 rng(time(0)); //used to set time to collision as a high value to indicate no collision int const NO_VALUE ...
5,076
#include "includes.h" __global__ void ComputeBiasTermKernel( float *biasTerm, float cFactor, float *winningFraction, int activeCells, int maxCells ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blockDim.x*blockIdx.x //blocks preceeding current block + threadIdx.x; if(th...
5,077
#include "includes.h" __global__ void compute_l(double *dev_w, int n_patch) { int tid = threadIdx.x + blockIdx.x * blockDim.x; int N = n_patch * n_patch; while (tid < N) { dev_w[tid] = ((tid % (n_patch + 1) == 0) ? 1.0 : 0.0) - dev_w[tid]; tid += blockDim.x * gridDim.x; } }
5,078
#include <iostream> #include <vector> #include <cmath> #include <string> using namespace std::string_literals; #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/count.h> __global__ void add(unsigned int N, thrust::device_ptr<float> a, thrust::device_ptr<float> b) { auto index = ...
5,079
// vAdd.cu // // driver and kernel call #include <stdio.h> #define THREADS_PER_BLOCK 32 __global__ void vAdd_d (int *a_d, int *b_d, int *c_d, int n) { int x = blockIdx.x * blockDim.x + threadIdx.x; if (x < n) c_d[x] = a_d[x] + b_d[x]; } extern "C" void gpuAdd (int *a, int *b, int *c, int arraySize) { in...
5,080
#include <stdio.h> #define NUM_BLOCKS 16 #define BLOCK_WIDTH 1 __global__ void hello() { printf("Hello world! I'm a thread in block %d\n", blockIdx.x); // It has 16! different ways in which the thread blocks can be run } int main(int argc,char **argv) { // launch the kernel hello<<<NUM_BLOCKS, BLOCK...
5,081
/* Daniel Sá Barretto Prado Garcia 10374344 Tiago Marino Silva 10734748 Felipe Guilermmo Santuche Moleiro 10724010 Laura Genari Alves de Jesus 10801180 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define THREADS 32 #define INF 0x7fffffff __global__ void prodEscalar(int* A, int* B, int* somaD...
5,082
#include "includes.h" __global__ void HessianPositiveDefiniteKernel( char *d_hessian_pd, float *d_Src, int imageW, int imageH, int imageD ) { __shared__ float s_Data[HES_BLOCKDIM_Z+2][HES_BLOCKDIM_Y+2][(HES_RESULT_STEPS + 2 * HES_HALO_STEPS) * HES_BLOCKDIM_X]; //Offset to the left halo edge const int baseX = (blockIdx...
5,083
#include "includes.h" __global__ void profilePhaseSolve_kernel() {}
5,084
#include <assert.h> #include <iostream> #include <cstdlib> #include<sys/time.h> #include <cmath> #include "cuda_runtime.h" const int LANGE = 16; __global__ void vecAdd(double *d_a, double *d_b, double *d_c, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < (N / LANGE)) { int large = ...
5,085
#include <iostream> #include <cmath> using namespace std; __global__ void add(double *x, double *y, int N) { int i, ind, stride; ind = blockIdx.x*blockDim.x + threadIdx.x; stride = gridDim.x * blockDim.x; for(i=ind; i<N; i+=stride) { y[i] += x[i]; } } int main() { double *d_x, *d_y, *x, *y, err{0.}; int N ...
5,086
#include "includes.h" #define NOMINMAX const unsigned int BLOCK_SIZE = 512; __global__ void addKernel(float *c, const float *a, const float *b) { int i = threadIdx.x; c[i] = a[i] + b[i]; }
5,087
#include "includes.h" __global__ void addWalkers ( const int dim, const int nwl, const float *xx0, const float *xxW, float *xx1 ) { int i = threadIdx.x + blockDim.x * blockIdx.x; int j = threadIdx.y + blockDim.y * blockIdx.y; int t = i + j * dim; if ( i < dim && j < nwl ) { xx1[t] = xx0[t] + xxW[t]; } }
5,088
#include <sstream> #include <iomanip> #include <cuda.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <curand.h> #include <curand_kernel.h> #include <iostream> using namespace std; #define NUM_POINTS_PER_THREAD 1000 __global__ void kernel_initializeRand( curandState * randomGeneratorStat...
5,089
__global__ void add_kernel(int *x, int a, int b) { x[0] = a + b; } void add(int *x, int a, int b) { add_kernel<<<1, 1>>>(x, a, b); }
5,090
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <math.h> // #include <stdexcept> #define CUDA_CALL(x) do { if((x)!=cudaSuccess) { \ printf("Error at %s:%d\n",__FILE__,__LINE__);\ return EXIT_FAILURE;}} while(0) __global__ void prepare_function(float * d_out, int n_points, ...
5,091
#include <stdio.h> __global__ void kernel1( int *a ) { int idx = blockIdx.x*blockDim.x + threadIdx.x; a[idx] = 7; // output: 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 } __global__ void kernel2( int *a ) { int idx = blockIdx.x*blockDim.x + threadIdx.x; a[idx] = blockIdx.x; // output: 0 0 0 0 1 1 1 1 ...
5,092
#include <cuda.h> #include <cuda_runtime_api.h> #define N_MEM_OPS_PER_KERNEL 2 //----------------------------------------------------------------------------- // Simple test kernel template for memory ops test // @param d_counters - Simple memory location to exploit for lots of memory accesses // @param n_threads ...
5,093
/* Kernel for vector squaring */ __global__ void gpusquare(float in[], float out[], int n) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < n) { out[i] = in[i] * in[i]; } }
5,094
#include "includes.h" __device__ unsigned int getGid3d3d(){ int blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z) + (threadIdx.y * blockDim.x) + (threadIdx.z * (blockDim.x * blockDim.y)) + threadIdx.x; return threadId; } _...
5,095
#include "includes.h" __global__ void cuda_mul(int* A, int* B, int* C, int w) { int tid,tx,ty; //range of tx,ty 0 ~ w tx = blockDim.x * blockIdx.x + threadIdx.x; ty = blockDim.y * blockIdx.y + threadIdx.y; tid = w*ty + tx; int v = 0; int a = 0; int b = 0; /* oooo oxo xxxx X oxo oooo oxo oxo */ for(int i=0;i...
5,096
#include <stdio.h> // add sera ejecuta en el device // add será llamada desde el host // add corre en device asi que a,b y c deben apuntar a memoria del device __global__ void add(int *a, int *b, int *c){ *c = *a + *b; } int main(void){ int a, b, c; // Copias de a b y c en el host int *d_a, *d_b, *d_...
5,097
//nvcc -ptx EM2.cu -ccbin "F:Visual Studio\VC\Tools\MSVC\14.12.25827\bin\Hostx64\x64" __device__ void EM1( double * x, double * y, double * z, double * vx, double * vy, double * vz, double * ...
5,098
#include <stdio.h> #include <stdlib.h> #include <time.h> /*#define M(row, col) *(M.elements + (row) (*) M.width + col)*/ typedef struct { int width; int height; float* elements; } Matrix; //a h w B h w C void MatMul(const Matrix A, const Matrix B, Matrix C) { for (int i = 0; i < A.height; i++...
5,099
#include <cstdio> #include <cstdlib> #include <cmath> #define N 9999 // number of bodies #define MASS 0 // row in array for mass #define X_POS 1 // row in array for x position #define Y_POS 2 // row in array for y position #define Z_POS 3 // row in array for z position #define X_VEL 4 // row in array for x velocity ...
5,100
// write your code into this file #define TILE_X 16 #define TILE_Y 8 #define TILE_Z 8 #define PADDING 1 __global__ void compute_cell(int* in_array, int* out_array, int dim); void solveGPU(int **dCells, int dim, int iters) { dim3 threadsPerBlock(TILE_X, TILE_Y, TILE_Z); dim3 numBlocks((int)ceil(dim/(float)(TILE_X-2)...