serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
1,001
#include "includes.h" __device__ int d(void) { return 8; } __global__ void g(void) {}
1,002
__global__ void step( int n, float *xy, int *num_edges, int *first, int *num, int *map, int *potential, float stp, float reject_stp, float attract_stp, float spring_stp, float spring_reject_rad, float spring_attract_rad, float node_rad ){ const int i = blockIdx.x*512 + threadIdx.x; if (...
1,003
// SPDX-FileCopyrightText: 2020 CERN // SPDX-License-Identifier: Apache-2.0 #include <curand.h> int main() { // What are the ways to transform the CPU `fisher_price` to CUDA/GPU // An obvious branch/divergence (eloss vs pair), but good exercise // As first steps in microkernel workflow. return 0; }
1,004
#include <stdio.h> #include <cmath> #include <math.h> #include <ctime> __global__ void findwindow (bool* mask_img, int* scores) { int wh_p = blockIdx.x * blockDim.x + threadIdx.x; // threadIdx.x; int ui = blockIdx.y * blockDim.y + threadIdx.y; // 60 int vi = blockIdx.z * b...
1,005
#include <thrust/device_vector.h> #include <thrust/fill.h> #include <thrust/sequence.h> #include <iostream> struct soma_impares { __device__ __host__ int operator()(const double &x, const double &y) { return x + y; } }; int main() { thrust::device_vector<double> v(100); thrust::sequence(v...
1,006
// ref https://devblogs.nvidia.com/parallelforall/even-easier-introduction-cuda/ // ver 20170219 by jian #include <iostream> #include <math.h> // ``kernel'' to add the elements of two arrays __global__ void add(int n, float *x, float *y) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * ...
1,007
__global__ void k(int *input, int *output, int count) { int tid = threadIdx.x; int nid = blockDim.x; #pragma unroll 3 for(int i =tid; i<count; i+=nid) { output[i]=input[i]*16; } }
1,008
#include <stdio.h> class CudaClass { public: int* data; CudaClass(int x) { data = new int[1]; data[0] = x; } }; __global__ void useClass(CudaClass *cudaClass) { printf("%d\n", cudaClass->data[0]); }; int main() { CudaClass c(1); // create class storage on device and copy top level class CudaCl...
1,009
//Just your regular Hello World file // to be compiled with nvcc rather than gcc #include <stdio.h> int main(void) { printf("Hello World from CPU!\n"); return 0; }
1,010
#include <stdio.h> #include <stdlib.h> #define SIZE (1024*1024) __global__ void addVector(float* left, float* right, float* result) { int idx = threadIdx.x; result[idx] = left[idx] + right[idx]; } __host__ int main() { float* vec1 = new float[SIZE]; float* vec2 = new float[SIZE]; float* vec3 = new float[SIZE]; ...
1,011
#include <stdio.h> #include <fstream> #include <iostream> #include <string.h> #include <vector> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> #include <time.h> #include <cuda.h> //#include "sha256.h" #define uchar unsigned char // 8-bit byte #define uint unsigned int // 32-bit word //define for sha256...
1,012
#include <stdio.h> __device__ void MatrixSquare(void *input) { float *matrix = (float *) input; int warp_size=32; int thread = threadIdx.x % warp_size; int matrixWidth = 32; for (unsigned int i = thread; i < matrixWidth; i=i+32) { for (unsigned int j = 0; j < matrixWidth; j++) {...
1,013
#include <cuda.h> #include <stdio.h> #include <iostream> #include <time.h> #define T 4 using namespace std; //prod matrice matrice terza versione(vedi slide) //input: l,m,n, size blocco (blocchi bidimensionali, quadrati, l m ed n devono essere multipli interi di sizeblocco) __host__ void allocaEInizializzaMatrice(i...
1,014
#include <stdio.h> #define GREENWICH_LON (0.0f) #define PI (3.141592653589793f) #define DEG2RAD (PI / 180.0f) #define RAD2DEG (180.0f / PI) #define i_dt (threadIdx.z) #define i_dxy (blockIdx.x + (blockIdx.y * gridDim.x)) #define i_dxyt (i_dxy + gridDim.x * gridDim.y * i_dt) __device__ void getdeclination(float *dec...
1,015
/******************************************************************************/ /* */ /* (C) 2010 Texas Advanced Computing Center. All rights reserved. */ /* For information, contact Frank Willmore: willmore@tacc.utexas.edu ...
1,016
#ifdef _WIN32 # define NOMINMAX #endif // includes, system #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> __global__ void MatMult(double *dA, double *dB, double *dC, int nRows, int nInnerDimension, int nCols, int TileSize) { int bx = blockIdx.x; int by = blockIdx.y; int tx = threadI...
1,017
/*#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <opencv2/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgui.hpp> #include<opencv2\imgproc.hpp> #include <iostream> #define totalThreads 16 __global__ void kernel(unsigned char* d_img_in, unsigned char* d...
1,018
/* Compute the sum of two vectors using CUDA * Vishwas S */ #include <stdio.h> #include <stdlib.h> __global__ void add(int *a, int *b, int *c, int n) { int id = blockIdx.x*blockDim.x + threadIdx.x; if(id<n) c[id] = a[id] + b[id]; } int main() { int N; int *a, *b, *c, *da, *db, *dc; scanf("%d",&N); cuda...
1,019
#include "includes.h" __global__ void vc(float *dA, float *dB, int N) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < N) { dA[id] = dB[id]; } }
1,020
#include "includes.h" __global__ void sinewave(float *heightMap, unsigned int width, unsigned int height, float time) { const float freq = 4.0f; const size_t stride = gridDim.x * blockDim.x; // Iterate through the entire array in a way that is // independent of the grid configuration for (size_t tid = blockIdx.x * blo...
1,021
#include "includes.h" __global__ void LinearPolynomProbsImpl( const float* features, int batchSize, const int* splits, const float* conditions, const int* polynomOffsets, int polynomCount, float lambda, float* probs, const int* origFIds) { if (threadIdx.x < batchSize) { int polynomId = blockIdx.x; features += threadId...
1,022
#include "job.cuh" #include "common.cuh" int calc_jobs(int real_job_num) { return (real_job_num / THREADS_PER_BLOCK) * THREADS_PER_BLOCK + ((real_job_num % THREADS_PER_BLOCK) ? THREADS_PER_BLOCK : 0); } job_t allocate_host_job(job_t job) { job_t host_job = job; int jobs_num = calc_jobs(host_job.image_width * h...
1,023
#include<iostream> #include<chrono> #include<cuda.h> #include<cuda_runtime.h> #define N 1024 using namespace std; using namespace std::chrono; static const int wholeArraySize = 100000000; static const int blockSize = 1024; static const int gridSize = 24; //this number is hardware-dependent; usually #SM*2 is a good n...
1,024
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void swap(int *a, int n) { int temp; int i = blockIdx.x * blockDim.x + 0; int j = blockIdx.x * blockDim.x + 1; temp = a[i]; a[i]= a[j]; a[j]=temp; } int main(void) { int n,a[100],i; printf("Enter no of elements...
1,025
#include <cstdlib> #include <iostream> //#include <cuda_runtime.h> #include <cuda.h> #include <stdio.h> #define CUDA_CHECK_RETURN(value) {\ cudaError_t _m_cudaStat = value;\ if (_m_cudaStat != cudaSuccess) {\ fprintf(stderr, "Error %s at line %d in file %s\n",\ cudaGetErrorString(_m_cudaStat), __LINE__...
1,026
#include<iostream> using namespace std; #define size 256 #define ssize size*4 __global__ void max_reduction(int *v,int *v_r) { __shared__ int partial_sum[ssize]; int tid=blockIdx.x*blockDim.x+threadIdx.x; partial_sum[threadIdx.x]=v[tid]; __syncthreads(); for(int i=blockDim.x/2;i>0;i=i/2) { if(threadIdx...
1,027
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #define CHECK_STATUS(status) \ if (status != cudaSuccess) \ fprintf(stderr, "File: %s\nLine:%d Function:%s>>>%s\n", __FILE__, __LINE__, __FUNCTION__,\ cudaGetErrorString(status)) // Device code __global__ void MyKe...
1,028
#include <cstdio> const int NUM_THREADS = 256; const int NUM_CATEGORIES = 5; template <typename T, int NUM_ARRS> __device__ void multiReduce(volatile T arr[NUM_ARRS][NUM_THREADS]) { if (threadIdx.x < 128) { for (int i = 0; i < NUM_ARRS; ++i) arr[i][threadIdx.x] += arr[i][threadIdx.x + 128]; } __syncthread...
1,029
#include <cuda.h> //#include <cutil_inline.h> #include <stdio.h> #include <stdlib.h> #include <string> #include <iostream> #include <fstream> #define ASIZE 256 #define DATA_SIZE 1024 __device__ int shifts[ASIZE]; __device__ int results[DATA_SIZE]; __global__ void processPattern(char* x ,int m, int shifts[]) { int i...
1,030
#include "includes.h" __global__ void izhikevich_update_membrane_potentials_kernel(float *d_membrane_potentials_v, float *d_states_u, float *d_param_a, float *d_param_b, float* d_current_injections, float* thresholds_for_action_potentials, float* last_spike_time_of_each_neuron, float* resting_potentials, float current_...
1,031
//每个线程同时加密64块即1024B数据 //将数据预处理,事先翻转 //在远端服务器块内线程256:21.483 Gbps //远端服务器块内线程512:22.75 Gbps #include<stdio.h> #include<string.h> #include <stdint.h> #include <stdlib.h> #include <iostream> #include <fstream> #include <cstring> #include <cuda.h> #include <iomanip> #include <time.h> typedef uint64_t word_t; #define BYTE...
1,032
__device__ int countBits(unsigned int v) { int c; // c accumulates the total bits set in v for (c = 0; v; v >>= 1) { c += v & 1; } return c; } __device__ bool checkerFunc (unsigned int* queensList,int width, int numQueens){ ////input exceptions // if (numQueens > width){ // prin...
1,033
#include <cuda.h> #include <stdio.h> #include <stdlib.h> /*inline void CUDA_ERROR_CHECK(const cudaError_t &err){ if(err != cudaSuccess){ fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(err)); exit(EXIT_FAILURE); } }*/ __device__ int mandel(float c_re, float c_im, int maxIteration) { float z_re =...
1,034
/*! * \brief Matrix multi with shared memory */ #include <stdio.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <time.h> #include <stdlib.h> __global__ void MatrixMuiOnDevice(int *M,int *N, int *P, int width) { int x = threadIdx.x; int y = threadIdx.y; ...
1,035
#include <iostream> #include <math.h> using namespace std; __global__ void kernel_sum (int *A, int *B, int *C, int n); void sum (int *A, int *B, int *C, int n); int main() { int n; cout<<"Enter n:"; cin>>n; int size=n*sizeof(int); int *deviceA,*deviceB,*deviceC; int *hostA = (int*)malloc(size); int *hostB ...
1,036
/* ============================================================================ Name : structoverflow.cu Author : Version : Copyright : Your copyright notice Description : CUDA compute reciprocals ============================================================================ */ #include <stdio....
1,037
#include <stdio.h> #include <math.h> int main(){ // GetGPUProperties cudaDeviceProp props; cudaGetDeviceProperties(&props,0); // Get maximum threads, blocks and grids printf("GPU Info\n"); printf("Name: %s\n",props.name); printf("Max Threads Per Block %d\n",props.maxThreadsPerBlock); ...
1,038
/* * main.cpp * * Created on: Jul 4, 2015 * Author: markus */ #include <iostream> #include <iomanip> #include <sstream> #include <fstream> #include <numeric> #include <stdlib.h> #include <chrono> #include <vector> #include <algorithm> using namespace std::chrono; using namespace std; struct Mat { Mat() :...
1,039
float h_A[]= { 0.9437638001242697, 0.9136534788427546, 0.7464430964435773, 0.6148443668541146, 0.8639953234778698, 0.6252542682698676, 0.8583020500593208, 0.6776662703078024, 0.7384280592300332, 0.8195537928976389, 0.7435505093785533, 0.626861660657713, 0.7911855482725979, 0.5991974690271062, 0.9075270446196592, 0.9953...
1,040
#include <iostream> #include <set> #include <algorithm> #include <assert.h> #include "cuda_runtime.h" using namespace std; #define ITERATION_FINEGRAINED (1) #define KB (1024/sizeof(int)) #define MB (KB*1024) #define MAX_NUM_THREADS (1024) // a block has maximal ...
1,041
#include <math.h> #include <stdio.h> #include <stdlib.h> #define PI 3.14159265359 __global__ void solve(const int N, float * u, float *newu, float *f, float *res2v){ float w = 0.5; int id = blockIdx.x*blockDim.x + threadIdx.x; if (id>N+2 && id<(N+2)*(N+2)-(N+2) && id%(N+2) !=N+1 && id%(N+2) != 0){ const float ...
1,042
#include <stdio.h> // 1. Note the convention d_* is used for device and h_* is used for host allocations. // 2. __global__ tells cuda that what follows is a kernel implementation // Cuda kernel that returns a cube of a given array // Mostly written in a serial manner __global__ void cube(float *d_out, float *d_in) {...
1,043
/* * SpaceTime Simulator * Curso Deep Learning y Cuda - 2020 * Autor: Oscar Noel Amaya Garcia * email: dbanshee@gmail.com */ #include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <unistd.h> #include <string.h> #include <sys/time.h> #define RUN_MO...
1,044
#include <iostream> #include <stdio.h> using namespace std; #define imin(a,b) (a<b?a:b) const int N = 33*1024; const int threadsPerBlock = 256; const int blocksPerGrid = imin(32, (N+threadsPerBlock-1)/threadsPerBlock); // dot on the kernel __global__ void dot(float *a, float *b, float *c) { __shared__ float cach...
1,045
/* * File: HelloCuda.cu * * Created on June 24, 2012 * * Purpose: Demonstrate 2D Blocks and Threads with Hello World * * If it works, it was written by Brian Swenson. * Otherwise, I have no idea who wrote it. */ #include <iostream> #include <cuda_runtime.h> #include <stdio.h> using namespace std; di...
1,046
/* Copyright 2015 Stanford University, NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by app...
1,047
#include <time.h> #include <stdlib.h> #include <stdint.h> #include <stdio.h> #include <iostream> // Required to include CUDA vector types #include <cuda_runtime.h> #include <vector_types.h> #define REPETITIONS 1000 #define NS_PER_SECOND 1000000000L #define VECTOR_SIZE 1000*1024 // CUDA kernel. Each thread takes ...
1,048
#include "includes.h" __global__ void convdx_gpu_kernel(float *dx, float *dy, float *weights, const int S,const int outSize, const int inSize){ int row = blockIdx.y*blockDim.y+threadIdx.y; int col = blockIdx.x*blockDim.x+threadIdx.x; if(row < inSize && col < outSize){ // printf("row %d, col %d, bias[col] %.2f\n", row,...
1,049
#include "includes.h" __global__ void vectorAddGPU(float *a, float *b, float *c, int N) { int idx = blockIdx.x*blockDim.x + threadIdx.x; if (idx < N) { c[idx] = a[idx] + b[idx]; } }
1,050
#include <cuComplex.h> #include <cuda.h> #include <cuda_runtime.h> __host__ __device__ double carg(const cuFloatComplex &z) { return atan2(cuCimagf(z), cuCrealf(z)); } __host__ __device__ cuFloatComplex conj(const cuFloatComplex &z) { return make_cuFloatComplex(z.x, -z.y); } __global__ void calc_beta_err_kernel(c...
1,051
//////////////////////////////////////////////////////////////// // 2D FDTD solution for Mur's Absorbing Boundary Condition // Using GPU acceleration (CUDA implementation) // Simple harmonic excitation source ////////////////////////////////////////////////////////////// // Set your code generation to "compute...
1,052
#include <stdio.h> #include <time.h> const long int M = 10; const long int N = 10; const long int O = 10; #define BLOCK_WIDTH 16 void fillMatrix(float *A, long long int sizeA); void printMatrix(float *A, long long int sizeA, long long int N); float getValue(float *A, long long int i, long long int j, long long int co...
1,053
#define TILE_DIM 32 template<typename T, typename R> __device__ void common_std(const T* matrix, R* result, const int numRows, const int numColumns) { __shared__ R sumTile[TILE_DIM][TILE_DIM]; __shared__ R squareSumTile[TILE_DIM][TILE_DIM]; int tx = threadIdx.x; int ty = threadIdx....
1,054
#include <stdio.h> __global__ void printid(){ int id = blockIdx.x; printf("I'm a thread in block %d!\n", id); __syncthreads(); } int main(int argc, char **argv){ printid<<<16, 1>>>(); cudaDeviceSynchronize(); printf("That's all!\n"); return 0; }
1,055
// runSim.cu #include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #include <math.h> #include <thrust/reduce.h> #include <thrust/execution_policy.h> // Executes the A1 operator optimized __global__ void A1_kernel(double* r, double* v, double dt) { size_t id = blockIdx.x * blockDim.x +...
1,056
#include "includes.h" __device__ inline float stableSigmoid(float x) { if(x >= 0) { float z = expf(-x); return 1.0 / (1.0 + z); } else { float z = expf(x); return z / (1.0 + z); } } __global__ void gGRUFastBackward(float* outState, float* outXW, float* outSU, float* outB, const float* state, const float* xW, const floa...
1,057
/* Program perform matrix multiplication */ #include<stdio.h> #include<cuda.h> #include<assert.h> #include<stdlib.h> #include<sys/time.h> #define VAL_LIMIT 10 #define DEBUG 0 #define TILE_WIDTH 32 cudaError_t err; /* * @PRAM : Number of rows and columns * @RETURN : Pointer to created Matrix * @DESC : * @S...
1,058
//A practice code of using constant memory in dot product //Author: Zhaoyuan "Maxwell" Cui //Jun 13, 2017 #include<stdio.h> #include<iostream> #define VEC_DIM 120 //Define constant memory __constant__ float d_vec[VEC_DIM]; //Prototype the kernal __global__ void kernal(float* input,float* d_result); int main() { ...
1,059
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> int sorting(int argc, char** argv) { std::cout << "not implemented" << std::endl; return 0; }
1,060
__global__ void gaussKernel(float *ptr, int width, int height, int sigma2) { int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; if(x < width && y < height) { int xc = width / 2; int yc = height / 2; int idx = (width * y + x); ptr += idx; float pi = 3.1415926f; ...
1,061
#include "includes.h" __constant__ float *c_Kernel; __global__ void convolutionColumnsKernel_down_smp( float *d_Dst, float *d_Src, int imageW, int imageH, int n_imageH, int pitch, int filter_Rad, int Halo_steps ) { extern __shared__ float s_Data[]; //Offset to the upper halo edge const int baseX = blockIdx.x * COLUM...
1,062
#include <stdlib.h> #include <stdio.h> #include <math.h> #define BLOCK_SIZE 3 #define WA 3 #define HA 3 #define WB 3 #define HB 3 #define WC 3 #define HC 3 void Init(float * data ,int size) { for(int i = 0; i < size; ++i) data[i] = i; } __global__ void matrixMul(float* A,float* B,float* C,int wA,int wB) { int ...
1,063
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <math.h> #include <complex.h> #include <cuda_runtime.h> #include <utility> #include <sys/time.h> #define K 3 #define BLCH 8 #define BLCW 32 int compute(float *img, float *f, float * out, int bh, int bw, int imgH, int imgW, int imgN, int nF, int convH,...
1,064
#include <stdio.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <chrono> using namespace std; __global__ void addKernel( int* a, int* b, int* c ) { int idx = threadIdx.x; c[idx] = a[idx] + b[idx]; } void testCudaAdd() { const int COUNT = 10; int* a = new int[COUNT]; int...
1,065
#include <stdio.h> #include <sys/time.h> #include <vector> #include <iostream> using namespace std; int problem_size = 20000000; float random_float(float a, float b) { float random = ((float) rand()) / (float) RAND_MAX; float diff = b - a; float r = random * diff; return a + r; } int random_int(in...
1,066
// Dot product #include <iostream> #define N 1024 __global__ void dot( int*a, int*b, int*c ) { __shared__ int temp[N]; temp[threadIdx.x] = a[threadIdx.x] * b[threadIdx.x]; __syncthreads(); // Thread 0 sums the pairwiseproducts if( 0 == threadIdx.x ) { int sum = 0; for( int i = N-1; i >= 0 ; i-- ) sum += temp[i];...
1,067
#include "includes.h" __global__ void add(float *A, float *C) { int columna = threadIdx.x; //indice de las filas int fila = threadIdx.y; //indice lineal int Id = columna + fila * blockDim.x; int id1 = (columna - 1) + fila * blockDim.x; int id2 = (columna + 1) + fila * blockDim.x; int id3 = columna + (fila - 1) * block...
1,068
#include <iostream> #include <ctime> #include <cstdlib> #include <cmath> #include "cuda_runtime.h" #include <thrust/scan.h> using namespace std; #define TPB 1024 #define RANGE 10 #define min(a,b) ((a < b) ? a : b) __global__ void incl_pfsum (float * array, int size) { int bsize = blockIdx.x * blockDim.x; int tid...
1,069
#include "includes.h" __global__ void arrayReduce(int *m, int *ms){ int id = threadIdx.x + blockIdx.x * blockDim.x; if (m[id] > -1) m[id] = m[id] - ms[blockIdx.x]; }
1,070
#include "includes.h" __global__ void worker(double * a, long n) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < n) { a[i] += i; } }
1,071
__global__ void create_escape_carry_index(char *file, long n, char *escape_carry_index) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; long normal_chars_per_thread = max((n+stride-1) / stride, 64L); long chars_per_thread = ((normal_chars_per_thread + 64 - 1) / 64) * 6...
1,072
/* CUDA exercise to convert a simple serial code for a brute force largest prime number search into CUDA. This initial code is serial, but it is written as CUDA code for your convenience, so should be compiled with nvcc (see below). Your task is to convert the serial computation to a kernel computation. In ...
1,073
#include<iostream> #include <stdlib.h> #include <time.h> #include <math.h> #include "../inc/WeightedGraph.cuh" WeightedGraph::WeightedGraph(int s,int p){ size=s; cudaMallocManaged(&adjmat,size*sizeof(float*)); srand(time(NULL)); for(int i=0;i<size;i++){ cudaMallocManaged(&adjmat[i],siz...
1,074
#include "includes.h" // Device input vectors int *d_a; //Device output vector int *d_b; __global__ void setLastToCero(int *A, int size) { const int index = blockIdx.x * blockDim.x + threadIdx.x; if (index == size - 1) { A[index] = 0; } }
1,075
//ulimit -s unlimited //gcc -lm -std=c99 NRCDML1RegLog.c && ./a.out //nvcc CE.cu -arch sm_20 && ./a.out #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #include <stdint.h> #include <cuda.h> #include "device_functions.h" #include <curand.h> #include <curand_kernel.h> #inc...
1,076
#include<stdio.h> #define N 833 void add(int *X, int* Y, int* Z) { for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { Z[i*N+j] = X[i*N+j] + Y[i*N+j]; } } } __global__ void add_kernel(int *X, int *Y, int *Z) { int i = threadIdx.x; int j = threadIdx.y; if(i < N && j < N) { Z[i*N+j] = X[i*N+j] ...
1,077
//////////////////////////////////////////////////////////////////////////// // Calculate scalar products of VectorN vectors of ElementN elements on CPU. // Straight accumulation in double precision. //////////////////////////////////////////////////////////////////////////// #include <iostream> //extern "C" void Ker...
1,078
#include <stdio.h> #define N 32 void add(int *X, int *Y, int *Z){ for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ Z[i*N+j] = X[i*N+j] + Y[i*N+j] ; } } } __global__ void add_kernel(int *X, int *Y, int *Z){ int i = threadIdx.x ; int j = threadIdx.y ; if(i < N && j < N){ Z[i*N+j] = X[i*N+j] + Y[i*N+j] ; ...
1,079
#include "learn_kernels.cuh" __global__ void kMultiplyBySigmoidGrad(float* act, float* target, const 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) { targ...
1,080
#include "includes.h" __global__ void reduce_to_first_index_h(float *X, int height, int width) { int t = blockIdx.x * blockDim.x + threadIdx.x; float tmp = 0; if (t < width) { for (int i = 0; i < height; i++) { tmp += X[i * width + t]; } X[t] = tmp; } }
1,081
#include <stdio.h> #include <stdlib.h> #include <fstream> #include <iostream> #include <float.h> using namespace std; #define TILE_WIDTH 32 //#define THREADS_PER_BLOCK 32; void MatrixMulOnHost(float* M, float* N, float* P, int Width) { for (int i = 0; i < Width; ++i) for (int j = 0; j < Width; ++j) { float sum...
1,082
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <math.h> __global__ void cuda_hello(){ printf("Hello World from GPU!\n"); } int main(){ cuda_hello<<<1,1>>>(); printf("Hello World from CPU!\n"); cudaGetLastError(); return 0; }
1,083
// matrix multiplication between square matrices using bidimensional indexes. #include <stdio.h> #include <stdlib.h> #include <time.h> #include <ctype.h> #include <sys/types.h> #include <sys/time.h> // #define MATRIXSIZE 10 // #define MAX_THREADS 5 // #define NUM_BLOCKS MATRIXSIZE / MAX_THREADS double cclock() /*...
1,084
// for this simple illustration, it is assumed that the code runs in // just one block, and that the number of threads evenly divides n // improvements that could be made: // 1. change to multiple blocks, to try to use all SMs // 2. possibly use shared memory // 3. have each thread work on staggered elemen...
1,085
#include <stdio.h> __constant__ int const_symbol; /********************/ /* CUDA ERROR CHECK */ /********************/ #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...
1,086
// standard lib stuff #include <stdio.h> #include <iostream> #include <math.h> #include <algorithm> #include <random> // thrust library #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/tuple.h> #include <thrust/generate.h> #include <thrust/random.h> #include <thrust/sort.h> #include <...
1,087
#include "includes.h" __global__ void __word2vecEvalPos(int nrows, int ncols, int *W, int *LB, int *UB, float *A, float *B, float *Retval) {}
1,088
#include <stdio.h> __global__ void helloFromGPU() { printf("Hello, World from GPU!\n"); } void helloFromCPU() { printf("Hello, World from CPU!\n"); } int main() { helloFromCPU(); helloFromGPU<<<1,1>>>(); cudaDeviceSynchronize(); helloFromCPU(); }
1,089
template <typename T> struct A { T* p; int *b; A(int a) { p = new T[a]; b = new int[a]; } }; int main() { A<int> x(10); return 0; }
1,090
__device__ int ave(int a, int b) { return (a+b)/2; } __global__ void simple(int *data) { int tid = blockIdx.x * blockDim.x + threadIdx.x; data[tid] = ave(tid, tid); }
1,091
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <time.h> #define WA 10000 // Matrix A width #define HA 10000 // Matrix A height #define WB 10000 // Matrix B width #define HB WA // Matrix B height #define WC WB // Matrix C width #define HC HA // Matrix C height #define N 100 #...
1,092
#include<iostream> using namespace std; __global__ void average(int *a, float *b, int n) { int tid=threadIdx.x; int sum=0; for(int i=0;i<n;i++) { sum+=a[i]; } float mean=sum/(n*1.0); b[tid]=mean; } __global__ void standardDev(int *a, float *b, float mean, int n) { int tid=blockIdx.x; b[0]...
1,093
#include <iostream> #include <cstdlib> #include <stdio.h> #include <math.h> #include <assert.h> #include <sys/time.h> __global__ void fPixelGenerator(int width, unsigned char* pic) { int frame = threadIdx.x; // ID da thread for (int row = 0; row < width; row++) { for (int col = 0; col < width; col++) { ...
1,094
#include "includes.h" __global__ void vectorAddKernel(float *a, float *b, float *c, int n) { // Escribir en c la suma de a y b };
1,095
#include "includes.h" __global__ void l2_regularize_kernel(int factors, float regularization, float * YtY) { YtY[threadIdx.x * factors + threadIdx.x] += regularization; }
1,096
#include<stdio.h> #include<stdlib.h> #include<math.h> double randd() { return (double)rand() / (RAND_MAX + 1.0); } //Kernel -- To multiply matrix with it's transpose __global__ void multiply_serial(double **d_a,double **d_c,int mSize) { int i,j,k; //start with matrix multplication calcultaion for(i=0;i<mSize;i++)...
1,097
#include "includes.h" /* This file is copied from https://github.com/jzbonter/mc-cnn */ extern "C" { } #define TB 128 #define DISP_MAX 256 __global__ void rho(float *x, int size, float lambda) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < size) { x[id] = 1 - exp(-x[id] / lambda); } }
1,098
// Approximation of Pi using a simple, and not optimized, CUDA program // Copyleft Alessandro Re #include <stdio.h> #include <cuda.h> #include <curand_kernel.h> typedef unsigned long long Count; const Count WARP_SIZE = 32; // Warp size const Count NBLOCKS = 64; // Number of total cuda cores on my GPU __global__ voi...
1,099
#include<iostream> using namespace std; #define N 512 __global__ void ArithmeticMean (int *a,int *o) { int of = N/2; int tid = threadIdx.x; for(of;of>0;of = of/2) { if(tid < of) { a[tid]+=a[tid+of]; } } o[0] = a[0]; } int main() { int *h_a,*d_a,*o_a...
1,100
#if GOOGLE_CUDA #define EIGEN_USE_GPU __global__ void default_function_kernel0(const float* __restrict__ U, const float* __restrict__ K0, float* __restrict__ U0) { float U0_local[1]; __shared__ float U_shared[128]; __shared__ float K0_shared[4]; for (int n_inner_outer = 0; n_inner_outer < 2; ++n_inner_outer) ...