serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
22,301
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand_kernel.h> #include <math_constants.h> extern "C" { __global__ void rtruncnorm_kernel( float *x, // Vector to contain returned samples int n, // Number of samples to return floa...
22,302
#include "includes.h" #define HISTOGRAM_LENGTH 256 __global__ void histo_kernel(unsigned char * buffer, unsigned int * histo, long size) { // compute histogram with a private version in each block __shared__ unsigned int histo_private[HISTOGRAM_LENGTH]; int bx = blockIdx.x; int tx = threadIdx.x; // ind...
22,303
#include <stdio.h> #define N 2048 * 2048 // Number of elements in each vector __global__ void saxpy(float scalar, float * x, float * y) { // Determine our unique global thread ID, so we know which element to process int tid = blockIdx.x * blockDim.x + threadIdx.x; if ( tid < N ) // Make sure we don't...
22,304
#include <stdio.h> #include <stdlib.h> #include <float.h> #include <math.h> #include <cuda.h> #include <curand.h> // Type for points typedef struct{ float x; // x coordinate float y; // y coordinate int cluster; // cluster this point belongs to } Point; // Type for centroids typedef struct{ floa...
22,305
/* Finds: TLB misses For the Tesla V100-SXM2-16GB's TLB Soure code based on paper https://arxiv.org/pdf/1509.02308.pdf */ #include <stdio.h> #include <stdint.h> #include "cuda_runtime.h" #define LEN 256 __global__ void ...
22,306
#include <inttypes.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" /* Kernel for use with ManagedCuda */ __global__ void kernel(uint16_t *c, int xsize, double y_scale, double y_base, double x_scale, double x_base, int max) { int idx_x = blockDim.x * blockIdx.x + threadIdx.x; int idx_y = blockDi...
22,307
/********************************************************************* * Copyright © 2011-2012, * Marwan Abdellah: <abdellah.marwan@gmail.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software ...
22,308
/* Program to demonstrate time taken by function fun() */ #include <stdio.h> #include <time.h> // A function that terminates when enter key is pressed void fun() { printf("fun() starts \n"); printf("Press enter to stop fun \n"); while(1) { if (getchar()) break; } printf("f...
22,309
#include <stdio.h> #include <stdlib.h> #include <math.h> namespace cudakernel { __global__ void stepLIF(float* voltages, float* spike_trains, int* refractory_buffer, float* in_currents, float* weights_in, ...
22,310
#include <iostream> #include <string.h> #include <cstdlib> #include <stdlib.h> #include <stdio.h> #include <iomanip> #include <fstream> #include <sstream> #include <list> #include <utility> #include <math.h> #include <limits> #include <ctime> #define N 20000 using namespace std; __global__ void reduce(int *g_idata, ...
22,311
__global__ void update_e( int Ntot, int Nz, int Nyz, int c1, int c2, float *Ex, float *Ey, float *Ez, float *Hx, float *Hy, float *Hz, float *CEx, float *CEy, float *CEz ) { int tk = threadIdx.x; int idx = blockIdx.x*blockDim.x + tk; int fidx = idx + idx/c1*Nz + c2; extern __shared__ float hs[]; float* hx = (flo...
22,312
#include "includes.h" __global__ void multi(int *a, int *b, int *c,int n) { int suma = 0; int row = blockIdx.y * blockDim.y + threadIdx.y ; int col = blockIdx.x * blockDim.x + threadIdx.x ; if (row <n && col<n){ for(int i=0;i<N;++i){ suma+= a[row*n+i] * b[i*n+col]; } } c[row*n+col] = suma; }
22,313
#include "cuda.h" typedef long long int64; __global__ void Init(double *out, const double *in, int size){ int i = blockIdx.x*blockDim.x + threadIdx.x; if(i<size) out[i] = in[i]; } __global__ void Zero(double *out, int size){ int i = blockIdx.x*blockDim.x + threadIdx.x; if(i<size) out[i] = 0.0; } __global__ vo...
22,314
#include "includes.h" __global__ void SigmoidBackKernel(float* Z, float* dZ, int size){ int id = blockIdx.x * blockDim.x + threadIdx.x; if(id < size){ float t = Z[id]; dZ[id] = dZ[id] * t * (1-t) ; } }
22,315
#include "includes.h" __global__ void __fillToInds3D(double A, double *B, int ldb, int rdb, int *I, int nrows, int *J, int ncols, int *K, int nk) { int ii = threadIdx.x + blockDim.x * blockIdx.x; int jj = threadIdx.y + blockDim.y * blockIdx.y; int kk = threadIdx.z + blockDim.z * blockIdx.z; int i, j, k, mapi, mapj, map...
22,316
#include <stdio.h> #include <stdlib.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #define BLOCK_DIM 16 __global__ void transpose(float *odata, float *idata, int width, int height) { __shared__ float block[BLOCK_DIM][BLOCK_DIM+1]; unsigned int xIndex = blockIdx.x * BLOCK_DIM + threadIdx.x; uns...
22,317
//Nathanael Grix //Hw5 Cuda Core Benchmark: //Purpose: Compare cpu and gpu execution time to sum large arrays of numbers on // Penn State's computing cluster. I will compare the exectution time from // sets of 1 to 200,000,000. #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define B 1024 //unused impl...
22,318
#include <cuda_runtime.h> #include <stdio.h> /*** __shared__ 通过共享内存来完成线程间的通信 这一段代码 通过共享内存 ***/ cudaError_t addWithCuda(int *c, const int *a, size_t size); __global__ void addKernel(int *c, const int *a){ int i = threadIdx.x; extern __shared__ int seme []; //声明一个全局的 共享内存的变量 seme[i] = a[i]; __syncthre...
22,319
/* ** Projeto de Algoritmos Paralelos ** Ola Mundo */ #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda_profiler_api.h> __global__ void cuda_olamundo(){ printf("Ola Mundo direto da GPU!\n"); } int main(int argc, const char * argv[]){ int count; cudaError_t erro...
22,320
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <cuda.h> #define BLOCK_SIZE 512 // __global__ void findmax(float * input, float * output, int len) { __shared__ float partialMax[BLOCK_SIZE]; unsigned int t = threadIdx.x; unsigned int start = blockI...
22,321
#include <iostream> #define numBlocks 512 #define numThreads 1024 using namespace std; __global__ void addVectors(int blockSize, int totalSize, int * a, int * b, int * dest) { int idxBlock = blockIdx.x; int idx = blockIdx.x * blockSize + threadIdx.x; while (idx < (idxBlock+1)*blockSize && idx < totalSiz...
22,322
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<cuda.h> #include<cuda_runtime.h> namespace placeholder { class Data { public: int InputSize(void) { FILE *input = NULL; input = fopen("input.txt", "r"); char line[30]; int N = 0; while(fgets(line, 30, in...
22,323
#include <iostream> using namespace std; long layer_sizes[] = {56l * 56 * 96, 28l * 28 * 96, 27l * 27 * 256, 13l * 13 * 256, 13l * 12 * 384, 13l * 12 * 384, 13l * 13 * 256, 6l * 6 * 256}; int num_layers = 8; int main() { cudaEvent_t start, stop; cudaEventCreate(&star...
22,324
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/sort.h> #include <thrust/random.h> #include <iostream> #include <iomanip> #include <ctime> #include <fstream> #include <string> void print(const thrust::device_vector<int>& v) { for(size_t i = 0; i < v.size(); i++) std::cout << " ...
22,325
/** * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. * * Please refer to the NVIDIA end user license agreement (EULA) associated * with this source code for terms and conditions that govern your use of * this software. Any use, reproduction, disclosure, or distribution of * this software and relate...
22,326
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> #define DEBUG void initializeMatrix(int *matrix, int rows, int cols); void printMatrix(int *matrix, int rows, int cols); __global__ void matrixSumGpu(int *a, int *b, int *c, int rows, int cols); int main() { int...
22,327
#include "includes.h" __global__ void extractValues(void* fb, int* voxels, int num_voxels, int* values) { int index = blockIdx.x * blockDim.x + threadIdx.x; if (index < num_voxels) { //TODO: Make this support other storage_type's besides int32 float* tile = (float*)fb; values[index] = __float_as_int(tile[voxels[index]...
22,328
#include "kernel.cuh" #include <stdio.h> __global__ void firstKernel(void) { printf("Hello I'm thread in block: %d\n", blockIdx.x); } void runKernel() { getDeviceProperties(); firstKernel << <16, 1 >> > (); } void getDeviceProperties() { int device_count = 0; cudaGetDeviceCount(&device_count); ...
22,329
#include <stdio.h> #include <iostream> #define M 32 #define N 64 #define BLOCK_DIM 32 __global__ void matrixTranspose(int *d_a, int *d_out, int nRows, int nCols){ // Mapping from 2D block grid to absolute 2D locations on C matrix int row = blockDim.y * blockIdx.y + threadIdx.y; int col = blockDim.x * bl...
22,330
#include <stdio.h> #include <cuda.h> #define ARRAY_SIZE 64 __global__ void SquareKernel(float *d_out, float *d_in) { int idx = blockIdx.x * blockDim.x + threadIdx.x; float val = d_in[idx]; d_out[idx] = val * val; } int main() { const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float); // Allocate the array on the h...
22,331
#include <algorithm> namespace kernels { __global__ void diffusion_interior(double *x0, double *x1, int nx, int ny, double dt) { auto i = threadIdx.x + blockDim.x*blockIdx.x; auto j = threadIdx.y + blockDim.y*blockIdx.y+1; if(i<nx && j<ny-1) { auto pos = (j+1)*(nx+2) + i + ...
22,332
#include "includes.h" __global__ void reduceNeighboredLess(int *g_idata, int *g_odata, unsigned int n){ unsigned int tid = threadIdx.x; unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; int *idata = g_idata + blockIdx.x * blockDim.x; if(idx >= n) return; for(int stride = 1; stride < blockDim.x; stride <<= 1)...
22,333
/* We consider 1024 map, which are initially constructed with (at most)size = 1024 key, value pairs, for which keys are integers and values are float point numbers. Then each of them processes 262,144 operations. The operations include: 'i': insert a key-value pair, or modify the original value. (if the map is ful...
22,334
float h_A[]= { 0.6231129915441065, 0.6159796536213568, 0.7516223300466565, 0.5614399174950864, 0.7806484910812693, 0.6231672425083965, 0.9403363360562412, 0.6721354421249044, 0.9066093680806764, 0.8975730352955702, 0.5148014596757533, 0.7417318092438872, 0.7395976420984723, 0.7838657534425599, 0.7958196527715926, 0.937...
22,335
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #include <cuda_runtime_api.h> // We have to include cuFFT library #include <cufft.h> #define NX 256 #define BATCH 1 // cuFFT can do 1D, 2D and 3D Fourier transformations using fast Fourier transform (FFT) algorithm. // cuFFT is also ...
22,336
#include <stdlib.h> #include <sys/time.h> #include <stdio.h> #include <string.h> #include <time.h> #include <math.h> #include <cuda.h> __device__ int endLoop=0; __device__ __host__ int get_keypair(char* tab, int length, int first_char, int last_char){ int sum=0; int pow=1; int i=0; for(i=0; i<length; i++){ ...
22,337
#include <iostream> #include <math.h> #include <time.h> #include <stdlib.h> #include <random> #include <vector> #include <chrono> #include <deque> #include <algorithm> #include <iterator> #include <curand.h> #include <curand_kernel.h> #define BLOCK_SIZE 1024 __global__ void partition(int *arr, int *bit_arr, int *l, i...
22,338
#include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #define DATATYPE int #define MEMSIZE 1024 #define REP 128 #define conflictnum 1 __constant__ int d_array_m1[MEMSIZE]; __constant__ int d_array_m2[MEMSIZE]; __global__ void constant_broadcast(double *time,DATATYPE *out,int its) { DATATYPE p,q=(threadIdx....
22,339
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #include <stdbool.h> #include <sys/time.h> double getTimeStamp() { struct timeval tv; gettimeofday( &tv, NULL ); return (double) tv.tv_usec/1000000 + tv.tv_sec; } void h_addmat(float*A, float*B, float*C, int nx, int ny) { int total ...
22,340
#include "includes.h" __global__ void myhistKernel(unsigned char * buffer,unsigned int * histo) { __shared__ unsigned int temp[256]; int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; int offset = x + y * blockDim.x * gridDim.x; temp[threadIdx.x]=0; __syncthreads(); atomicA...
22,341
#include "includes.h" __global__ void calculoAlgoritmoTroca(float *dev_matrizSuperior, int linhaPerm, int colunaPerm, int totalColunas, int totalLinhas) { int i = blockDim.x * blockIdx.x + threadIdx.x; float fatorAnulador = 0.0; //evitar operação em endereço invalido //se for indice da linha permissivel, desconsider...
22,342
#include <iostream> #define THREAD_PER_BLOCK 1024.0 #define CUDAMALLOC_ERROR(_err) \ do { \ if (_err != cudaSuccess) { \ printf("%s in %s at line %d\n", cudaGetErrorString(_err),__FILE__,__LINE__); \ exit(EXIT_FAILURE); \ } ...
22,343
// // Created by gxl on 2021/3/29. // #include "TimeRecord.cuh"
22,344
/** * jrc_cuda_delta.cu * block loading delta calculation. should be much faster * system('nvcc -ptx -m 64 -arch sm_35 jrc_cuda_rho.cu') * iA is multiple of CHUNKSIZE (16) * J. James Jun, Vidrio Technologies, LLC., 2017 Jun 11 */ #include <cuda_runtime.h> #include <math.h> #define ABS(my_val) ((my_val) < 0) ? (-1...
22,345
/************************************************************************* > File Name: 05_0304.cu > Author: dong xu > Mail: gwmxyd@163.com > Created Time: 2016年03月30日 星期三 13时37分15秒 ************************************************************************/ #include <stdio.h> #include <cuda_runtime.h> cudaError_t...
22,346
#include "includes.h" __global__ void scale( float *a, int size, int c) { int index=c,k=0;//size=b for(k=index+1;k<size;k++) { a[size*index + k] = (float) a[size*index + k] / a[size*index + index]; } }
22,347
//seqBig.cu #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=1000000; // task 1: create the array thrust::device_vector<int> a(N); // task 2: fill the array thrust...
22,348
#pragma once #include <cuda.h> #include <cuda_runtime_api.h> __global__ void kernelApply3x3MatrixOnImage(unsigned int* input, unsigned int* output, unsigned int* mat, unsigned int width, unsigned int height) { unsigned int x = blockIdx.x * blockDim.x + threadIdx.x; unsigned int y = blockIdx.y * blockDim.y + threadId...
22,349
#include<cuda_runtime.h> #include "kernel.cu" #include<iostream> #include<chrono> #include<vector> #include<string.h> #include "helper.cu" using namespace std; using namespace std::chrono; void index(float* input, int inputSize, int inputDim, // scale of input float* projections, int tableNums, int hashSize, ...
22,350
/* sparse_matrix.cu: Cuda implementation Sparse Matrix Multiplication by Vector compile & run: nvcc sparse_matrix.cu -o sparse_matrix.sh -lm && ./sparse_matrix.sh 32768 256 256 1 input: NNZ: None Zero Values ROWS: The number of Rows (max 1024) COLS: The number of Columns (max 1024) DEBUG: 1 to debug, 0 to no-...
22,351
#include <stdlib.h> #include <stdio.h> #include <curand.h> #include <time.h> #include <iostream> #include <string> #include <fstream> using namespace std; #define CURAND_CALL(x) do { if((x)!=CURAND_STATUS_SUCCESS) { \ printf("Error at %s:%d\n",__FILE__,__LINE__);\ return EXIT_FAILURE;}} while(0) int main(in...
22,352
#include <stdio.h> #include <random> #include <time.h> #define ARRAY_SIZE 100000000 #define THREADS 256 #define RANDOM_MAX 100000 __global__ void saxpy_kernal(float *x, float *y, const float a, int length) { const int id = threadIdx.x + blockIdx.x * blockDim.x; if (id >= length) return; y[id] = x[id] * a + y[id];...
22,353
#include <stdio.h> #include <cuda.h> #include <cuda_runtime.h> #define LOG_DEBUG if(0) #define LOG_INPUT if(0) #define LOG_OUTPUT if(0) __global__ void sumTriangle(float* M, float* V, int N); __global__ void sumTriangleWithAtomics(float* M, float* V, int N); __global__ void sumTriangle(float* M, float* V, int N){ ...
22,354
#include "includes.h" #define SIZ 20 #define num_inp 4 using namespace std; typedef struct edge { int first, second; } edges; __global__ void bfs(const edge *edges, int *vertices, int current_depth) { int a = blockDim.x * blockIdx.x + threadIdx.x; int vfirst = edges[a].first; int dfirst = vertices[vfirst]; in...
22,355
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <cuda.h> #include <cuda_profiler_api.h> #include <curand.h> #include <curand_kernel.h> #define MAX 9 int ROWS = 9; int COLUMNS = 9; char* FILENAME; void printGridToFile(int* board); void startSeq(char* name); int main ( int argc, ...
22,356
#include <cstdio> #include <cstdlib> #include <iostream> #include <ctime> using namespace std; #define blockSize 32 #define DIM 1000 __device__ __managed__ float A[DIM][DIM], B[DIM][DIM], C[DIM][DIM]; void init() { srand48(5L); for (int i=0; i<DIM; i++) for (int j=0; j<DIM; j++) { A[i][j] = drand48()...
22,357
#include <stdio.h> #include <cuda_runtime.h> #include <math.h> #include <time.h> static double a = 1.0E-10; void FillMatrix(double *matrixA, double *matrixB, int size); void OpenFile(int *N); void SaveFile(struct tm *start, struct tm *end, double error, double elapsed, int N); __global__ void Multiply(double* A, dou...
22,358
#include <stdio.h> #include <iostream> #include <curand.h> #include <curand_kernel.h> #define N 16 const int blocksize = 4; __global__ void init_random(curandState_t *state) { int idx = threadIdx.x + blockDim.x * blockIdx.x; curand_init(0,idx,0,&state[idx]); } __global__ void generate_random(curandState_t *s...
22,359
// Author: Sudnya Padalikar // Date: 01/23/2014 // Brief: simple matrix multiplication kernel in cuda #include <stdio.h> #include <cassert> #include <iostream> // Kernel that executes on the CUDA device __global__ void matrixMultiply(float * A, float * B, float * C, int numARows, int numAColumns, ...
22,360
// // $ nvcc add.cu -o add_cuda // $ ./add_cuda // Max error: 0.000000 // #include <cuda_runtime.h> #include <iostream> #include <math.h> using namespace std; // Kernel function to add the elements of two arrays __global__ void add(int n, float *x, float *y, float *z, int batch_size) { int i = blockDim.x * blockId...
22,361
#include <stdio.h> __global__ void helloFromGPU(void) { // The qualifier __global__ tells the compiler // that the function will be called from the CPU and executed on the GPU. printf("Hello World from GPU from thread %d\n", threadIdx.x); } int main(void) { printf("Hello Wor...
22,362
#include "includes.h" __global__ void kCopy(float* srcStart, float* destStart, unsigned int copyWidth, unsigned int jumpWidth, unsigned int numElements) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < numElements) destStart[(idx / copyWidth) * jumpWidth + idx % copyWidth] = srcStart[(idx / co...
22,363
/***************************************************************************//** * \file calculateForce.cu * \author Christopher Minar (minarc@oregonstate.edu) * \brief */ #include "calculateForce.h" namespace kernels { __global__//kernel should be of size totalPoints void force_pressure(double *force_pressure, d...
22,364
#include <stdio.h> #define imin(a,b) (a<b?a:b) const int threadsPerBlock = 256; __global__ void gpu_partial_dot_product( double *a, double *b, double *c, int N) { __shared__ double cache[threadsPerBlock]; int tid = threadIdx.x + blockIdx.x * blockDim.x; int cacheIndex = threadIdx.x; double temp = ...
22,365
#include "includes.h" __global__ void vecadd( int * v0, int * v1, std::size_t size ) { auto tid = blockIdx.x * blockDim.x + threadIdx.x; if( tid < size ) { v0[ tid ] += v1[ tid ]; } }
22,366
extern "C" __global__ void bhsm_forward_backward( const float *x, const float *w, const int *ts, const int *paths, const float *codes, const int *begins, const int n_in, const int max_len, const int n_ex, float *ls, float *gx, float *gW ) { int i = blockIdx.x * blockDim.x + threa...
22,367
/* * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. * * NVIDIA Corporation and its licensors retain all intellectual property and * proprietary rights in and to this software and related documentation. * Any use, reproduction, disclosure, or distribution of this software * and related documentat...
22,368
#include "includes.h" __global__ void LSTMDeltaKernelBPTT( float* deltas, float* cellStates, float* previousCellStates, float* cellStateErrors, float* nextCellStateErrors, float* outputGateDeltas, float* forgetGateDeltas, float* nextForgetGateDeltas, float* inputGateDeltas, float* nextInputGateDeltas, float* cellInput...
22,369
#ifndef _LIST_CU_CUDA #define _LIST_CU_CUDA template <typename T> struct Node { T data; Node *next; }; template <typename T> class List { private: Node<T> *head; int count = 0; public: __device__ __host__ List() { head = NULL; } __device__ __host__ bool isEmpty() { return (count == 0); } __device__ __...
22,370
// Babak Poursartip // 02/6/2021 // CUDA //topic: gather // y = f(a_m, b_n, ... ) // black scholes (option price) #define _USE_MATH_DEFINES #include "cstdio" #include "curand.h" #include <math.h> // ==================================== __device__ __host__ __inline__ float N(float x) { return 0.5+0.5*erf(x* M_S...
22,371
#include <stdio.h> #include <assert.h> #include <cuda.h> // taken from Dr.Dobbs // http://www.ddj.com/cpp/207200659 // the next line was changed from // void cudaCompute(void) // to // extern "C" void cudaCompute(void) extern "C" void cudaCompute(void) { float *a_h, *b_h; // pointers to host memory float ...
22,372
extern "C"{ void matmult_kmn(int m, int n, int k, double *A, double *B, double *C) { int i1, i2,i3; for(i1 = 0; i1< m; i1++){ for(i2 = 0; i2 < n; i2++){ C[i1*n+i2]=0; } } for(i3=0; i3<k; i3++){ for(i1=0; i1<m; i1++){ for(i2 = 0; i2 < n; i2++){ C[i1*n+i2]+...
22,373
// nvidia_properties.cu // // Fred J. Frigo // 07-Oct-2021 // // // See CUDA by Example, J Sanders & E Kandrot, p 33 // // To compile: nvcc nvidia_properties.cu -o nvidia_props // #include <stdio.h> #include <unistd.h> #include <err.h> #include <stdint.h> // you must first call the cudaGetDeviceProperties() fu...
22,374
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #define MAX_ERR 1e-6 //__global__ void vector_add(float *out, float *a, float *b, int n) { // int stride = 1; // int tid = blockIdx.x * blockDim.x + threadIdx.x; // 0 * 2...
22,375
#include <cuda.h> #include <cuda_runtime.h> #include <stdlib.h> #include <stdio.h> __global__ void vector_add(int *out, int *a, int *b, int n){ int index = threadIdx.x; int stride = blockDim.x; for (int i = index; i < n; i+=stride) { out[i] = a[i] + b[i]; } } int main() { int n = 10; ...
22,376
#include <stdio.h> #include <cuda_runtime.h> #define DATA_TYPE int #define ARRAY_SIZE 32 __global__ void copy_kernel(DATA_TYPE *d_a, DATA_TYPE *d_b) { int i; i = threadIdx.x; d_b[i] = d_a[i]; } int main(int argc, char* argv[]) { cudaError_t err = cudaSuccess; DATA_TYPE* h_a = NULL; DATA_TYPE* h_b = N...
22,377
// Joshua Donnoe, Kyle Evens, and Dominik Haeflinger #include <stdlib.h> #include <stdio.h> #include <cuda.h> #define NUM_THREADS 256
22,378
#include <cuda_runtime.h> #include <stdio.h> __global__ void checkIndex(void) { printf("threadIdx:(%d,%d,%d) blockIdx:(%d,%d,%d) blockDim:(%d,%d,%d)\ gridDim(%d,%d,%d)\n",threadIdx.x,threadIdx.y,threadIdx.z, blockIdx.x,blockIdx.y,blockIdx.z,blockDim.x,blockDim.y,blockDim.z, gridDim.x,gridDim.y,gridDim.z); } int...
22,379
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <cuda.h> #define n 3 #define m 3 #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: ...
22,380
#include <iostream> #include <fstream> #include <chrono> __global__ void saxpy(int n, float a, float *x, float *y) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) y[i] = a * x[i] + y[i]; } using namespace std; using namespace chrono; #define CU_CHK(ERRORCODE) \ {cudaError_t error = ERRORCODE; \ ...
22,381
#include <cstdio> __global__ void init7(int* arr,size_t pitch,int n){ int idx=blockDim.x*blockIdx.x+threadIdx.x; int idy=blockDim.y*blockIdx.y+threadIdx.y; if(idx <n && idy<n){ int* row=(int*)( (char*)arr +idy*pitch); row[idx]=7; } } __host__ void printMtrx(int* const mtrx,const int n){ for(int i=0;i<n;i++){...
22,382
#include <stdio.h> #include <string.h> #include <stdlib.h> #define BLOCK_SIZE 16 __global__ void MultiMatrices(float *d_ma, float *d_mb, float *d_mp, int Width, int m, int n){ int Row = blockIdx.y*blockDim.y+threadIdx.y; int Col = blockIdx.x*blockDim.x+threadIdx.x; if ((Row < m) && (Col < n)) { ...
22,383
__global__ void ZerosToOnes(float* V, int M, int N, float eps) { /* Turn zeros into ones (for use when something goes in the denomenator) :param V: An MxN input matrix :param M, N: Dimensions :param eps: The value below which to consider things zero */ int i = blockIdx.x*blockDim.x + threadI...
22,384
#include<stdio.h> #include<iostream> #include<cuda.h> using namespace std; //Catch Cuda errors void catchCudaError(cudaError_t error){ if(error!=cudaSuccess) { printf("\n====== Cuda Error Code %i ======\n %s\n",error,cudaGetErrorString(error)); exit(-1); } } //================================...
22,385
#include <iostream> /* Ryan McDonald CSUF Spring 2021 CPSC 479 - Dr. Bein */ __global__ void setVal(int n, int* x) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; for (int i = index; i < n; i += stride) x[i]=0; } __global__ void addVal(int n, int* x){ int index = blockI...
22,386
/* multiplication table using CUDA code downloaded from http://blog.daum.net/heoly/7 $ nvcc -o multiplication multiplication.cu */ #include <stdio.h> #include <malloc.h> #include <cuda_runtime.h> #define BLOCK_SIZE 5 // upto 5+1 dan #define THREAD_SIZE 9 // Device code __global__ void test(int *result) { in...
22,387
#include <iostream> int main(void){ cudaDeviceProp prop; int count; cudaGetDeviceCount(&count); printf("Number of devices: %d\n", count); printf("\n"); for (int i=0; i<count; i++){ cudaGetDeviceProperties(&prop, i); printf("Information for device %d\n", i); printf("====...
22,388
#include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <math.h> using namespace std; // CUDA KERNEL FUNCTIONS __global__ void Hello(int *neighbours) { //int globalidx = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; int globa...
22,389
#include <cstdio> __global__ void VecAddKernel(float* dA, float* dB, float* dC) { int i = threadIdx.x; dC[i] = dA[i] + dB[i]; } void VecAdd( const float* pA, const float* pB, float *pC, int vectorSize) { size_t vectorMemSize = vectorSize * sizeof(float); // Allocate float* dA; cudaMalloc( &dA, vectorMemSize ); ...
22,390
//nvcc -o gol gol.cu #define NEPOCHS 1000 #define DIMENSIONX 100 #define DIMENSIONY 100 #include <stdio.h> #include <cstdlib> #include <iostream> #include <fstream> __global__ void Evolve(bool *u, int n, int dx, int dy) { int n_next = n + 1; bool active_pre, active_post; __shared__ bool shared_u[DIM...
22,391
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #define CUDA_ERROR_EXIT(str) do{\ cudaError err = cudaGetLastError();\ if( err != cudaSuccess){\ printf("Cuda Error: '%s' for %s\n", cudaGetErro...
22,392
#include "includes.h" __global__ void cudaSPadding_kernel( unsigned int nbOutputs, unsigned int outputWidth, unsigned int outputHeight, unsigned int nbChannels, unsigned int batchSize, unsigned int inputWidth, unsigned int inputHeight, int leftPad, int rightPad, int topPad, int botPad, const float* input, float* output...
22,393
//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) { atomicCAS(A,2,11); atomicCAS(B,5,1); atomicCAS(C,7,3); }
22,394
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> //int main() //{ // int iDev = 0; // cudaDeviceProp iProp; // // cudaGetDeviceProperties(&iProp, iDev); // printf("Max threads per SM : %d \n", // iProp.maxThreadsPerMultiProcessor); // // return 0; //}
22,395
#include "merge_func.cuh" #include "cuda_runtime.h" #include "device_launch_parameters.h" __global__ void MergeRank(float * d_input, float * d_output) { int indexA = blockIdx.x * blockDim.x + threadIdx.x; int indexB = indexA + 2048; float temp1 = d_input[indexA]; float temp2 = d_input[indexB]; int indexAB = 204...
22,396
/* timing_of.c Calculates timing given struct rusage. $Id: timing_of.c,v 1.3 2002/07/12 20:48:49 eschrich Exp $ Steven Eschrich Copyright (C) 2002 University of South Florida This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public Licens...
22,397
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <string> #include <vector> #include <iostream> #include <fstream> #include <sstream> #include <random> #include <cmath> #include <ctime> #include <chrono> #define DEVICE 0 #define MAX_THREADS 6'000 #define RAND_CONST_1 61746235 #define RAND_CO...
22,398
#include <stdio.h> #include <cuda.h> /* Matrices are stored in row-major order: */ /* M(row, col) = (M.width*row +col); */ typedef struct{ /* suppose we use only square matrices */ int width; float *elements; } Matrix; /* Thread block size */ #define TILE_WIDTH 2 /***********************/ /* TODO, write...
22,399
#include <stdio.h> #include <stdlib.h> // Kernel to add two integers __global__ void add(int *a, int *b, int *c){ *c = *a + *b; } // Main program int main(void){ int *a,*b,*c; // Host copies int *a_dev,*b_dev,*c_dev; // Device copies int size = sizeof(int); // Allocate host m...
22,400
#include <cstdlib> #include <ctime> #include <random> #include <iostream> #include <cmath> #include <stdio.h> #include <iomanip> #include <chrono> #include <unistd.h> #include <map> using namespace std::chrono; using namespace std; #define N_THREADS_PER_BLOCK 1024 __device__ double atomicAddDouble(double* address, do...