serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
2,201
#include<stdlib.h> #include<stdio.h> #include<time.h> #include<unistd.h> __global__ void sumArraysOnGPUN(float *A,float *B,float *C,const int N){ int idx = blockIdx.x*blockDim.x+threadIdx.x; if(idx<N) C[idx] = A[idx] + B[idx]; printf(" %f + %f = %f On GPU:block %d thread %d\n",A[idx],B[idx],C[idx],blockIdx.x,th...
2,202
#include "includes.h" __global__ void increment_kernel(int *g_data, int inc_value) { int idx = blockIdx.x * blockDim.x + threadIdx.x; g_data[idx] = g_data[idx] + inc_value; }
2,203
/** * Multiply 2 matrices using CUDA. */ #include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #include <iostream> #include <string.h> typedef struct { int width; int height; float* elements; } Matrix; /** * This macro checks return value of the CUDA runtime call and exits ...
2,204
#include <stdio.h> #include <stdlib.h> #include <curand_kernel.h> // CURAND lib header file #define TRIALS_PER_THREAD 2048 #define BLOCKS 256 #define THREADS 256 #define PI 3.1415926535 // known value of pi __global__ void pi_mc(float *estimate, curandState *states) { unsigned int tid = threadIdx.x + blockDim.x*blo...
2,205
#include "includes.h" __global__ void Substep2Kernel (double *Dens, double *VradInt, double *VthetaInt, double *TemperInt, int nrad, int nsec, double *invdiffRmed, double *invdiffRsup, double *DensInt, int Adiabatic, double *Rmed, double dt, double *VradNew, double *VthetaNew, double *Energy, double *EnergyInt) { int j...
2,206
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> __global__ void print_details_of_wraps() { int gid = (blockIdx.y * gridDim.x * blockDim.x) + (blockDim.x * blockIdx.x) + threadIdx.x; int warp_id = threadIdx.x / 32; int gbid = blockIdx.y * gridDim.x + b...
2,207
//============================================================================ // Name : cudaProg.cpp // Author : Pratil // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #in...
2,208
#include <stdbool.h> #include <stdio.h> #include <string.h> #include <getopt.h> #include <curand_kernel.h> #include <stdlib.h> #include <cuda.h> #include <sys/time.h> #include "RoeStep.cu" #include<chrono> #include<iostream> using namespace std; using namespace std::chrono; int blocks_[20][2] = {{8,8},{16,16},{24,24},{...
2,209
#include <cuda_runtime.h> #include <stdio.h> #include <sys/time.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(-10*error);\ ...
2,210
#include "cuda.h" /*--------------------------------------------------------------------- ______ ______ _____ ______ _____ | ____|___ // ____| ____/ ____| | |__ / /| (___ | |__ | | __ | __| / / \___ \| __|| | |_ | | |____ / /__ ____) | |___| |__| | |______/_____|_____/|______\_____| GPU-en...
2,211
#include<stdio.h> #include<stdlib.h> int M,N; double *A, *AT; double *d_A, *d_AT; __global__ void MT(double *A, double *AT, int m, int n){ int idx = blockDim.x * blockIdx.x + threadIdx.x; if(idx < m){ for(int rows=0; rows<n; rows++){ AT[idx * n + rows] = A[idx + rows * m]; } } } int main(int argc, char *...
2,212
#include "includes.h" __global__ void kDot(const int nThreads, const float *m1, const float *m2, float *output, const int m1_rows, const int m1_columns, const int m2_columns) { for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < nThreads; i += blockDim.x * gridDim.x) { int r = (int)i / m2_columns; int c = i % m2_c...
2,213
#include <fstream> #include <sstream> #include <vector> #include "math.h" #include <limits> #include <float.h> __device__ double calculateMin(double *data, int col, int rows, int columns) { double calculatedMin = DBL_MAX; for (int i = 0; i < rows * columns; i += columns) { auto temp = data[i]; ...
2,214
#include <cuda.h> #include <stdio.h> #include <math.h> #include <sys/time.h> const int PARTITION_SIZE = 32; #define AT(mtx, width, row, column) \ mtx[(row) * (width) + (column)] inline double nowSec() { struct timeval t; struct timezone tzp; gettimeofday(&t, &tzp); return t.tv_sec + t.tv_usec*1e-6; } ...
2,215
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> __global__ void transpose(int *a, int *t){ int n = threadIdx.x, m=blockIdx.x, size = blockDim.x, size1 = gridDim.x; t[n*size1+m] = a[m*size+n]; } int main(){ int *a, *t, m, n; int *d_a, *d_t; pri...
2,216
#include "includes.h" __global__ void conflictDetection (int *vertexArray, int *neighbourArray, int *degreeCount, int n, int m, int *detectConflict){ int i= blockDim.x * blockIdx.x + threadIdx.x; if (i>=n){ return; } int myColour = degreeCount[i]; int start = -1, stop = -1; start = vertexArray[i]; stop = vertexA...
2,217
#include "includes.h" __global__ void floyd2DKernel(int * M, const int nverts, const int k){ int jj = blockIdx.x * blockDim.x + threadIdx.x; // indice filas int ii = blockIdx.y * blockDim.y + threadIdx.y; // indice columnas int tid = (ii * nverts) + jj; int i = tid/nverts; int j = tid - i * nverts; //printf ("Fila %u, ...
2,218
#include "cuda_MP5.cuh" //////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// int cuda_MP5(int argc, char* argv[]) { int num_elements = NUM_ELEMENTS; int errorM = 0; const unsigned int arra...
2,219
/* 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 ...
2,220
/* * Copyright (c) 2018 Preferred Networks, Inc. All rights reserved. */ #include <cuda_fp16.h> namespace chainer_trt { namespace plugin { template <typename T> __global__ void leaky_relu_kernel(const T* src_gpu, T* dst_gpu, int n_in, float slope) { const int id...
2,221
#include "includes.h" //#define _SIZE_T_DEFINED extern "C" { } __global__ void ShuffleRGB(float* input, float* output, int size) { int id = blockDim.x * blockIdx.y * gridDim.x + blockDim.x * blockIdx.x + threadIdx.x; if (id < size) { //int index = id / 3 + (id % 3) * (size / 3); output[id / 3 + (id % 3) * (size / 3)...
2,222
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <time.h> #define TIMER_CREATE(t) \ cudaEvent_t t##_start, t##_end; \ cudaEventCreate(&t##_start); \ cudaEventCreate(&t##_end); #define TIMER_START(t) \ cudaEventRecord(t##_start); ...
2,223
#include <stdio.h> #include <stdlib.h> #include <iostream> __global__ void block_scan( unsigned long long *g_odata, unsigned long long *g_idata, unsigned long long n, unsigned long long *block_sums){ __shared__ unsigned int temp[1024]; int tid = threadIdx.x; int offset = 1; int blo...
2,224
#include "includes.h" __global__ void d_count_kernel(unsigned int * d_pivots, int * r_buckets, int pivotsLength, unsigned int * r_indices, unsigned int * r_sublist, unsigned int * d_in, int itemCount) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < itemCount) { unsigned int element = d_in[idx]; unsigned in...
2,225
#include <stdio.h> #include <stdlib.h> #define N 256 __global__ void kernel(int *a, int *b, int *c){ __shared__ int s[N]; __shared__ int r[N]; int t =threadIdx.x; r[t]=b[t]; s[t]=a[t]; __syncthreads(); c[t]=s[t]+r[t]; } int main (void) { //const int n=64; int a[N],c[N],b[N],i; for(i=0;i<N;i++) { a[i]=i; ...
2,226
#include <stdio.h> #include <stdlib.h> int main(void) { int num_elements = 16; int num_bytes = num_elements * sizeof(int); int *device_array = 0; int *host_array = 0; // malloc host memory host_array = (int *)malloc(num_bytes); // cudaMalloc device memory cudaMalloc((void **)&device_array, num_bytes...
2,227
/* #include <omp.h> #include <stdio.h> main(int argc, char *argv[]) { int nthreads, tid; #pragma omp parallel private(tid) { tid = omp_get_thread_num(); printf("Hello World from thread = %d\n", tid); if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads...
2,228
#include <stdlib.h> #include <stdio.h> #include <math.h> //Thread block size #define BLOCK_SIZE 3 #define WA 10 // Matrix A width #define HA 10 // Matrix A height #define WB 10 // Matrix B width #define HB WA // Matrix B height #define WC WB // Matrix C width #define HC HA // Matrix C height //Allo...
2,229
#include <fstream> #include <iostream> #include <chrono> # include <mutex> #include <stdio.h> #include <string.h> using namespace std; # define NO_OF_CHARS 256 char* getFileContents(const char*); // preprocessing function __device__ void badCharHeuristic(char* str, int size, int badchar[NO_OF_CHARS]) { int i; ...
2,230
#include "includes.h" __global__ void kernel2( int *a, int dimx, int dimy ) { int ix = blockIdx.x*blockDim.x + threadIdx.x; int iy = blockIdx.y*blockDim.y + threadIdx.y; int idx = iy*dimx + ix; a[idx] = (blockIdx.x + blockIdx.y); }
2,231
#include<stdio.h> #include<cuda_runtime.h> int main(void){ int deviceCount; cudaDeviceProp deviceProp; cudaGetDeviceCount(&deviceCount); cudaGetDeviceProperties(&deviceProp,0); printf("There are %d gpu devices\n",deviceCount); printf("Device %s has %f GB of global memory\n", devic...
2,232
#include "includes.h" __global__ void mul_sub(float* in1, float* in2, float* out, int in1ScalarCount, int in2ScalarCount) { int tid = blockIdx.x * blockDim.x + threadIdx.x; int stride = gridDim.x * blockDim.x; for (; tid < in1ScalarCount; tid += stride) { out[tid] = in1[tid] * in2[tid % in2ScalarCount]; } }
2,233
__global__ void copyToOpenMM( float *target, float *source, int N ) { int elementNum = blockIdx.x * blockDim.x + threadIdx.x; int atom = elementNum / 3; if( elementNum > N ) { return; } //else target[elementNum] = source[elementNum]; else { target[4 * atom + elementNum % 3] = sou...
2,234
//%%cu #include <iostream> #include <cuda.h> #include<bits/stdc++.h> using namespace std; float device_time_taken; struct edgepairs{ int x; int y; int wt; }; bool compareTwoEdgePairs(edgepairs a, edgepairs b) { if (a.x != b.x) return a.x < b.x; if (a.y != b.y) return a.y < b.y; ret...
2,235
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> __global__ void transpose(int *a, int *t) { int n = threadIdx.x, m = blockIdx.x, size = blockDim.x, size1 = gridDim.x; t[n*size1 + m] = a[m*size+n]; } int main (void) { int *a, *t, m, n; int *d_a, *d_t; print...
2,236
#include <stdlib.h> #include <stdio.h> #include <sys/time.h> /* change dimension size as needed */ const int dimension = 512 ; const int blocksize = 32; const int K = 1; struct timeval tv; __global__ void gpuMM(float *A, float *B, float *C, int N) { // Matrix multiplication for NxN matrices C=A*B // Each thread ...
2,237
#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_NUM_BLOCKS_FLOAT 70 //#include "global_sync.cu" #define WARP_SIZE_FLOAT 32 #define NUM_THREADS_FLOAT 512 #define NUM_WARPS_FLOAT (NUM_THREADS_FLOAT / WARP_SIZE_FLOAT) #define LOG_NUM_THREADS_FLOAT 9 #define LOG_NUM_WARPS_FLOAT...
2,238
#include <iostream> #include <cuda.h> #include <cstdlib> #include <stdlib.h> #include <time.h> int SIZE = 2; __global__ void vecAddK(float *A, float *B, float *C, int len) { int i = threadIdx.x+blockDim.x*blockIdx.x; if(i<len) C[i] = A[i] + B[i]; } __host__ void vecAdd(float *h_A, float *h_B, float *h_C, i...
2,239
__global__ void kernelForMSSP(int *V, int *E, int *W, int *n, int *src, int *sn, bool *visit, int *dist, int *predist){ int u=0, stInd=0, st=0, align=0, old=0; __shared__ int QuickExit; const int blockId = blockIdx.z *(gridDim.x * gridDim.y) + blockIdx.y * gridDim.x + blockIdx.x; const int threadId = ...
2,240
/* #ifndef __CUDACC__ #define __CUDACC__ #endif #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <conio.h> const int TILE_WIDTH=2; const int width=4; __global__ void matrixmul(int *d_M,int *d_N,int *d_P) { __shared__ int dS_M[TILE_WIDTH][TILE_WIDTH]; __shared__ int dS...
2,241
#include<stdio.h> __global__ void Array_add(int *a, int *b, int *c, int *n) { unsigned short tid = threadIdx.x; if(tid < *n) c[tid] = a[tid] + b[tid]; } int main() { int n = 5, i; int a[n], b[n], c[n]; int *cuda_a, *cuda_b, *cuda_c, *cuda_n; for(i=0; i<n; i++) a[i] = rand()%100; ...
2,242
/****************************************************************************** *cr *cr (C) Copyright 2010-2013 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr ***************************************************************...
2,243
//errorcheck_soln.cu: This program is designed to produce output //'data = 7'. Error checking has been added and all errors have //been removed. #include <stdio.h> #include <stdlib.h> __global__ void setData(int *ptr) { *ptr = 7; } int main(void) { int *data_d = 0; int *data_h = 0; cudaError_t error; //UINT...
2,244
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /* demo to show the usage of share memory*/ #define DEBUG typedef float dataType; void checkCudaError(cudaError_t error, const char* filename, const int linenum) { if(error != cudaSuccess){ printf("File: %s, line: %d, CUDA error: %s\...
2,245
#include<bits/stdc++.h> __global__ void gpufib(){ double a,b,c; a=0;b=1; for(long long int i=0;i< (1<<29);i++){ c=a+b; a=b; b=c; } } int main(){ gpufib<<<1,1>>>(); cudaDeviceSynchronize(); std::cout<<"Done"; }
2,246
#include <cuda_runtime.h> #include <stdio.h> #include <cuda.h> __global__ void check(double* d_norm, int n, double* val) { double temp = 0; double f ; for(int i=0; i<n; i++) { f = d_norm[i]; temp += f*f; } *val = sqrt(temp); //if(*val <= 0) *val *= -1; } __global__ void ca...
2,247
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand.h> #include <math.h> #define N 1000000 __global__ void counts(float *x, float *y, int *results) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if(tid < N) { float result = x[tid] * x[tid] + y[tid] * y[tid]; if(result <=...
2,248
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <iostream> #include <chrono> int main() { std::vector<double> stocks_a; std::vector<double> stocks_m; int n = 0; double stock_a; double stock_m; while (std::cin){ n = n + 1; std::cin >> stock_a; ...
2,249
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> //__global__ void AddVec(const float* A, const float* B, float* C, int N) //{ // int i = blockDim.x * blockIdx.x + threadIdx.x; // if (i < N) // C[i] = A[i] + B[i]; //} int main() { return 0; }
2,250
#include "includes.h" __global__ void reduceUnrolling8New (int *g_idata, int *g_odata, unsigned int n) { // set thread ID unsigned int tid = threadIdx.x; unsigned int idx = blockIdx.x * blockDim.x * 8 + threadIdx.x; // convert global data pointer to the local pointer of this block int *idata = g_idata + blockIdx.x * b...
2,251
#include "includes.h" __global__ void _bcnn_backward_depthwise_conv_weight_kernel( int nthreads, float *dst_grad, float *src_data, int batch_size, const int channels, int dst_h, int dst_w, const int src_h, const int src_w, int kernel_sz, int stride, int pad, float *weight_diff) { int i, n, c, h, w, kw, kh, h_out_s, w_o...
2,252
struct VMState { int a; float *b; }; static const int kOpsPerThread = 1; __device__ void a0(const VMState& vm) { vm.b[vm.a] = 0.; } __device__ void a1(const VMState& vm) { vm.b[vm.a] = 1.; } __device__ void a2(const VMState& vm) { vm.b[vm.a] = 2.; } __device__ void a3(const VMState& vm) { vm.b[vm.a] = 3.; } __dev...
2,253
__global__ void cudaWarp(double * warpedImg, const double * indBase, const double * img, const double *resImg1, const double * tri, const double * nTri, const double * pixelTri, const double * x, const double * y, const double * alphas, const double * betas, const double * gammas, const double * idMax) { int id = ...
2,254
/** * Simple example provided by NVIDIA for profiling and understanding GPU acceleration. * Source: https://devblogs.nvidia.com/even-easier-introduction-cuda/ * Retrieved: 30 June 2018 */ #include <iostream> #include <math.h> #include <stdio.h> // Kernel function to add the elements of two arrays __global__ void ...
2,255
#include<cuda.h> #include<stdio.h> #include<stdlib.h> #include<iostream> float *hs_device, *gs_device; double *hd_device, *gd_device; const unsigned int SINGLE_PRECISION = 1; const unsigned int DOUBLE_PRECISION = 0; //generate matrix template<typename T> T *GenMatrix(const unsigned int width, const unsigned int heigh...
2,256
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "curand.h" #include <cstdio> #include <ctime> // global counter to count points that fall into circle __device__ int dnum = 0; __global__ void countPoints(float* xs, float* ys) { int idx = threadIdx.x + blockDim.x * blockIdx.x; float x =...
2,257
#include "includes.h" #define BLOCK_SIZE_X 16 #define BLOCK_SIZE_Y 16 __global__ void gameOfLifeKernel(unsigned char* d_src, unsigned char* d_dst, const size_t width, const size_t height) { extern __shared__ unsigned char board_sh[]; size_t glob_x = blockDim.x * blockIdx.x + threadIdx.x; size_t glob_y = blockDim.y ...
2,258
#include <cuda.h> #include <stdio.h> #include <string.h> #define ITERS 32768 char* concat(const char *s1, const char *s2) { char *result = (char*)malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator // in real code you would check for errors in malloc here strcpy(result, s1); strcat(resu...
2,259
#include "assignments.cuh" #include <math.h> #include <string.h> #include <stdio.h> #include <assert.h> //The two different definitions seem to have no noticable performance differnce. //abs(a) has a tiiiny performance drop vs the other, but it's not worth being so hw-implementation specific //for it. //#define FAST_...
2,260
extern "C" { __global__ void vsign(const int n, const double *a, double *b) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i<n) { if (a[i]<0) {b[i]=-1.0;} else {if (a[i]>0) {b[i]=1.0;} else {b[i]=0.0;} } } } }
2,261
#include <iostream> #include <fstream> #include <math.h> #include <cstdio> #include <ctime> #include <assert.h> /* assert */ using namespace std; //0 3 6 //1 4 7 //2 5 8 // row idx: i // col idx: j __global__ void _mask_conv(float diag_coef_1, float diag_coef_2, float side_coef_1, float side_coef_2, int N, float *...
2,262
#include <stdio.h> #include <cuda_runtime.h> #include <time.h> #include <vector> using namespace std; const int GPUs[] = {0,1,2,3,4}; // If left blank all available GPUs will be used. vector<int> g(GPUs, GPUs + sizeof(GPUs)/sizeof(int)); void configure(size_t size, vector<int*> &buffer_s, vector<int*> &buffer_d, ...
2,263
/* 2013 * Maciej Szeptuch * II UWr * ---------- * bez shared, pozbywanie sie jak najwiecej pamieci + loop unrolling * czasy okolo 10x szybciej niz na CPU. word | gpu | cpu | distance ------------------|--------------------------------|----------...
2,264
/* Write GPU code to perform the step(s) involved in counting sort. Add additional kernels and device functions as needed. */ __global__ void counting_sort_kernel(int *histogram, int *input_array, int length) { int tx = blockIdx.x * blockDim.x + threadIdx.x; if (length <= tx) { return; } atomicAdd(&histog...
2,265
/** * @author Alejandro Brugarolas * @since 2019-12 */ #include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #define N 1024 __global__ void arrayReduction(float *d_array){ int idx = threadIdx.x; int idx2 = 0; for (int i = blockDim.x; i >= 1 ; i /=2) { if (idx < i){ idx2 ...
2,266
extern "C" { __global__ void gscale(const int lengthB, const double *a, double *b) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i<lengthB) { b[i] = a[0]*b[i]; // REMEMBER ZERO INDEXING IN C LANGUAGE!! } } }
2,267
#include <cuda.h> #include <stdio.h> #define NUM 4 __global__ void clzKernel(int *uA, int *uB) { unsigned tid = threadIdx.x; uB[tid] = __clz(uA[tid]); } __global__ void ffsKernel(int *uA, int *uB) { unsigned tid = threadIdx.x; uB[tid] = __ffs(uA[tid]); } __global__ void popcKernel(unsigned *uA, unsigned *...
2,268
/* ============================================================================ Filename : implementation.cu Author : Romain Jufer SCIPER : 229801 ============================================================================ */ #include <iostream> #include <iomanip> #include <sys/time.h> #include <cuda_run...
2,269
/* xor_pcases_ref.cu Implementation of a XOR neural network in CUDA, calculating output of many input cases in parallel. (Refactored version.) Andrei de A. Formiga, 2012-03-31 */ #include <stdio.h> // weights for the hidden layer float weights_h[] = { 0.5f, -1.0f, -1.0f, -1.5...
2,270
#include <iostream> #include <complex> #include <math.h> #include <thrust/complex.h> #include <sys/time.h> #include <cassert> #include <cufft.h> using namespace std; int main(){ int n;cin>>n; cufftComplex *data_host = (cufftComplex*) malloc (sizeof (cufftComplex)* n); cufftComplex *data_back = (cufftComplex*) ma...
2,271
#ifdef _GLIBCXX_USE_INT128 #undef _GLIBCXX_USE_INT128 #endif #ifdef _GLIBCXX_ATOMIC_BUILTINS #undef _GLIBCXX_ATOMIC_BUILTINS #endif #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <cstdlib> int main(void) { // generate random data on...
2,272
__device__ __host__ inline double cal_mean(const double *observations, int n_observations){ double mean = 0; for(int o = 0; o < n_observations; o++){ mean += observations[o]; } mean /= double(n_observations); return mean; } __device__ __host__ inline double cal_variance(const double *observations, int n_...
2,273
// Stolen from Seb /*#include <cstdint>*/ #include <stdint.h> #define WARP_SIZE 32 // macro function #define min(a,b) (a > b ? b : a); // ------------------------------------------------------------------- // helper functions // ------------------------------------------------------------------- // Get largest mem...
2,274
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define THREAD 128 __global__ void dot(int N,float *x,float*y,float *ans); int main(void){ /*for CPU*/ int i; int size = 1024; int block = (size + THREAD -1);//number of block float *x,*y,*ans;//(x,y) float z; cudaMallocHost((...
2,275
#include <stdio.h> // Print device properties void printDevProp(cudaDeviceProp devProp) { printf("Major revision number: %d\n", devProp.major); printf("Minor revision number: %d\n", devProp.minor); printf("Name: %s\n", devProp.name); printf("Total global memo...
2,276
// linear algebra calculation on GPU devices // By Zheshu Wu, Jun 1, 2018 #include<stdio.h> #define N 33 * 1024 __global__ void add(int *a, int *b, int *c) { // int tid = 0; // CPU zero, so we start at zero // while (tid < N) // { // c[tid] = a[tid] + b[tid]; // tid += 1; // we have one CPU, so we increment b...
2,277
// What if we are given a device pointer that is offset from any of the device pointers we provided to the client? // // This file is a test-case for this. Then we can look at handling that... #include <iostream> #include <memory> #include <cassert> using namespace std; #include <cuda.h> // __global__ void getValu...
2,278
#include <stdio.h> #include <time.h> __global__ void matrixMultiply(int *matrix1, int *matrix2, int *matrix3, int m, int p) { int sum=0; int i = blockIdx.x*64 + threadIdx.x; for (int j = 0; j < p; j++) { for (int k = 0; k < m; k++) { sum = sum + matrix1[m*i+k]*matrix2[p*...
2,279
#include <stdio.h> #include "cuda_runtime.h" // CUDA Kernel Function __global__ void add(int *a, int *b, int *c){ int i = threadIdx.x; c[i] = b[i] + a[i]; } // main Function int main(){ // define A, B, and C // These are three array and we will do A + B = C int A[5] = {1, 2, 3, 4, 5}; int B...
2,280
#include<iostream> #include<cuda.h> using namespace std; __global__ void add(int *a,const int *b){ int i=blockIdx.x; a[i]+=b[i]; } int main(){ const int N=10; int *a,*b,*temp; temp=new int[N]; cudaMalloc(&a,N*sizeof(int)); cudaMalloc(&b,N*sizeof(int)); for(int i=0;i<N;i++) ...
2,281
#include "includes.h" __global__ void Overlay_Cuda( int x_position, int y_position, unsigned char* main, int main_linesize, unsigned char* overlay, int overlay_linesize, int overlay_w, int overlay_h, unsigned char* overlay_alpha, int alpha_linesize, int alpha_adj_x, int alpha_adj_y) { int x = blockIdx.x * blockDim.x + ...
2,282
#include "includes.h" __global__ void BitonicMergeSort(float * d_output, float * d_input, int subarray_size) { extern __shared__ float shared_data[]; // internal index for sorting of the subarray int index = threadIdx.x; int index_global = index + blockDim.x * blockIdx.x; double portions = log2(double(subarray_size)) ...
2,283
#include "includes.h" __global__ void cudaAcc_dev_t_funct(float PulseThresh, int PulseMax, int di, float *dev_t_funct_cache, float pulse_display_thresh) { // do nothing }
2,284
__global__ void getSortedDegree(int numNodes, int *offset, int *workspace1, int *workspace2, int *workspace3) { for(int i=blockDim.x*blockIdx.x+threadIdx.x; i<numNodes; i++) { // initiate all workspace to 0 workspace1[i] = 0; workspace2[i] = 0; workspace3[i] = 0; // compute each neighlist's length int n...
2,285
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <iostream> #include <ctype.h> #include <vector> #include <string> #include <chrono> typedef std::vector<double> double_vec; int main() { double_vec stocks; std::string value; while (true) { std::getline(std::cin, value)...
2,286
// Matrix Multiplication in gpu with 2D grid of blocks with 1D block shape // Compile with: nvcc -o test matrix_multiplication_2D_2D.cu -std=c++11 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <chrono> // Multiplies matrices using GPU with 2D grid __global__ void multiply_matr...
2,287
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <stdio.h> // utility function provided by https://gist.github.com/jefflarkin/5390993 #define cudaCheckError() { \ cudaError_t e=cudaGetLastError(); \ if(e!=cudaSucce...
2,288
////////////// Parallelization of PageRank Algorithm using CUDA and OpenMp ///////////////////////// #include <iostream> #include <fstream> #include <string> #include<stdlib.h> #include<bits/stdc++.h> #include <stdio.h> #include<time.h> #include <sys/time.h> using namespace std; #define TILE_WIDTH 32 #define gp...
2,289
#ifndef MarshalStructs_H #define MarshalStructs_H #include <cuda_runtime.h> class SoundPacketStruct{ public: __host__ __device__ SoundPacketStruct(float _amplitude): amplitude(_amplitude), minRange(0.0f), maxRange(1.0f) { } __host__ __device__ SoundPacketStruct(float _amplitude, float _minRange, float _maxRange) :...
2,290
//#include "bits/stdc++.h" //#include<iostream> //#include<string> #include<stdio.h> #include<stdlib.h> extern "C" //typedef struct testStruct{ // int x; //}testStruct; __global__ void gpu(float* input, float* output, int* startPoints, int* endPoints, float* distancePoints){ int block = blockIdx.x; output[block...
2,291
#include<fstream> #include<iostream> #include<vector> #include<ctime> #include<cmath> using namespace std; int N; vector<float> readVector(ifstream &fin) { //fin.open(); int n; int c; fin>>n; vector<float> result; for (int i=0;i<n;i++){ fin>>c; result.push_back(c); ...
2,292
#include "reader.cuh"
2,293
#include "includes.h" __global__ void histogram(const float* d_in, unsigned int* d_out, const float lumMin, const float lumRange, const size_t numBins, const size_t size) { int abs_x = threadIdx.x + blockDim.x * blockIdx.x; if (abs_x > size) { return; } int bin = (d_in[abs_x] - lumMin) / lumRange * numBins; //then i...
2,294
#include "asset.cuh" #include <math.h> #include <numeric> #include <algorithm> #include <stdio.h> namespace fin { CUDA_CALLABLE_MEMBER Asset::Asset(int id) { this->id = id; this->size = 0; this->closes = 0; } CUDA_CALLABLE_MEMBER Asset::Asset() { this->id = -1; this->size = 0; this->closes = 0; } CUD...
2,295
#include <stdio.h> #include <stdlib.h> #include <cuda.h> //nvcc -o mutual_outlinks mutual_outlinks.cu -arch sm_20 //find mean number of mutual outlinks //among all pairs of websites //checking all (i,j) pairs //thread k will handle all i such that //i%totth = k, where totth is the number of threads __global__ void...
2,296
// mmm_cuda.cu, Crispin Bernier, chb2ab #include <stdio.h> #include <sys/time.h> #include <stdlib.h> #include <iostream> using namespace std; //----------------------------------- Structures and Globals--------------------------------------------- typedef struct { int dimension1; int dimension2; } ArrayMetadata2D...
2,297
#include <stdio.h> #include <fstream> #include <time.h> // Generic utils typedef float3 pixel; void check_result(cudaError_t value) { cudaError_t status = value; if (status != cudaSuccess) { printf("Error %s at line %d in file %s\n", cudaGetErrorString(status), __LINE__, __FILE__); // exit(1); } } __devi...
2,298
#include <iostream> #include <cstdlib> #include <ctime> #include "cuda_runtime.h" #define VEC_SIZE 20000 #define START 1 #define STOP 100 using namespace std; __global__ void vect_mul(int *arr_a, int *arr_b, int *arr_c) { arr_c[threadIdx.x] = arr_a[threadIdx.x] * arr_b[threadIdx.x]; } int main() { int *arr_...
2,299
#include <stdlib.h> #include <iostream> using namespace std; __global__ void Plus(float A[], float B[], float C[], int n) { int i = blockDim.x * blockIdx.x + threadIdx.x; C[i] = A[i] + B[i]; } int main() { float*A, *Ad, *B, *Bd, *C, *Cd; int n = 1024 * 1024; int size = n * sizeof(float); // ...
2,300
#include <iostream> #include <cuda_runtime_api.h> using namespace std; __global__ void kernel(int* a, int n) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if ( tid < n) { a[tid] = a[tid] + tid; printf("a[i] = %d\n", a[tid]); } } int main() { const int n = 100; int a[n]; int *dev_a; // started value...