serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
20,501
#include <bits/stdc++.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/transform.h> #include <thrust/reduce.h> #include <thrust/copy.h> #include <thrust/functional.h> //#include "inner.hpp" #define t_copy(x, y) thrust::copy((x).begin(), (x).end(), (y).begin()) #define t_tran_u(x, z...
20,502
#include <sys/time.h> #include <stdio.h> #include <math.h> //TODO for writing to file, will be deleted #include <stdlib.h> //TODO: could include later //#include <device_launch_parameters.h> #include <cuda_runtime.h> //#include "../inc/helper_cuda.h" #define GRID_YDIM 65535 // time stamp function in seconds double get...
20,503
#include <stdio.h> __global__ void thread_per(int* a, int * b, int *c, int* alpha) { int index = threadIdx.x + blockIdx.x * blockDim.x; c[index] = *alpha * a[index] + b[index]; } void thread_per_block(int count) { int *a = (int*) malloc(sizeof(int) * count); int *b = (int*) malloc(sizeof(int) * count); int *c ...
20,504
/* number of mathematical operations (only floating point) operation flo/o total +-* : 27 1 27 / : 2 4 8 pow : 1 13 13 sum 48 */ #define M2L_KERNEL_CORE \ for(i=0;i<3;i++) nc[i]=0;\ nb=je-1;\ k=0;\ i=1;\ while(nb!=0){\ j...
20,505
#include "ops-builder.hh" #include <stdexcept> #include "graph.hh" #include "add.hh" #include "adam-update.hh" #include "argmax-accuracy.hh" #include "input.hh" #include "leaky-relu-grad.hh" #include "log-softmax.hh" #include "mat-mat-mul.hh" #include "mat-mul-add.hh" #include "mat-rvect-add.hh" #include "mat-sum.hh"...
20,506
#include "includes.h" namespace ann { // CUDA2 } __global__ void kernel_weight_update( int layer_id, int *l, int *s, int *sw, float *z_arr, float *a_arr, float *t_arr, float *gjl, float *w_arr, float *dw_arr, float eta, float alpha ){ volatile int idx = threadIdx.x + blockDim.x*blockIdx.x; int neuron_c...
20,507
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #define BLOCK_X 10 #define BLOCK_Y 1 #define BLOCK_Z 1 #define THREAD_X 360 #define THREAD_Y 1 #define THREAD_Z 1 #define N 3600 #define PI 3.14159265358979323846 #define DEG_TO_RAD(deg) ((deg) / 180.0 * (PI)) __global__ void cosine10_1_3...
20,508
/* CUDA timing example To compile: nvcc -o testprog2 testprog2.cu */ #include <iostream> #include <cuda.h> // Kernel that executes on the CUDA device. This is executed by ONE // stream processor __global__ void vec_add(float* A, float* B, float* C, int N) { // What element of the array does this thread work o...
20,509
#include <iostream> #include <math.h> #include <algorithm> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/adjacent_difference.h> #include <thrust/generate.h> #include <thrust/unique.h> #include <thrust/scan.h> #include <thrust/transform_reduce.h> #include <th...
20,510
/* * Created by Marcos Luciano * https://www.github.com/marcoslucianops */ #include <stdint.h> inline __device__ float sigmoidGPU(const float& x) { return 1.0f / (1.0f + __expf(-x)); } __global__ void gpuYoloLayer(const float* input, float* boxes, float* scores, float* classes, const uint netWidth, const uint...
20,511
#include <iostream> #include <stdio.h> #include <cmath> #include <math.h> #include <cstdlib> #include <ctime> #include <fstream> #include <cstring> #include <string> #include <algorithm> #include <random> #include <numeric> #include <time.h> #include <curand.h> #include <curand_kernel.h> //bacteria surface geometry, f...
20,512
#include <stdio.h> #include <stdlib.h> __global__ void shiftArray(unsigned* a, unsigned size) { int tid = blockDim.x * blockIdx.x + threadIdx.x; while (tid < size) { a[tid] = a[(tid + 1) % size]; tid += blockDim.x; } } int main() { unsigned size = 100, i; unsigned size_in_byte = si...
20,513
#include <stdlib.h> #include <assert.h> #include <stdio.h> #define BLOCKSIZE 16 __global__ void Cuda_Mult(int *d_a, int *d_b, int *d_res, int n){ // dot product of two matrices __shared__ int T1[BLOCKSIZE][BLOCKSIZE]; __shared__ int T2[BLOCKSIZE][BLOCKSIZE]; int R = blockIdx.y * BLOCKSIZE + threadId...
20,514
#include <iostream> #include <math.h> #include <cstdlib> #include <sys/time.h> #include <math.h> #include <stdio.h> #include <cuda_runtime.h> // #include <stdio.h> // #include <math.h> // #include <stdlib.h> // #include <time.h> #include <string.h> #include <stdbool.h> int nNodes; short int* graph; void write(FILE *...
20,515
#include <iostream> #include <chrono> #include <time.h> #include <algorithm> #include <math.h> #define eChk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { fprintf(stderr,"GPUassert: %s %s %d\n", c...
20,516
#include "includes.h" __device__ void applyRule(char* left, char* middle, char* right, char* res){ char a = *left; char b = *middle; char c = *right; if(a == 0 && b == 0 && c == 0){ *res = 0; }else if(a == 0 && b == 0 && c == 1){ *res = 1; }else if(a == 0 && b == 1 && c == 0){ *res = 1; }else if(a == 0 && b == 1 && c ...
20,517
#include <cuda.h> #include <cuda_runtime.h> #include <unistd.h> #include <future> #include <mutex> #include <stdio.h> // This works fine with a mutex, but crashes with a sigbus error when not using a mutex // #define USE_MUTEX #ifdef USE_MUTEX std::mutex m; #endif __global__ void testKernel() { printf("Thread Kerne...
20,518
#include "includes.h" //Number of elements of the inpu layers, that correspond to the number of pixels of a picture #define PIXELS 3073 //Number of elements of the first hidden layer #define HIDDEN_LAYER_1 2000 //Number of elements of the second hidden layer #define HIDDEN_LAYER_2 450 //Number of elements of the outpu...
20,519
#include "includes.h" __global__ void total(float *input, float *output, int len){ __shared__ float partialSum[2*BLOCK_SIZE]; unsigned int t=threadIdx.x,start=2*blockIdx.x*BLOCK_SIZE; if(start+t<len) partialSum[t] = input[start+t]; else partialSum[t]=0; __syncthreads(); if(start+BLOCK_SIZE+t<len)partialSum[BLOCK_SIZE...
20,520
#include <cstdlib> #include <stdio.h> #include <cassert> #include <cuda_runtime.h> /* Naive implementation. Allocate one thread for one element in result matrix, processing dot(Arow, Bcol); */ __global__ void kMatrixMul0 (float *d_res, float *d_mat1, int m1, int m2, ...
20,521
#include "includes.h" __global__ void BaseNeuronGetFloatArray(float *arr1, float *arr2, int n_elem, int step1, int step2) { int array_idx = threadIdx.x + blockIdx.x * blockDim.x; if (array_idx<n_elem) { arr2[array_idx*step2] = arr1[array_idx*step1]; } }
20,522
//pass //--gridDim=1 --blockDim=2 --only-divergence __device__ unsigned int x = 0; __global__ void f() { atomicInc(&x, 1); }
20,523
#include <iostream> #include <cuda_runtime.h> #include<cmath> const double NEWTON_G = 6.67384e-11; const double SOFTENING = 1e-9f; __constant__ double NEWTON_GG = 6.67384e-11; __constant__ double SOFTENINGG = 1e-9f; void writeSoA(double** f, int B, int size, const char *filename){ FILE* file; file=fopen(file...
20,524
#include <stdio.h> #include <fstream> #include <iostream> #include <stdlib.h> #include "vector" #include <sstream> #include <string> using namespace std; #define STD_TEST true using namespace std; __global__ void befriend_adjacents(int* adj_lists, int* sizes, int* labels, int* changed) { int id = threadIdx.x; ...
20,525
#include "Renderer.cuh" #include "MathOps.cuh" #include "cuda.h" #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __device__ void cuLight() { } __device__ void cuRefraction() { } __device__ void cuReflection() { } __device__ void cuIntersection() { } __device__ unsigned in...
20,526
#include <thrust/device_vector.h> #include <thrust/extrema.h> #include <cmath> #include <time.h> #include <iostream> #define CSC(call) \ do { \ cudaError_t res = call; \ if (res != cudaSuccess) { \ fprintf(stderr, "ERROR: file:%s line:%d message:%s\n", \ __FILE__, __LINE__, cudaGetErrorString(res)); \ exit(...
20,527
#include <iostream> #include <chrono> #include <stdio.h> #include <math.h> #include <chrono> struct Source{ double x; double y; double z; }; // Since sm35 is the targeted platform, and doesn't have float64 atomicAdd implemented, // We need a custom atomicAdd function __device__ double atomicAdd_sm35(doub...
20,528
#include "cuda_runtime.h" #include "device_launch_parameters.h" int main() { cudaError_t err; // Device number int deviceCount = 0; err = cudaGetDeviceCount(&deviceCount); if (err != cudaSuccess) return 1; /* CUDA 3.0 totalGlobalMem = 2GB sharedMemPerBlock = 49152 bytes regsPerBlock = 65536 warpSize = ...
20,529
#include "includes.h" __global__ void matrixMul(int *a, int *b, int *c, int n){ int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; int temp_sum = 0; if((row < n) && (col < n)){ for (int k = 0; k < n; k++){ temp_sum += a[row * n + k] * b[k * n + col]; } c[row * n + col] ...
20,530
#include <iostream> #include <cstdlib> #include <cuda_runtime.h> #include <cassert> #include <vector> #include <cstdio> #define BLOCOS 2 #define THREADS 4 #define REPETICOES 4 #define CHECK_ERROR(call) do { \ if( cudaSuccess != call) { ...
20,531
/* ============================================================================ Filename : algorithm.c Author : Your name goes here SCIPER : Your SCIPER number ============================================================================ */ #include <iostream> #include <iomanip> #include <sys/time.h> #incl...
20,532
#include <stdio.h> #include<sys/time.h> #include <pthread.h> #define MAX_INITIAL_WEIGHT 1000 #define MAX_INITIAL_RANGE 10000 #define MAX_INITIAL_VELOCITY 100 #define EPS 1e-9f #define BLOCK_DIM 32 #define G 100 // time stamp function in seconds double getTimeStamp() { struct timeval tv ; gettimeofday( &tv, NU...
20,533
#include <stdio.h> #include "cuda.h" #include "cuda_runtime.h" //////////////////////////////////////////////////////////////////////////////// // Cuda error checking //////////////////////////////////////////////////////////////////////////////// void SAFE_CALL(cudaError_t err){ if(err != cudaSuccess){ pr...
20,534
#include <iostream> #include <stdio.h> #include <stdlib.h> int main(void) { int num_bits = 16; int num_bytes = num_bits * sizeof(int); int* device_array = 0; int* host_array = 0; host_array = (int*) malloc(num_bytes); cudaMalloc((void**)&device_array, num_bytes); cudaMemset(device_a...
20,535
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #define OUTPUT_FILE_NAME_A "q2a.txt" #define OUTPUT_FILE_NAME_B "q2b.txt" #define OUTPUT_FILE_NAME_C "q2c.txt" #define NUM_THREADS_A 32 #define NUM_BLOCKS_A 2 #define NUM_THREADS_B 32 #define NUM_BLOCKS_B 2 // int* fileToArray(char file1[]...
20,536
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, float var_1,float var_2,float var_3,float var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,floa...
20,537
// REQUIRES: clang-driver // REQUIRES: x86-registered-target // REQUIRES: nvptx-registered-target // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \ // RUN: FileCheck %s --check-prefix=OK // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-ar...
20,538
#include <algorithm> #include <random> #include <iostream> #include <iomanip> #include <functional> constexpr int BLOCK_SIZE = 32; __global__ void matrix_mult(float* C, float* A, float* B, int size) { int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x; int ty = threadIdx.y; int i = by * blockDim.y ...
20,539
#include <vector> #include <stdio.h> #include <iostream> #include <cuda.h> #include<cuda_runtime.h> #include<device_launch_parameters.h> #define BLOCKSIZE_x 32 #define BLOCKSIZE_y 32 using namespace std; __device__ double eucludianDist(int Ax, int Ay, int Bx, int By) { double d = sqrt(pow((Ax - Bx), 2) + ...
20,540
#include "includes.h" __global__ void cudaUpdateFiringRate_kernel(unsigned int * firingRate, unsigned int * totalFiringRatePartial, unsigned int inputsDimX, unsigned int inputsDimY, unsigned int inputsDimZ) { const unsigned int inputSize = inputsDimZ * inputsDimX * inputsDimY; const unsigned int batchInputOffset = bl...
20,541
#include <stdio.h> #include <cuda.h> __global__ void matrixAddKernel(int *a,int *b, int *c, int N) { int col = threadIdx.x + blockDim.x * blockIdx.x; int row = threadIdx.y + blockDim.y * blockIdx.y; int index = row * N + col; if(col < N && row < N) { c[index] = a[index]+b[index]; } } ...
20,542
#include "includes.h" __global__ void shared1R8C1W1G1RG(float *A, float *B, float *C, const int N) { // compilador é esperto e aproveita o valor de i, mas faz 1W, 2 R nas outras posições da Shared __shared__ float Smem[512]; int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < N) { Smem[(threadIdx.x+1)%512] = A[i];...
20,543
#include "includes.h" #define BLOCK_SIZE 32 #define N 3200 __global__ void matMult(float* a, float* b, int n, float* c) { int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x; int ty = threadIdx.y; float sum = 0.0f; int ia = n * BLOCK_SIZE * by + n * ty; int ib = BLOCK_SIZE * bx + ...
20,544
const int NUM_DIMS = 4; template <typename T> __device__ void reduce(const int * const numVals, const void * const oldVals, void * const newVals) { T output = static_cast<T>(0); const int count = *numVals; const T * input = reinterpret_cast<const T * >(oldVals) + *numVals * blockIdx.x; for (int i = 0; i < coun...
20,545
#include "includes.h" #define num_thread 256 #define num_block 256 __global__ void blending_pairs(float *a,float *b,float *c,float *d,float *wei,int width,int height,int w,float A,float error_lm,float error_mm,int class_num) { const int tid=threadIdx.x; const int bid=blockIdx.x; const int Idx=num_thread*bid+tid; float ...
20,546
/************************************************ * MATRIX TRANSPOSE CHECK between parallel * and sequential programs. * * Usage: * Compile using nvcc -lcudart transpose.cu -o transpose * Run using ./mat <size of the matrix> * * Example: * ./mat 153 * The above will check whether for a random matrix, A = tr...
20,547
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #include <time.h> #include <stdio.h> #include "parann.cuh"; //Sigmoid function __device__ float sigmoid(float x) { return 1.0 / (1.0 + exp(-x)); } //Derivative of sigmoid function __device__ float d_sigmoid(float x) { return x * (1...
20,548
#include <stdio.h> #include <iostream> #include <fstream> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; float randomNumber(int max) { return (rand() % (max + 1 )); } struct vect { float x; float y; float z; }; struct vectProd { vect v1; vect ...
20,549
#include <cuda_runtime.h> #include <stdio.h> #define CHECK(call)\ {\ const cudaError_t error = call;\ if (error != cudaSuccess)\ {\ printf("Error %s, %s\n", __FILE__, __LINE__);\ printf("code: %s, reason: %s\n", error, cudaGetErrorString(error));\ exit(-10 * error);\ }\ }\ void init_data(int *inp, int n) { ...
20,550
#include <iostream> #include <stdio.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #include "cuComplex.h" #include <complex> using namespace std; #define N 8192 struct complexF{ float real; float imag; }; __global__ void addNums(cuFloatComplex *a, cuFloatComplex *b, cuFloatComplex *c) { int id...
20,551
float h_A[]= { 0.7414255370004672, 0.7334934052927213, 0.5741340217761788, 0.6971148962014382, 0.8059969085163883, 0.7909542016925057, 0.6352556255067705, 0.9601936377550603, 0.9856604348821778, 0.8144888851871118, 0.8733320072857484, 0.8134113562732539, 0.5511309378200807, 0.8170992303736243, 0.5453870685558884, 0.657...
20,552
#include <stdio.h> #include <math.h> #include <assert.h> #define epsilon (float) 1e-5 #define THREADxBLOCKalongXorY 16 typedef float DataType_t; // // Kernels // void MatrixMulOnHost(DataType_t* M, DataType_t* N, DataType_t* P, int Width) { int i, j, k; DataType_t pvalue; for (i = 0; i < Width; i++) ...
20,553
#include<bits/stdc++.h> #include<cuda.h> using namespace std; struct edge{ int u, v, c, f; }; // pushes flow along the edges adjacent to a vertex, concurrently for all vertices __global__ void push(int n, int* excess, int* excess_inc, int* prefix_deg, int* adj, int* height, int* new_height, edge* d_edges){ i...
20,554
#include "includes.h" __global__ void kern_NormLogBuffer(float* agreement, float* output, float maxOut, int size, short max) { int idx = CUDASTDOFFSET; float locAgreement = (float) agreement[idx]; float logValue = (locAgreement > 0.0f) ? log((float)max)-log(locAgreement): maxOut; logValue = (logValue > 0.0f) ? logValue...
20,555
#include "includes.h" __global__ void cuConvertRGBToHSVKernel(const float4* src, float4* dst, size_t stride, int width, int height, bool normalize) { const int x = blockIdx.x*blockDim.x + threadIdx.x; const int y = blockIdx.y*blockDim.y + threadIdx.y; int c = y*stride + x; if (x<width && y<height) { // Read float4 in ...
20,556
// Checks errors generated by passing a bad value for --cuda-gpu-arch. // REQUIRES: clang-driver // REQUIRES: x86-registered-target // REQUIRES: nvptx-registered-target // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=compute_20 -c %s 2>&1 \ // RUN: | FileCheck -check-prefix BAD %s // RUN: %clang -### -tar...
20,557
#include <thrust/device_vector.h> #include <stdio.h> #include <iostream> #include <time.h> #include <chrono> int main(int argc, char** argv){ int size = atoi(argv[1]); thrust::device_vector<int> test(size); thrust::fill(test.begin(), test.end(), 1); auto started = std::chrono::high_resolution_clock::now(...
20,558
#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,gr...
20,559
#include<stdio.h> #define NUM_BLOCKS 15 #define BLOCK_WIDTH 1 __global__ void hello() { printf("Hello world! I am a thread block %d\n", blockIdx.x); } int main(int argc, char **argv) { // Launch the kernal hello<<<NUM_BLOCKS, BLOCK_WIDTH>>>(); // force the printf()s to flush cudaDeviceSynchroniz...
20,560
#include "vscale.cuh" #include <cuda.h> #include <stdio.h> #include <random> #define NUM_THREADS 512 // another option is 16 based on the problem statement // reference code is: https://github.com/DanNegrut/ME759/blob/main/2021Spring/Assignments/general/timing.md int main(int argc, char *argv[]) { int n = atoi(argv[...
20,561
// hello.cu // // Fred J. Frigo // 01-Sep-2020 // // See section B19.4: // https://docs.nvidia.com/cuda/archive/9.1/pdf/CUDA_C_Programming_Guide.pdf` // // To compile: nvcc hello.cu -o hello // #include <stdio.h> __global__ void helloCUDA(float f) { printf("Hello thread %d, f=%f\n", threadIdx.x, f); } int...
20,562
#include <stdio.h> #include <time.h> #include <math.h> #include <float.h> #include "cuda.h" #include "cuda_runtime.h" #include "device_launch_parameters.h" const int blocksize = 800; const int N = 16; const int PROFILE_SIZE = 8376; const int PROFILE_ARRAY_SIZE = PROFILE_SIZE * 6; __device__ const int GPU_PROFILE...
20,563
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #define BLOCK_SIZE 16 #define CONVERGENCE_CHECK 1 __global__ void convoluteBlock(unsigned char *src, unsigned char *dst, int x, int y, int multiplier) { int x_dim = blockIdx.x * blockDim.x + threadIdx.x; int y_dim = blockIdx.y * bl...
20,564
#include "cuda_runtime.h" #include "stdio.h" int main(){ // define total data elements int nElem = 1024; // define grid and block structure dim3 block(1024); dim3 grid((nElem+block.x-1)/block.x); printf("grid.x: %d block.x %d \n", grid.x, block.x); // reset block block.x = 512; ...
20,565
#include<stdio.h> #include<iostream> #include<stdlib.h> #include<math.h> #include<cmath> #include "cuda_runtime.h" #include "device_launch_parameters.h" using namespace std; #define X 32 #define Y 32 #define X_IN 10 #define Y_IN 10 #define N ((X+1) * (Y+1)) #define TIME 10 double h_x = 0.2; double h_y = 0...
20,566
/*---------------------------------------------------------------*/ /* example 02 - Device Management */ /* Description : get properties of all visible device/GPU */ /* Version : 1.0 for CUDA 2.0 */ /* Compilation : ...
20,567
#include <iostream> #include <random> using namespace std; // Matrices are stored in row-major order: // M(row, column) = *(M.elements + row * M.stride + col) typedef struct { int width; int height; int stride; float * elements; } Matrix; // Thread block size #define BLOCK_SIZE 16 // Get a matrix element ...
20,568
#include <iostream> #include <cstddef> #include <vector> #include <random> #include <algorithm> #include <chrono> #define cudaErrorCheck(expr) \ do { \ cudaError_t err; ...
20,569
#include <stdio.h> __global__ void kernel(int *a) { int idx = blockIdx.x*blockDim.x + threadIdx.x; a[idx] = idx; } int main() { int dimx = 16; int num_bytes = dimx*sizeof(int); int *d_a=0, *h_a=0; int *s_a = 0; h_a = (int*)malloc(num_bytes); s_a = (int*)malloc(num_bytes); cudaMalloc...
20,570
//pass //--blockDim=1024 --gridDim=1 --warp-sync=16 --no-inline #include <cuda.h> __global__ void shuffle (int* A) { int tid = threadIdx.x; int warp = tid / 32; int* B = A + (warp*32); A[tid] = B[(tid + 1)%32]; }
20,571
//pass //--blockDim=32 --gridDim=1 #include <cuda.h> __global__ void test_Prog(int *A, int N) { const int tid = blockIdx.x*blockDim.x + threadIdx.x; for(int d = N/2; d > 0; d = d / 2) { int tmp=A[tid + d]; for (int i = 0; i < N; ++i) { int tmp2=A[tid]; int t2=tmp2; int t32=t2; if (tid < d) ...
20,572
//pass //--blockDim=32 --gridDim=1 #include <cuda.h> __global__ void test_Prog(int *A, int N) { const int tid = threadIdx.x; int tmp=A[tid+1]; tmp=tmp+11; A[tid]+=tmp; }
20,573
#include "includes.h" extern "C" __global__ void invertVectorElements(float* vector, int n) { int i = threadIdx.x; if (i < n) { vector[i] = 1.0f / vector[i]; } }
20,574
/* * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. * * NOTICE TO USER: * * This source code is subject to NVIDIA ownership rights under U.S. and * international Copyright laws. * * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE * CODE FOR ANY PURPOSE. IT IS PROVIDED...
20,575
#include<stdio.h> __global__ void hello_world(void) { printf("GPU: Hello world!\n"); } int main(int argc,char **argv) { printf("CPU: Hello world!\n"); hello_world<<<1,10>>>(); cudaDeviceReset();//if no this line ,it can not output hello world from gpu return 0; }
20,576
#include <stdlib.h> #include <cuda_runtime.h> #include <cufft.h> #include <stdio.h> #include <sys/time.h> #define INPUT_SIZE 5120 #define BATCH_SIZE 720 int main(){ struct timeval start, end; cudaError_t err; cufftResult res; double *idata = (double *)malloc(INPUT_SIZE * BATCH_SIZE * sizeof(double)); for(int i...
20,577
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,float var_2,float var_3,float var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13) { if ...
20,578
#include "matrix.cuh" matrix_list_t* matrix_list_constructor(unsigned int num) { matrix_list_t* list = (matrix_list_t*)malloc(sizeof(matrix_list_t)); list->num = num; list->matrix_list = (matrix_t**)malloc(sizeof(matrix_t*) * num); return list; } void free_matrix_list(matrix_list_t* m) { assert(m != NULL); int ...
20,579
/** * Global Memory (Linear Array) * Demonstrates: * - Allocation of linear array by host * - Passing global memory pointer to device * - Method in which host accesses global memory */ #include <stdio.h> #include <stdlib.h> void check_cuda_errors() { cudaError_t rc; rc = cudaGetLastError(); if (rc !=...
20,580
#include "vect-relu-leaky.hh" #include <cassert> #include <stdexcept> #include "ops-builder.hh" #include "leaky-relu-grad.hh" #include "graph.hh" #include "../runtime/node.hh" #include "../memory/alloc.hh" namespace ops { VectReluLeaky::VectReluLeaky(Op* arg, const dbl_t alpha) : Op("vect_relu_leaky", arg...
20,581
#include <stdio.h> #include <stdlib.h> void vecadd(int nx, float *a, float *b, float *c) { int i; for(i=0; i<nx; i++) c[i] = a[i] + b[i]; } __global__ void vecadd_gpu(int nx, float *a_gpu, float *b_gpu, float *c_gpu) { int i = blockIdx.x*blockDim.x + threadIdx.x; if(i<nx) c_gpu[i] = a_gpu[i] + b_gpu[i]; } int ...
20,582
#include <stdio.h> #include <cuda.h> #define N 64 __global__ void exscan() { __shared__ unsigned a[N]; //= {4, 3, 9, 3, 5, 7, 3, 2}; a[threadIdx.x] = threadIdx.x; __syncthreads(); unsigned n = sizeof(a) / sizeof (*a); __syncthreads(); if (threadIdx.x == 0) { for (unsigned ii = 0; ii < n; ++ii) printf("%d ...
20,583
#include "math.h" #define SMALLEST_FLOAT 1.175494351E-38 #define MAX_ELEMENTS_PER_BLOCK 2048 #define NUM_BANKS 32 #define LOG_NUM_BANKS 5 #ifdef ZERO_BANK_CONFLICTS #define CONFLICT_FREE_OFFSET(n)\ ((n) >> NUM_BANKS + (n) >> (2 * LOG_NUM_BANKS)) #else #define CONFLICT_FREE_OFFSET(n)((n) >> LOG_NUM_BANKS) #endif ext...
20,584
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,float var_2,float var_3,float var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float ...
20,585
#include <vector> #include <stdio.h> #include <iostream> #include <sstream> #include <string> #include <fstream> #include <math.h> #include <time.h> #include <sys/time.h> #define E_SIZE 100 #define H_SIZE 99 #define BLOCK 1024 //this program will assume a 98x98x98 grid with 2 cells of zero padding for the E fields ...
20,586
__global__ void _add_32_01(int n, float xi, float *y, float *z) { int i = threadIdx.x + blockIdx.x * blockDim.x; while (i < n) { float yi = y[i]; z[i] = xi+yi; i += blockDim.x * gridDim.x; } } #ifdef __cplusplus extern "C" { #endif void add_32_01(int n, float xi, float *y, float *z) { _add_32_01...
20,587
#include<stdio.h> #include<stdlib.h> typedef struct { unsigned char red,green,blue; } PPMPixel; typedef struct { int x, y; PPMPixel *data; } PPMImage; #define CREATOR "COMP3231" #define RGB_COMPONENT_COLOR 255 #define thread_x 10 #define thread_y 10 #define CUDA_CHECK(err) (cuda_checker(err, __FILE__...
20,588
//adding two arrays and storing the results in a third array using CUDA //(Unified Memory Construct) #include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> __global__ void add(int *a, int *b, int *c, int Num) { //global thread id int idx = threadIdx.x + blockIdx.x * blockDim.x; //checking bounds...
20,589
/* ============================================================================ Name : last.cu Author : christopher Version : Copyright : @ copyright notice Description : CUDA compute reciprocals ============================================================================ */ #include <iostrea...
20,590
#include <stdio.h> // 每个thread负责一个 C(i, j), 每个线程for循环次数是K // C(0, 0) A的第0行 乘 B的第0列 __global__ void matrixMultiply(float *A, float *B, float *C, int M, int K, int N) { float sum = 0.0f; // thread(row, col) is for C(i,j) int row = blockIdx.y * blockDim.y + threadIdx.y; // y is for row int col = block...
20,591
#include <cuda.h> #include <cuda_runtime_api.h> #define N_FLOPS_PER_THREAD 784 #define N_LOOPS 1 #define FLOPS_BLOCK \ reg0 = reg1 * reg2 + reg3; \ reg5 = reg6 * reg6; \ reg1 = reg2 * reg3 + reg4; \ reg6 = reg7 * reg7; \ reg2 = reg3 * reg4 + reg5; \ reg7 = reg0 * reg0; \ reg3 = reg4 *...
20,592
#include "gol_gpu.cuh"
20,593
/* Test Programm nach: https://www.thomas-krenn.com/de/wiki/CUDA_Programmierung */ #include<stdio.h> #include<cuda.h> #include<stdlib.h> // Vars // Host-Vars int* h_A; int* h_B; int* h_C; // Device-Vars int* d_A; int* d_B; int* d_C; // Prototypes void RandomInit(int* data, int n); int CheckResults(int* A, int* B...
20,594
#include "includes.h" __global__ void FullToCOO(int numElem, float* H_vals, double* hamilValues, int dim) { int i = threadIdx.x + blockDim.x*blockIdx.x; if (i < numElem) { hamilValues[i] = H_vals[i]; } }
20,595
#define BLOCK_WIDTH 32 #define BLOCK_HEIGHT 32 #define TILE_WIDTH 30 #define TILE_HEIGHT 30 #define NODATA -9999 #define FILTER_RADIUS 1 // -------------------------------------------------Neighbours access order is // 1 2 3 __constant__ int off_x[8] = {-1, 0, 1,1,1,0,-1,-1}; // 8 4 __constant__ int off_y[8] = ...
20,596
/* This is a demonstration file that shows how the prime test functions work. */ #include "primetest.cuh" #include <iostream> #include <random> #include <chrono> int main() { // Initialize RNG. auto seed = std::chrono::system_clock::now().time_since_epoch().count(); std::mt19937 generator(seed); std::...
20,597
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> __global__ void mult_mat(float *matA, float *matB, float *matR, int ncol, int nRows, int stream) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int idy = blockIdx.y * blockDim.y + threadIdx.y; float res=0; int nPr = stream*ncol*nRows; for(int i=0; i...
20,598
#include <stdio.h> #include <curand_kernel.h> #include <unistd.h> #include <curand.h> #define M 512 #define CUDART_PI_F 3.141592654f // the CUDA kernel for vector addition __global__ void sum(double *a, double *b, double *out, int n) { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < n) { out[idx] = a...
20,599
#include <iostream> #include <chrono> #include <cassert> #include <cmath> #include <cstdlib> #include <vector> #include <algorithm> #define BLOCKSIZE 128 // MUST BE ASSOCIATIVE __device__ inline int f(int a, int b){ return a + b; } /** * Implements prefix-scan using a Hillis-Steele algorithm. * Since Hillis-St...
20,600
#include <iostream> #include <math.h> //#include <cuda_runtime.h> // function to copy the elements of an array and decrement to make the compiler not override it __global__ void copyKernel(int n, float4* x, float4* y, float4* z, float4* w){ int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim...