serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
23,001
//##########################################################// // Name: Kirtan Mali // // Roll no: 18AG10016 // // Question 3: Matrix Transpose using Dynamic Shared Mem // //##########################################################// #inc...
23,002
#include "includes.h" __global__ void vecmabite( int *out, int *in, std::size_t size ) { auto tid = threadIdx.x; out[ tid ] = in[ 2 * tid ]; }
23,003
#include <iostream> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/random/linear_congruential_engine.h> #include <thrust/random/uniform_real_distribution.h> struct rng_transform{ int SEED; __device__ __host__ double operator() (const int &i){ thrust::minstd_ra...
23,004
// // Created by zhaoxuanzhu on 3/21/21. // #include "problem.cuh"
23,005
extern __device__ __constant__ char d_coef[2]; char g_coef[2]={'a','b'}; void pre() { cudaMemcpyToSymbol(d_coef,g_coef,sizeof(char)*2); }
23,006
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1024 __global__ void CUDASubstring(char *A, char *C, int *sL, int *pFound) { int id = threadIdx.x; if(id == 0 || A[id-1] == ' ') { int fMatch = 1; for (int i = 0; i < *sL; i++) ...
23,007
#include <stdio.h> #include <stdlib.h> #include <time.h> __device__ double logsumexp(double a, double b) { if(a <= -1e20) { return b; } else if(b <= -1e20) { return a; } /*double diff = a-b; if (diff < -20.0f) { return b; } else if (diff > 20.0f) { return a; }*/ if(a > b) { return a + l...
23,008
#include <stdio.h> #include <stdlib.h> #include <cuda.h> __global__ void revArray(int N, float *a, float *b) { int n = threadIdx.x + blockIdx.x*blockDim.x; if(n<N) { b[N-1-n] = a[n]; } } int main(int argc, char **argv) { int N = 100; //Host memory allocation float *h_a = (float*) malloc(N*sizeof(float...
23,009
#include "includes.h" __global__ void weighted_interpolate_backward(int B, int N, int M, int C, int K, const int* nnIndex, const int* nnCount, const float* gradOutput, const float* weight, float* gradInput) { for(int i=blockIdx.x;i<B;i+=gridDim.x) { for(int j=threadIdx.x;j<N*C;j+=blockDim.x) { int n = j/C; int c = j%C;...
23,010
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <math.h> #define N 6000 /* Matrix size */ float A[N][N], B[N][N]; int threadPerBlock=256; int block=(int)N/threadPerBlock; /* Initialize A and B*/ void initialize_inputs() { int row, col; srand((unsigned)time(NULL)...
23,011
// // Created by gautam on 02/05/20. // #include "ColType.cuh" ColType newColType() { ColType c; c.type = TYPE_INVALID; c.size = 0; // c.str = ""; strcpy(c.str, ""); return c; } ColType newColType(std::string typeString) { ColType c; // utils::toLower(typeString); // c.str = typeS...
23,012
#include <stdio.h> #include <cuda_runtime_api.h> #include <time.h> /**************************************************************************** This program gives an example of a poor way to implement a password cracker in CUDA C. It is poor because it acheives this with just one thread, which is obviously not g...
23,013
#include <stdio.h> __global__ void dummy() { int j = 0; for(int i = 0; i < 1000000; i++) j++; } int main() { cudaStream_t stream1, stream2; double *A, *B, *C, *D; cudaSetDevice(2); cudaMalloc((void **) &C, 100000000 * sizeof(double)); cudaSetDevice(0); cudaMalloc((void **) &D, 100000000 * sizeof(double))...
23,014
/* Author: Su Ming Yi Date: 11/16/2018 Goal: Add 2D array by cuda How to compile it: nvcc -O -o example_3 example_3.cu How to run it: ./example_3 */ #include "stdio.h" #define COLUMNS 3 #define ROWS 2 __global__ void add(int *a, int *b, int *c) { int x = blockIdx.x; int y = blockIdx.y; int i ...
23,015
int lenInts, lenFloats, numPrototypes, numCoordinates; int *d_ints; float *d_floats; float *d_prototypes; float *d_activationRadii; int *d_features; void initialize(int _lenInts, int _lenFloats, int _numPrototypes, float *h_activationRadii){ lenInts = _lenInts; lenFloats = _lenFloats; numPrototypes = _numProto...
23,016
#include "includes.h" #define _USE_MATH_DEFINES static void CheckCudaErrorAux(const char *, unsigned, const char *, cudaError_t); #define CUDA_CHECK_RETURN(value) CheckCudaErrorAux(__FILE__,__LINE__, #value, value) /** * Check the return value of the CUDA runtime API call and exit * the application if the call h...
23,017
#include <stdio.h> #include <unistd.h> #define HANDLE_ERROR(x) {\ cudaError_t status = x;\ if (status) {\ printf("Error %d line %d\n", status, __LINE__);\ }\ } const int chunk = 10; const int limit = 100; const int target = 2000; #define check_and_add(M) {\ mult(X, M, Y);\ if (!dup(&queue,...
23,018
/** * @Author: Giovanni Dalmasso <dalmasso> * @Date: 14-Sep-2018 * @Email: giovanni.dalmasso@embl.es * @Project: IntroToParallelProgramming * @Last modified by: gioda * @Last modified time: 14-Sep-2018 * @License: MIT **/ #include <stdio.h> // squaring number using CUDA __global__ void square(float *d_ou...
23,019
/* * purpose: CUDA managed unified memory for >= pascal architectures; * this version just uses cudaMallocManaged() on the host, * then runs kernels on the GPU to add together two arrays * of size 1 GB and save the results into a third array; * n.b. her...
23,020
#include "point.cuh" // Default constructor __host__ __device__ Point::Point() { this->x = 0; this->y = 0; this->z = 0; } // Normal constructor __host__ __device__ Point::Point(float x, float y, float z) { this->x = x; this->y = y; this->z = z; } // Returns the norm of a point treated like a ...
23,021
#include <thrust/for_each.h> #include <thrust/iterator/counting_iterator.h> struct sum_Functor { int *sum; sum_Functor(int *s){sum = s;} __host__ __device__ void operator()(int i) { *sum+=i; printf("In functor: i %d sum %d\n",i,*sum); } }; int main(){ thrust::counting_ite...
23,022
#include <stdio.h> #include <cuda.h> #include <cuda_runtime.h> #include <cuda_runtime_api.h> #include <curand.h> #include <curand_kernel.h> #include "kernels.cuh" __device__ __forceinline__ int get_polarity(int id) { // If id is an even number, 1 will be returned. // If id is an odd number, -1 will be return...
23,023
#include<cuda_runtime.h> // Kernel definition __global__ void MatAdd(float A, float B, float C) { int i = threadIdx.x; int j = threadIdx.y; C= A + B; }
23,024
#include <iostream> #include <fstream> #include <cmath> #include <cstdlib> #include <string> #include <iomanip> #define T_P_B 1024 ///////////////////////////// Global variables ///////////////////////////////// std::string dimension; // grid dimension float k; // k-step int timeste...
23,025
#include "includes.h" __global__ void gpuTranspose(float *a, float *b, int m, int n) { uint i = blockDim.x * blockIdx.x + threadIdx.x; uint j = blockDim.y * blockIdx.y + threadIdx.y; if (i < m && j < n) { b[j * m + i] = a[i * n + j]; } }
23,026
#include "kernels.cuh" // TESETER: Tarek // Incremement times by drawn RVs // double[] randomVariables: The random variables array on device // double[] times: The array of times on device // size_t s: the number of simulations __global__ void updateTimesKernel(double* randomVariables, double* times, size_t s) { int...
23,027
#include "Graph.cuh" #include "CudaHelper.cuh" #include "VectorHelper.cuh" namespace atspSolver { Graph::Graph(int numberOfNodes) : numberOfNodes_(numberOfNodes), adjacencyMatrix_(new double[numberOfNodes*numberOfNodes]) { Graph::generateGraph(); } Graph::Graph(const double *adjacencyMatrix, int numberOfNodes) ...
23,028
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <thrust/random.h> #include <thrust/inner_product.h> #include <thrust/binary_search.h> #include <thrust/adjacent_difference.h> #include <thrust/iterator/constant_iterator.h> #include <thrust/itera...
23,029
#include "includes.h" __global__ void FullyConnectedUpdateMemoryKernel( float *avgWeightGradPtr, float *avgBiasGradPtr, float *avgWeightGradVarPtr, float *avgBiasGradVarPtr, float *weightMemorySizePtr, float *biasMemorySizePtr, float *dropoutMaskPtr, int prevLayerSize, int thisLayerSize ) { // i: prev. layer neuron id ...
23,030
// Yuxuan, 27 June // Parallel (CUDA) version of Hines algorthm. #include <cstdio> #include <cstdlib> #include <ctime> #include <cstring> #include <cuda.h> __global__ void HinesAlgo ( double *u, double *l, double *d, double *rhs, int *p, int N ) { int i; double factor; int offset = blockIdx.x * N...
23,031
#include <iostream> #include <algorithm> __managed__ unsigned int messagenum = 0; using namespace std; // kernal function takes in arguments cipher c, modulus n, messagelist(Which is shared betweeen host // and device in Unified memory). __global__ void breakingrsa(unsigned long long ciphertext,unsigned long long i...
23,032
#include<stdio.h> #include<cuda.h> #include<stdlib.h> #define WIDTH 100; __global__ void Matrix_multiplication(int *A, int *B, int *C, int n){ int col=threadIdx.x+blockIdx.x*blockDim.x; int row=threadIdx.y+blockIdx.y*blockDim.y; int value=0; if((row<n)&&(col<n)) for(int k=0; k<n; k++){ value+=A[row*n+k]*B[co...
23,033
#include "includes.h" __global__ void cu_copyMakeBorder(const float *src, float* dst, const int rowssrc, const int colssrc, const int up, const int down, const int left, const int right, const int n){ int tid = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; int colsdst = colssrc + left + ri...
23,034
template <class T, int gaussElim> __device__ void serial(T *a, T *b, T *c, T *d, int numEqs, int thid){ c[thid] = c[thid] / b[thid]; d[thid] = d[thid] / b[thid]; T tmp1, tmp2; for (int i = gaussElim+thid; i < numEqs; i+=gaussElim) //i=stride+thid; i + = stride; i < numEqs*numSerialize (systemSize)...
23,035
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void radix(int *a, int *b, int n, int count){ int id = threadIdx.x; int i=0, data=0, j=0, pos=0; int temp = a[id]; while(j<=count){ data=temp%10; temp/=10; j++; } for(i=0; i<n; i++){ j=0; int data2, temp=a...
23,036
#include <stdio.h> #include <time.h> void cVecAdd(float *A, float *B, float *C) { for(long long i=0; i < (4096 * 16); ++i) { C[i] = A[i] + B[i]; } } __global__ void VecAdd(float *A, float *B, float *C) { long long i = threadIdx.x + blockIdx.x * blockDim.x; C[i] = A[i] + B[i]; } int main() { const lo...
23,037
#include<stdio.h> #include<stdlib.h> #include<getopt.h> #include <assert.h> #include <cuda.h> #include <time.h> static char* program_name; // Usage void print_usage (FILE* stream, int exit_code) { fprintf (stream, "Usage: %s options\n", program_name); fprintf (stream, " -h --help Display...
23,038
// #CSCS CUDA Training // // #Example 1 - retrieve device info // // #Author Ugo Varetto // // #Goal: compute the maximum size for a 1D grid layout. i.e. the max size for 1D arrays that allows // to match a GPU thread with a single array element. // // #Rationale: CUDA on arch < 2.x requires client code to con...
23,039
#include "includes.h" __global__ void kernel_updateFullMatrix( float * device_fullMatrix, float * B, float * V, float * Cm, float * Em, float * Rm, float dt, unsigned int nComp ) { //TODO: fix memory usage matter unsigned int t = threadIdx.x; unsigned int baseIndex = t*nComp; unsigned int i; for ( i = 0; i < nComp; i...
23,040
#include "includes.h" __global__ void _kpolymap32(int n, float *k, float c, float d) { int i = threadIdx.x + blockIdx.x * blockDim.x; while (i < n) { k[i] = pow(k[i] + c, d); i += blockDim.x * gridDim.x; } }
23,041
#include "includes.h" __global__ void aypb_f32 (float a, float* y, float b, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { y[idx] = a * y[idx] + b; } }
23,042
//Reference implementation of reduction with dot product //#include <cuda_runtime.h> // automatically added by nvcc #include <vector> #include <iostream> typedef float real_t; const size_t BLOCK_SIZE = 16; __global__ void full_dot( const real_t* v1, const real_t* v2, real_t* out, int N ) { __shared__ real_t ca...
23,043
// includes, system #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <cuda_runtime.h> #define N 256 // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char *msg) { cudaError_t err = cudaGetLastError(); if( err != cudaSuccess) { ...
23,044
#include<stdio.h> __global__ void add(int* a, int* b, int* c, int n) { int idx = threadIdx.x; if(idx<n) c[idx] = a[idx]+ b[idx]; } int main(){ int n; scanf("%d",&n); float elapsed_time; cudaEvent_t start,stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start,0); cudaStream_t stream0...
23,045
__global__ void simple_loop(int *a) { int tid = threadIdx.x; for (int i = 0; i < 5; i++) { a[tid * 4] += a[tid * 4 + i]; } }
23,046
#include "includes.h" __global__ void kernel_set_vector_to_zero(double *d_vec, int dimension) { int iam = threadIdx.x; int bid = blockIdx.x; int threads_in_block = blockDim.x; int gid = bid*threads_in_block + iam; if (gid < dimension){ d_vec[gid] = 0; } }
23,047
#include <iostream> #include <stdlib.h> #include <math.h> #include <algorithm> using namespace std; int base[3][4]; int base7[3][7]; int tranposeBase7[7][3]; int base8[3][8]; int base11[3][11]; int base12[3][12]; int base13[3][13]; int base14[3][14]; int board7[7][7]; int board8[8][8]; void loadData() { //base 3*4 b...
23,048
/*----------------------------------------------------------- ** gaussian.cu -- The program is to solve a linear system Ax = b ** by using Gaussian Elimination. The algorithm on page 101 ** ("Foundations of Parallel Programming") is used. ** The sequential version is gaussian.c. This parallel ** implem...
23,049
#include <stdio.h> __global__ void matrixs_1D_multiplication(int *matrix_a_dev, int *matrix_b_dev, int *matrix_c_dev, int matrix_width) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; if(row < matrix_width && col < matrix_width) { for(int k =...
23,050
// Dummy file to trigger CUDA compile in this project
23,051
// dijkstra 算法的并行自全源加未更新快速退出 __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; // the number of threads in a block const...
23,052
#include <cuda.h> #include <cuda_runtime.h> #include<iostream> __global__ void kernel_update_models(float4* d_positions, float4* d_modelBuffer, int numel) { size_t col = threadIdx.x + blockIdx.x * blockDim.x; if (col >= numel) { return; } d_modelBuffer[col*4+3] = make_float4( d_positions[col].x, d_positions[c...
23,053
#include "includes.h" __global__ static void gaussdensity_direct_tex(int natoms, const float4 *xyzr, const float4 *colors, float gridspacing, unsigned int z, float *densitygrid, float3 *voltexmap, float invisovalue) { unsigned int xindex = (blockIdx.x * blockDim.x) * DUNROLLX + threadIdx.x; unsigned int yindex = (blo...
23,054
#include <stdlib.h> #include <stdio.h> #include <cuda.h> #include <math.h> #include <curand_kernel.h> #define ITER_PER_THREAD 256 #define NUMBER_OF_THREAD 256 __global__ void pi_cal(long *niter, long *a,curandState *state){ long idx = (blockDim.x * blockIdx.x) + threadIdx.x; long count = 0; float x,y,z; curand_i...
23,055
#include <cstdlib> #include <cassert> #include <iostream> // __global__ indicates it will called from the host and run on the device // __device__ is for device/device and __host__ for host/host __global__ void matrixMul (float*a, float* b, float* c, int N) { // get the global thread ID int row = blockIdx.x * ...
23,056
#include "includes.h" __global__ void lots_of_double_compute(double *inputs, int N, size_t niters, double *outputs) { size_t tid = blockIdx.x * blockDim.x + threadIdx.x; size_t nthreads = gridDim.x * blockDim.x; for ( ; tid < N; tid += nthreads) { size_t iter; double val = inputs[tid]; for (iter = 0; iter < niters; i...
23,057
// get cuda max hardware concurrency // by stdio2016 2023-03-18 #include<cuda.h> #include<stdio.h> __device__ int current_concurrency = 0; __device__ void waitClockGpu(int time) { long long t0 = clock64(); while (clock64() - t0 < time) { ; } } __global__ void concurrency_test(int *max_concurrency) {...
23,058
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/sequence.h> #include <thrust/count.h> int main() { /** * \brief armando2D v2.0 * * An SPH code for non stationary fluid dynamics. * Th...
23,059
#include <iostream> #include <math.h> // function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { int index = blockIdx.x * blockDim.x + threadIdx.x; y[index] = x[index] + y[index]; } int main(void) { int N = 1 << 20; // 1M elements float *x, *y; cudaMallocManaged(&x, N*sizeof(fl...
23,060
#include <cstdio> using namespace std; __global__ void adder(float* arr, float* block_incrs, int n) { int tid = threadIdx.x; extern __shared__ float sum[]; int gtid = blockIdx.x * blockDim.x + threadIdx.x; if (tid == 0) sum[0] = block_incrs[blockIdx.x]; __syncthreads(); if (gtid < n) arr[gtid] += s...
23,061
#include<stdio.h> __managed__ int sum=0; __global__ void Array_sum(int *a, int *n) { int tid = threadIdx.x; if(tid < *n) atomicAdd(&sum, a[tid]); } int main() { int n = 10, i; int a[n]; int *cuda_a, *cuda_n; for(i=0; i<n; i++) { a[i] = rand()%100; printf("%d ", a[i...
23,062
#include "includes.h" __global__ void smooth( unsigned char *entrada,unsigned char *saida, int n_linhas, int n_colunas ) { //Calcula a posição no vetor (id_bloco * total_blocos + id_thread) int posicao = blockIdx.x * blockDim.x + threadIdx.x; //Se a posição não é maior que o limite da imagem original... if(posicao < (n...
23,063
#include "includes.h" __global__ void integrateBins(int width, int height, int nbins, int* devImage, int binPitch, int* devIntegrals) { __shared__ int pixels[16]; const int blockX = blockDim.y * blockIdx.x; const int threadX = threadIdx.y; const int bin = threadIdx.x; const int x = blockX + threadX; if (x >= width) ret...
23,064
#include<stdio.h> #include<stdlib.h> #include<curand_kernel.h> #include<curand.h> #include<sys/time.h> unsigned int NUM_PARTICLES = 100000; unsigned int NUM_ITERATIONS = 10; unsigned int BLOCK_SIZE = 192; unsigned int GRID_SIZE = ((NUM_PARTICLES/BLOCK_SIZE) + 1); typedef struct { float3 posId; }position; typedef st...
23,065
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> #include <unistd.h> #include <string> #include <cuda.h> #define ThreadNum 256 #define BlockNum 16 __global__ void printOut(char *string) { printf("%s\n", string); } size_t getFileSize(cha...
23,066
#include <iostream> int main() { std::cout << "basic/hello initialized!" << std::endl; }
23,067
#include "includes.h" __global__ void binarize_f32 (float* vector, float threshold, float* output, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { output[idx] = vector[idx] > threshold ? 1 : 0; } }
23,068
/* multiplication table using CUDA refer : http://blog.daum.net/heoly/7 (Thank you) */ #include <stdio.h> #include <malloc.h> #include <cuda_runtime.h> #define BLOCK_SIZE 8 #define THREAD_SIZE 9 // Device code __global__ void test(int *result) { int tidx, bidx; tidx = threadIdx.x; //x-coordinate of thread bidx...
23,069
#include <stdio.h> __device__ void helloCalledFromDevice() { printf("Device fn hello from GPU\n"); } __global__ void helloFromGPU() { printf("Hello from GPU thread %d\n", threadIdx.x); //helloCalledFromDevice(); } int main() { printf("Hello from CPU\n"); helloFromGPU<<<2, 5>>>(); cudaDeviceSynchronize(); }
23,070
#include <stdio.h> __global__ void forward_step1(float *weight_D, float *a_D, float *res1_D, unsigned int columns) { unsigned int tid = blockDim.x*threadIdx.y + threadIdx.x; unsigned int i = blockIdx.z; unsigned int j = (gridDim.x*blockIdx.y+blockIdx.x)*blockDim.x*blockDim.y + tid; __shared__ float partial...
23,071
#include <cuda.h> #include <stdio.h> int main(int argc, char** argv) { struct cudaDeviceProp p; int device; cudaGetDevice(&device); cudaGetDeviceProperties(&p, device); printf("> %s\n" "\ttotalGlobalMem: %u B\n" "\tsharedMemPerBlock: %u B\n" "\tregsPerBlock:...
23,072
__global__ void cuda_GetImgDiff(unsigned char *dest, unsigned char *a, unsigned char *b, int res) { int x = 3*threadIdx.x + 3*(blockIdx.x * blockDim.x); int y = (3 * res)*threadIdx.y + (3 * res)*(blockIdx.y * blockDim.y); int z = threadIdx.z; int i = (x + y + z); if(a[i] >= b[i]){ dest[i] = ...
23,073
/* Teste la peformance de rsqrt sur un grand nombre de valeurs aléatoires (version GPU) * À compiler avec `nvcc perf_gpu.cu -o test -O3` (requière CUDA!) */ #include <cmath> #include <chrono> #include <iostream> #include <cuda.h> #define N_FLOAT 100000000 #define MAX_FLOAT 1000 __global__ void rsqrt_vec(float* ve...
23,074
#include "includes.h" __global__ static void kernelCalcSum_EffectiveShareAccess_DoubleGlobalAccess(const int* dataArray, int arraySize, int* sum) { __shared__ extern int cache[]; int cacheIndex = threadIdx.x; int arrayIndex1 = (int)(blockDim.x * blockIdx.x + threadIdx.x); // first element int arrayIndex2 = arrayIndex...
23,075
#include <iostream> #include <iomanip> #include <sstream> #include <fstream> #include <numeric> #include <stdlib.h> #include <vector> #include <algorithm> using namespace std; #define REDUCE_BLOCK_SIZE 128 struct Matrix { Matrix() : elements(NULL), width(0), height(0), pitch(0) {} ~Matrix() { if (elements) delete[]...
23,076
// This is not really C++-code but pretty plain C code, but we compile it // as C++ so we can integrate with CUDA seamlessly. // If you plan on submitting your solution for the Parallel Sorting Contest, // please keep the split into main file and kernel file, so we can easily // insert other data. #define BLOCKSIZE ...
23,077
#include <stdio.h> __global__ void add(int* d_a, int* d_b, int* d_c){ int tid = threadIdx.x + blockIdx.x*blockDim.x; if(tid < 2000){ d_c[tid] = d_a[tid] + d_b[tid]; } } int main(int argc, char* argv[]){ cudaSetDevice(1); return 0; }
23,078
#include "includes.h" __global__ void conv_layer_forward_gpu(float *x, float *w, float *y, int h_in, int w_in, int w_out, int k, int m) { int n, m_, h, w_, p, q; n = blockIdx.x; // Batch index m_ = blockIdx.y; // Channel index h = threadIdx.y; // Pixel (h, w_) w_ = threadIdx.x; // Pixel (h, w_) float ans = 0; //...
23,079
#define W 500 #define H 500 #define TX 32 #define TY 32 __global__ void distanceKernel(float *d_out, int w, int h, float2 pos) { const int c = blockIdx.x*blockDim.x+threadIdx.x; const int r = blockIdx.y*blockDim.y+threadIdx.y; const int i = c+r*w; if((c>=w) || (r>=h)) return; d_out[i]=sqrtf((c-pos.x)*(c-pos.x)+(...
23,080
// #include <stdlib.h> // #include <stdio.h> // #include <math.h> // #include <string.h> // // //#include "cuPrintf.cu" // #include "K_Common.cuh" // #include <cutil.h> // #include "host_defines.h" // #include "builtin_types.h" // // #include "SimDEM.cuh" // #include "CudaUtils.cuh" // // // // Grid textures and co...
23,081
#include "includes.h" __global__ void stencil_1d(int n, double *in, double *out) { /* calculate global index in the array */ int globalIndex = blockIdx.x * blockDim.x + threadIdx.x; /* return if my global index is larger than the array size */ if( globalIndex >= n ) return; /* code to handle the boundary conditions *...
23,082
#include <iostream> #include <chrono> typedef std::chrono::high_resolution_clock Clock; __global__ void kernel(int n, float a, float* x, float* y){ for( int i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x){ x[i] = a * x[i] + y[i]; } } int main(void){ int N = 1 << 29;...
23,083
/* 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,int 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 va...
23,084
// Copyright (c) OpenMMLab. All rights reserved. #include <cuda_runtime.h> namespace mmdeploy { namespace cuda { __global__ void FillKernel(void* dst, size_t dst_size, const void* pattern, size_t pattern_size) { size_t idx = threadIdx.x + blockIdx.x * blockDim.x; auto p_dst = static_cast<uchar1*>(dst); auto p...
23,085
#include <iostream> #include <cuda_runtime_api.h> #include <cuda.h> // Define and implement the GPU addition function // This version is a vector addition, with N threads // and one block. // Adding one a and b instance and storing in one c instance. __global__ void add(int *a, int *b, int *c) { c[threadIdx.x] = a[t...
23,086
#include<stdlib.h> #include<stdio.h> #include<cuda.h> //indexes "threadIdx.x" elements into the array, adds threadId.x to it (effectively doubling it), then adding 1 __global__ void multiGo(float* arr) { arr[threadIdx.x] += threadIdx.x + 1; } int main() { int N = 5; size_t size = N * sizeof(float);//the size in by...
23,087
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> void query_device(){ int deviceCount = 0; cudaGetDeviceCount(&deviceCount); if (deviceCount == 0){ printf("No CUDA support device found\n"); } int devNo = 0; cudaDeviceProp iProp; cudaGetDeviceProperties(&iProp, dev...
23,088
#define _CRT_SECURE_NO_WARNINGS #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cuda.h> #include <cstdint> #include <cstdio> #include <chrono> #include <algorithm> #include <cassert> #include <iostream> //const bool DEBUG = true; // #define R1 64 // #define R2 2 #define INF INT32_MAX ...
23,089
#include <cuda.h> #include <iostream> #define N 1024 using namespace std; __global__ void add(int *a,int *b,int *c) { int tid = threadIdx.x; if(tid < N) { c[tid]=a[tid]+b[tid]; } } int main(int argc,char *argv[]) { int *a,*b,*c,*A_D,*B_D,*C_D; a=new int[N]; b=new int[N]; c=new...
23,090
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #include<pthread.h> #include<math.h> #define MAX_THREAD 1024 #define USAGE_EXIT(s) do{ \ printf("Usage: %s <# of elements> <random seed> \n %s\n", argv[0], s); \ exit(-1);\ }while(0); ...
23,091
#include "includes.h" __global__ void kWhere(float* condition_mat, float* if_mat, float* else_mat, float* target, unsigned int len) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int numThreads = blockDim.x * gridDim.x; for (unsigned int i = idx; i < len; i += numThreads) { target[i] ...
23,092
#include <stdio.h> #include "FileUtils.cuh" int n_lines(const char *file) { FILE *myfile = fopen(file, "r"); int ch, n_lines = 0; do { ch = fgetc(myfile); if (ch == '\n') { n_lines++; } } while (ch != EOF); // last line doesn't end with a new line! // ...
23,093
#include "includes.h" __global__ void Compute_Path(int *Md, const int Width, const int k) { //2 Thread ID int ROW = blockIdx.x; int COL = threadIdx.x; if (Md[ROW * Width + COL] > Md[ROW * Width + k] + Md[k * Width + COL]) Md[ROW * Width + COL] = Md[ROW * Width + k] + Md[k * Width + COL]; }
23,094
#include "includes.h" __global__ void BFS_UNIFIED(int source, int* edges, int* dest, int* label, int* visited, int *c_frontier_tail, int *c_frontier, int *p_frontier_tail, int *p_frontier) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < *p_frontier_tail) { int c_vertex = p_frontier[i]; for (int i = edges[c_v...
23,095
#include "includes.h" //FILE IO RELATED //max number of lines in the training dataset #define MAX_ROWS_TRAINING 16896 // max number of columns/features in the training dataset #define MAX_COLUMNS_TRAINING 26 // max number of rows in the testing dataset #define MAX_ROWS_TESTING 4096 // max number of columns in the test...
23,096
#include "includes.h" __global__ void testKernel( float* g_idata, float* g_odata) { float result=1; // read two values float val1 = g_idata[0]; float val2 = g_idata[1]; // place loop/unrolled loop here to do a bunch of multiply add ops // make sure you use results, so compiler does not optomize out result = val2 + (re...
23,097
#include "sum.cuh" #include <cstdio> #include <iostream> const float COEFFICIENT = 1389.38757; int get_max_cols(Matrix A) { int globalsum = 0; int n = A.height; for (size_t i = 0; i < n; i++) { int localsum = 0; for (size_t j = 0; j < n; j++) { if (A.elements[i * n + j] > 0) {...
23,098
#include "includes.h" __global__ void kernelGradf(const float *d_x, float *d_grad) { const float x0 = d_x[0]; const float x1 = d_x[1]; // df/dx0 = -2 (1-x0) - 400 (x1-x0^2) x0 // df/dx1 = 200 (x1 - x0^2) d_grad[0] = -2.0f * (1.0f - x0) - 400.0f * x0 * (x1 - x0*x0); d_grad[1] = 200.0f * (x1 - x0*x0); }
23,099
/* * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use...
23,100
#include <iostream> using namespace std; // Scan, limited to 1 block, upto 1024 threads; __global__ void scan(unsigned int *g_odata, unsigned int *g_idata, int n) { extern __shared__ unsigned int temp[]; // allocated on invocation int thid = threadIdx.x; int pout = 0, pin = 1; int Ndim=n; // Load in...