serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
24,101
#include "includes.h" static unsigned int GRID_SIZE_N; static unsigned int GRID_SIZE_4N; static unsigned int MAX_STATE_VALUE; __global__ static void cudaSumTIGammaKernel(unsigned char *tipX1, double *x2, double *tipVector, double *sumtable, int limit) { const int n = blockIdx.x * blockDim.x + threadIdx.x; if (n >= li...
24,102
#include<stdio.h> __global__ void kernel(int * a, int * b) { *b=*a+*b; } int main(void) { int h_in,h_out; int *d_out,*d_in; h_in=2; h_out=7; cudaMalloc((void **)&d_out,sizeof(int)); cudaMalloc((void **)&d_in,sizeof(int)); cudaMemcpy(d_in,&h_in,sizeof(int),cudaMemcpyHostToDevice); cudaMemcpy(d_out,&h_out,sizeof(int),cu...
24,103
#include "includes.h" #define TB 128 #define GS(x) (((x) - 1) / TB + 1) __global__ void downsample_(float *input, float *output, int factor, int size3, int size) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < size) { int dim3 = id % size3; int dim2 = id / size3; atomicAdd(output + ((dim2 / factor) * (siz...
24,104
#include <vector> #include <iostream> #include <string> #include <iomanip> #include <sys/time.h> #include <cuda.h> #include <cstdio> #include <cmath> const int MAXITER = 1024; const int DIVISOR = 512; enum Color { red, black }; #define AT(mtx, width, row, column) \ mtx[(row) * (width) + (column)] inline do...
24,105
#include <cstdio> // main program for the CPU: compiled by MS-VC++ int main(void) { // host-side data const int WIDTH = 5; int a[WIDTH][WIDTH]; int b[WIDTH][WIDTH]; int c[WIDTH][WIDTH] = { 0 }; // make a, b matrices for (int y = 0; y < WIDTH; ++y) { for (int x = 0; x < WIDTH; ++x) { a[y][x] = y * 10 + x; ...
24,106
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #define MAXBLOCKS 10 #define MAXTHREADS 1 //__global__ (paralellized method) __global__ void VectorAdd(int *a, int *b, int*c, int n) { int i = blockIdx.x; //Assign each c element to a single block c[i] = a[i] + b[i]; } int main() ...
24,107
#include "includes.h" __global__ void ExactResampleKernel_Nto1(float *input, float *output, int inputWidth, int inputHeight, int outputWidth, int outputHeight) { int id = blockDim.x * blockIdx.y * gridDim.x + blockDim.x * blockIdx.x + threadIdx.x; int size = outputWidth * outputHeight; if (id < size) { //output point ...
24,108
#include <cmath> #include <cstdlib> #include <cstdio> #include <sys/time.h> #define M 1024 __global__ void matmul(float *A, float *B, float *C, int N) { int i = blockIdx.y; int j = threadIdx.x + blockDim.x * blockIdx.x; float sum = 0.0f; __shared__ float s_A[M]; for (int ks=0; ks<N; ks+=M) { __syncthrea...
24,109
int main(){ float * tst; cudaMalloc((void **) &tst, sizeof(float) * 10); }
24,110
#include <cstdio> #include <cstdlib> #include <cuda_runtime.h> #include <cuda.h> #include "rbm_cuda.cuh" __global__ void trainKernel(int* train_vec_in_batch, int* movies_in_batch, int* ratings_in_batch, float* Vzeros, float* Vts, float* Hzeros, float* Hts, float* W, float* BV, float* BH, float* W_inc, float* BV_...
24,111
#include "includes.h" __global__ void g_One_wgrad_Add( float* _WgradTmp, float* Wgrad, float* w, int rows, int cols, int channels, float lambda) { extern __shared__ float _sum[]; int channel = blockIdx.x; int col = blockIdx.y; int tid = threadIdx.x; _sum[tid] = 0; __syncthreads(); for(int i = 0; i < rows; i +...
24,112
#include "includes.h" __global__ void sobel( int width_d, int height_d, int threshold_d, unsigned int *pic_d , int *final_res) { int row_1 = blockIdx.y * blockDim.y + threadIdx.y; int col_1 = blockIdx.x * blockDim.x + threadIdx.x; int tx = threadIdx.y; int ty = threadIdx.x; int width_Tile = TILE_SIZE; int id, id...
24,113
#include "includes.h" __global__ void kernel_update_velocities(float4* d_uv, float4* d_velocities_buffer, int numel) { size_t col = threadIdx.x + blockIdx.x * blockDim.x; if (col >= numel) { return; } d_velocities_buffer[col] = make_float4( d_uv[col].x, d_uv[col].y, 0, 0 ); __syncthreads(); }
24,114
#include "includes.h" __device__ void updateCMax(const int nbrOfGrids, const double *d_u1, const double *d_u2, const double *d_u3, const double *d_gama, double *d_cMax) { *d_cMax = 0; int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; double ro, p, u; __shared__ double c; for (int i...
24,115
/* //Serial version #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <math.h> #include <time.h> #define SEED 921 #define NUM_ITER 1000000000 int main(int argc, char * argv[]) { int count = 0; double x, y, z, pi; srand(SEED); // Important: Multiply SEED by "rank" when yo...
24,116
#include "cuda.h" #include "stdio.h" #include <sys/time.h> #include <sys/resource.h> double dwalltime(){ double sec; struct timeval tv; gettimeofday(&tv,NULL); sec = tv.tv_sec + tv.tv_usec/1000000.0; return sec; } int cant = 512; int cant_elem = cant * cant; // arreglos u...
24,117
#include <curand_kernel.h> __device__ float gamma(float k, curandState_t* state_ptr){ // gamma distribution float x; if(k<1){ // Weibull algorithm float c=1/k; float d=(1-k)*powf(k, 1/(c-1)); float z; float e; do{ z=-logf(curand_uniform(state_ptr)); e=-logf(curand_uniform(state_...
24,118
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cmath> #include <iostream> #include <forward_list> #include <chrono> cudaError_t findSimpleDividersWithCUDA(std::forward_list<long long> *result, long long value, int cudaCores); __device__ bool isPrime(long long value) { f...
24,119
__global__ void reduce_kernel(const int* g_idata, int* g_odata, unsigned int n) { extern __shared__ int arr[]; long tid = threadIdx.x; long idx = (long)blockIdx.x * (long)blockDim.x + tid; if (idx < n) arr[tid] = g_idata[idx]; else arr[tid] = 0; __syncthreads(); for...
24,120
#include "includes.h" __global__ void metropolisPoposal2 ( const int dim, const int nwl, const int isb, const float *xx, const float *rr, float *xx1 ) { int i = threadIdx.x + blockDim.x * blockIdx.x; int j = threadIdx.y + blockDim.y * blockIdx.y; int t = i + j * dim; if ( i < dim && j < nwl ) { xx1[t] = xx[t] + ( i == ...
24,121
#include<iostream> #include<ctime> #define Size 512 using namespace std; template<typename T, unsigned int BlockSize> void __global__ add(const T* lhs,const T *rhs ,T*sum, const unsigned int n) { unsigned int idx = threadIdx.x + blockIdx.x * blockDim.x*4; if(idx + 3*blockDim.x < n) { sum[idx] = lhs[idx] + rhs[i...
24,122
/* * file name: matrix.cu * * matrix.cu contains the code that realize some common used matrix operations in CUDA * * this is a toy program for learning CUDA, some functions are reusable in other project * */ #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <unistd.h> #define BLOCK_SIZ...
24,123
#include "stdio.h" #define CUDA_ERR_CHECK(x) \ do{ cudaError_t err = x; \ if (err != cudaSuccess) { \ fprintf(stderr, "Error \"%s\" at %s:%d \n", \ cudaGetErrorString(err), __FILE__, __LINE__);\ exit(0);\ } \ } while(0) #define DGX 3 #define DGY 2 #define DBX 2 #define DBY 2 #define DBZ 2 #define ...
24,124
/* Program name: HelloGPU.cu Author name: Dr. Nileshchandra Pikle Email: nilesh.pikle@gmail.com Contact Number: 7276834418 Webpage: https://piklenileshchandra.wixsite.com/personal Purpose: To demonstarte 1. How to write a simple CUDA program 2. Calling ...
24,125
#include <iostream> #include <vector> #include <cstdio> #include <exception> /** macro to throw a runtime error */ #define THROW(fmt, ...) \ do { \ std::string msg; ...
24,126
// counting Hamilton cycle, CUDA acceleration #include<stdio.h> #include<stdlib.h> #define MAX_BLOCK_SIZE 1024 #define MAX_ARRAY_SIZE (1024*8) // any 2 <= mod <= 2^31 should work __host__ __device__ unsigned mod_sum(unsigned a, unsigned b, unsigned mod) { unsigned c = a+b; return c >= mod ? c-mod : c; } __glo...
24,127
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> // std::cout #include <algorithm> // std::sort #include <vector> // std::vector #include <time.h> using namespace std; #define PINNED 1 #define THREADS 1000 struct Point { float x, y; // Co-ordinate of point }; void se...
24,128
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <ctype.h> #include <sys/types.h> //----------------------------------------------------------------------------// //----------------------------------ppmFile.c----------------------------------// //---------------------------------...
24,129
#include "device_launch_parameters.h" #include <cuda_runtime_api.h> #include "cuda_runtime.h" #include <iostream> #include <stdlib.h> #include <random> #include <chrono> #include <math.h> using namespace std; // Define error values #define MEMORY_ERROR -2 #define INPUT_ERROR -1 // Define Constant value...
24,130
/** * Global Memory (Symbol) * Demonstrates: * - Communication between host and device * - Method in which host accesses global memory */ #include <stdio.h> #include <stdlib.h> #define NUM_ELEMENTS 5 __device__ int result[NUM_ELEMENTS]; void check_cuda_errors() { cudaError_t rc; rc = cudaGetLastError();...
24,131
#include "includes.h" __global__ void MatrixMulKernelV3(float* d_M, float* d_N, float* d_P, int Width) { __shared__ float Mds[TILE_WIDTH][TILE_WIDTH]; // [TILE_WIDTH][TILE_WIDTH] __shared__ float Nds[TILE_WIDTH][TILE_WIDTH]; // [TILE_WIDTH][TILE_WIDTH] int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x;...
24,132
/* * Module : Twine * Copyright : [2016..2017] Trevor L. McDonell * License : BSD3 * * Maintainer : Trevor L. McDonell <tmcdonell@cse.unsw.edu.au> * Stability : experimental * Portability : non-portable (GHC extensions) * * Convert between Accelerate's Struct-of-Array representation of complex *...
24,133
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #define MAX_THREADS 1024 //declerations cudaError_t matchWithGPU(int* results, double* points, int* signs, double* w, int numOfPoints, int k); cudaError_t updateLocationsWithGPU(double* locations, double* velocity, int numOfPoints, i...
24,134
#include "includes.h" #define MAX_THREADS 20 #define pi(x) printf("%d\n",x); #define HANDLE_ERROR(err) ( HandleError( err, __FILE__, __LINE__ ) ) #define th_p_block 256 __global__ void dotPro(long n, double *vec1, double *vec2, double *vec3) { __shared__ double cache[th_p_block]; unsigned tid = blockIdx.x * blockD...
24,135
// // Created by kindr on 2021/4/28. // #include "pinnedMemory.cuh" #include "../../common/utils.cuh" #include <cstdio> bool profileCopies(float *h_a, float *h_b, float *d, unsigned int n) { unsigned int bytes = n * sizeof(float); CHECK(cudaMemcpy(d, h_a, bytes, cudaMemcpyHostToDevice)); CHECK(cudaMemcpy...
24,136
#include "includes.h" __global__ void matrixAddKernel2(float* ans, float* M, float* N, int size) { int row = blockIdx.y*blockDim.y + threadIdx.y; if(row < size) { for(int i = 0; i < size; ++i) ans[row*size + i] = M[row*size + i] + N[row*size + i]; } }
24,137
#include <stdio.h> __global__ void AplusB(int *ret, int a, int b) { /* * Simple unimportant kernel */ ret[threadIdx.x] = a + b + threadIdx.x; } int main() { // Create a managed space int *ret; cudaMallocManaged(&ret, 1000 * sizeof(int)); // Call the kernel AplusB<<< 1, 1000 >>>(ret, 10, 10...
24,138
/* blockDim=[16, 16, 1] * * * p refers to the new pixel * */ __global__ void my_reduce256(float const * const partialSum16x16, float const * const ZpartialSum16x16, float *filtI, int m, int n) { __shared__ float Z[256], my_w[256]; int p=/*blockDim.z*blockIdx.z+threadIdx.z*/blockIdx.z; int tid = 16*threa...
24,139
#include <iostream> #include <assert.h> #include <cuda.h> #include <math.h> #include <bits/stdc++.h> using namespace std; #define isValid(X, Y) (X >= 0 && Y>=0 && X < M && Y < N) __global__ void image_bluring(float* a, float* b, int M, int N) { //__shared__ float[16][16][3]; int global_x = blockDim.x * blockIdx.x ...
24,140
#include <stdio.h> #include <stdlib.h> #include <cuda.h> /* * Tempo Sequencial: * real 1m9.236s * user 1m8.004s * sys 0m0.132s * * Tempo multicore: * real 0m17.290s * user 1m8.421s * sys 0m0.148s * * Tempo, warps_launched e warp_execution_efficiency GPU OpenMP: * * real 0m5.384s * u...
24,141
#include "MatrixUtilities.cuh" HostMatrix MatrixUtilities::loadFromFile(const char* fileName) { std::ifstream fin; fin.open(fileName); if (!fin.is_open()) { std::cerr << "Could not open " << fileName << "." << std::endl; exit(EXIT_FAILURE); } unsigned int height = 0; unsigned i...
24,142
#include <stdio.h> #include <cuda_runtime.h> /*#define CHECK(call) { const cudaError_t error = call; if (error != cudaSuccess) { printf("Error: %s:%d, ", __FILE__, __LINE__); printf("code:%d, reason: %s\n", error, cudaGetErrorString(error)); exit(1); } }*/ void initialInt(int *...
24,143
#include <cuda_runtime_api.h> #include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; void cuSetDeviceFlags(){ cudaSetDeviceFlags(cudaDeviceMapHost); } void cuMallocManaged(void** h_img, int r, int c, int channel){ cudaMallocManaged(h_img,sizeof(unsigned char)*r*c * channel...
24,144
/** * @file * @author answeror <answeror@gmail.com> * @date 2012-04-05 * * @section DESCRIPTION * * */ //#include <boost/range/algorithm/fill.hpp>
24,145
/* Name: Daniyal Manair Student Number: 20064993 */ #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <vector> #include <stdio.h> #include <random> #include <algorithm> #include <chrono> #include <map> __global__ void TiledMatrixMulGPU2(float* A, float* B, float* C, const int N) { __shared__...
24,146
#include <stdlib.h> #include <stdio.h> #include <sys/time.h> #include <iostream> #include <string> //===> FINITE DIFFERENCES PARAMETERS <===// #define DT 0.05f //->Time in milliseconds #define DX ( 12.0f / MODELSIZE_X ) //->Displacement in x #define DY ( 12.0f / MODELSIZE_Y ) //->Displacement in y ...
24,147
#include "includes.h" __global__ void get_i_idx_se_r(const int nloc, const int * ilist, int * i_idx) { const unsigned int idy = blockIdx.x * blockDim.x + threadIdx.x; if(idy >= nloc) { return; } i_idx[ilist[idy]] = idy; }
24,148
/** * @brief Hello Wolrd with an empty kernel. * * This is a basic Hello World example where we use our first * kernel, ableit empty. * * From: http://www.nvidia.com/docs/io/116711/sc11-cuda-c-basics.pdf */ #include <iostream> #include <string> /** * @brief Emt...
24,149
#include "includes.h" /* ============================================================================ Name : Author : Peter Whidden Version : Copyright : Description : ============================================================================ */ static void CheckCudaErrorAux (const char *, unsig...
24,150
#include "includes.h" __global__ void matrixMulCUDA5(float *C, float *A, float *B, unsigned int n) { const int tileWidth = 1; // Define the starting row and ending row for each thread block int startRow = blockIdx.y * blockDim.y + threadIdx.y * tileWidth; int endRow = startRow + tileWidth; // Define the starting col...
24,151
#include<iostream> //think about inlining this __device__ double* three_dim_indexGPU(double* matrix, int i, int j, int k, double m, int b){ int m_int = (int)m; double* p; //specify index layout here p=&matrix[(m_int)*b*(k)+(m_int)*(j)+(i)]; return p; } __device__ double* two_dim_indexGPU(double* vector, int i, in...
24,152
#include <stdio.h> #include <time.h> int main(void) { time_t t; time( &t ); printf("%ld\n", t); printf(ctime( &t )); }
24,153
#include <cuda.h> #include <time.h> #include <stdio.h> #include <stdlib.h> #include <math.h> //---------------------------------------------- // 排序 N 個 float 元素 (N=1~1025) // 使用到的記憶體大小為 SIZE 個 bytes // 只使用單一區塊 // 區塊大小為 N/2 //---------------------------------------------- #define N 1024 #define SIZE (N*sizeof(fl...
24,154
#include <stdio.h> #include <algorithm> #include <cstdlib> #include <curand.h> #include <curand_kernel.h> // In the following section, define the model Parameters #define N_AR 3 #define START_X 0.800, 0.900, 1.100 #define PHI -0.315415, 0.427606, 0.189134 #define C 1.500 // End model parameters unsigned int N_SIMS, N...
24,155
#include <stdio.h> #define cudaCheck(ans) { cudaAssert((ans), __FILE__, __LINE__); } inline void cudaAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { fprintf(stderr,"cudaAssert: %s at %s:%d\n", cudaGetErrorString(code), file, line); if (abort) exit(code); ...
24,156
// A "hello world" style CUDA program #include <stdio.h> #include <stdlib.h> // Define a kernel function __global__ void vector_add(float* A, float* B, float* C) { // Add two vectors together and store in a third // Our ID is unique to our thread int i = threadIdx.x; C[i] = A[i] + B[i]; } int main() { // Th...
24,157
#include "includes.h" __global__ void pow_kernel(float *v, int n, float e) { int x(threadIdx.x + blockDim.x * blockIdx.x); if (x >= n) return; v[x] = ::pow(v[x], e); }
24,158
#include<stdio.h> #define MIN(a,b) (a<b?a:b) #define MAX(a,b) (a>b?a:b) __device__ size_t string_len(const char *str){ const char *s; for(s=str; *s; ++s); return (s-str); } __device__ char* string_copy(char *dest, const char *src, size_t n){ size_t k; for(k=0; k < n && src[k] != '\0'; k++){ dest[k] = s...
24,159
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <thrust/sort.h> using namespace std; /********************************************************** *********************************************************** error checking stufff ********************************************************...
24,160
#include "includes.h" __global__ void kernelMultMat(int *a, int *b, int *c,int m){ int i,add; int col=blockDim.x*blockIdx.x + threadIdx.x; int row=blockDim.y*blockIdx.y + threadIdx.y; if(col<m && row<m) { add=0; for(i=0; i< m ;i++){ add += a[i+m*row]*b[col+m*i]; } c[row*m+col] = add; } }
24,161
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <chrono> #define BLOCK_SIZE 16 //функция ядра __global__ void matrixMult(const double *A, const double *B, double *C, int n) { int ai = n * (blockDim.y * blockIdx.y + threadIdx.y); // ин...
24,162
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<random> #define cudaCheck(x) _cudaCheck(x, #x ,__FILE__, __LINE__) template<typename T> void _cudaCheck(T e, const char* func, const char* call, const int line){ if(e != cudaSuccess){ printf("\"%s\" at %d in %s\n\treturned %d\n-> %s\n", func, line...
24,163
#include "includes.h" __global__ void mult(int* results, int* data, int* vec) { int index = blockIdx.x * blockDim.x + threadIdx.x; int result_val = 0; for(int i = 0; i < cuda_features; i++) { result_val += vec[i] * data[(index * cuda_features) + i]; } results[index] = result_val; }
24,164
#include "includes.h" __global__ void kMultScalar(float* mat, float alpha, float* dest, 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) { dest[i] = alpha * mat[i]; } }
24,165
#include "includes.h" #define THREADS_PER_BLOCK 1024 #define TIME 3600000 __global__ void initialize(float *a_d, float *b_d, float *c_d, int arraySize) { int ix = blockIdx.x * blockDim.x + threadIdx.x; if(ix==0) { a_d[ix]=200.0; b_d[ix]=200.0; } else if (ix<arraySize) { a_d[ix]=0.0; b_d[ix]=0.0; } }
24,166
#include <iostream> #include <stdio.h> #include <sys/time.h> #define CUDA_CHECK(cmd) {cudaError_t error = cmd; if(error!=cudaSuccess) std::cout << cudaGetErrorString(error) << std::endl;} __global__ void kernelLineSliceFields(cudaPitchedPtr fieldE, cudaPitchedPtr fieldB, float3 *sliceDataField, dim3 globalCellIdOffse...
24,167
#include <stdio.h> #include <stdlib.h> #include <math.h> #ifndef N #define N 4096 #endif #ifndef FLOAT #define FLOAT double #endif #define sqrt_of_array_cell(x,j) ((FLOAT)sqrt(x[j])) #define FLOAT_N 3214212.01f #define EPS 0.005f /* Thread block dimensions for kernel 1*/ #define DIM_THREAD_BLOCK_KERNEL_1_X 256 #d...
24,168
#include<stdlib.h> #include<stdio.h> __global__ void kernel(int* array) { int index_x = blockIdx.x*blockDim.x + threadIdx.x; int index_y = blockIdx.y*blockDim.y + threadIdx.y; //map the two 2D indices to a single linear 1D index int grid_width = gridDim.x*blockDim.x; int index = index_y*grid_width + index_x; /...
24,169
#include "includes.h" __global__ void update_mixed_derivatives(double *temppsix, double *temppsiy, double *temppsixy, unsigned int nx, unsigned int ny, double dx, double dy, unsigned int TileSize) { unsigned int bx = blockIdx.x; unsigned int by = blockIdx.y; unsigned int tx = threadIdx.x; unsigned int ty = threadIdx.y...
24,170
__global__ void per_row_kernel(int m,int n,int *A,int *B,int *C){ int idr; idr=blockIdx.x*blockDim.x+threadIdx.x; if(idr<m){ for(int j=0;j<n;j++){ C[idr*n+j]=A[idr*n+j]+B[idr*n+j]; } } } __global__ void per_column_kernel(int m,int n,int *A,int *B,int *C){ int i...