serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
4,401
#include "includes.h" __global__ void add(float *loc, float *temp, const int num) { int idx = blockIdx.x*blockDim.x+threadIdx.x; if(idx < num) { atomicAdd(loc,temp[idx]); } }
4,402
#include <stdio.h> static void HandleError( cudaError_t err, const char *file, int line ) { if (err != cudaSuccess) { printf( "%s in %s at line %d\n", cudaGetErrorString( err ), file, line ); exit( EXIT_FAILURE ); } } #define HAND...
4,403
//#include "Mandelbrot.h" // //#include <iostream> // //using std::cout; //using std::endl; // ///*----------------------------------------------------------------------*\ // |* Declaration *| // \*---------------------------------------------------------------------*/ // ///*------------------------------------...
4,404
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #define N 1024 __global__ void saxpy(float *d_x, float *d_y){ int tid = blockIdx.x * blockDim.x + threadIdx.x; if (tid < N) d_y[tid] = d_x[tid] * 2.0f + d_y[tid]; } int main(){ float *h_y, *h_x; float *d_y, *d_x; int memSize = sizeo...
4,405
//Got Help from Henry #include <stdio.h> //Standard Input/Output Lib #include <stdlib.h> //Standard Lib #define N 3 //Dimensions for row matirx #define M 3 //Dimensions for column matrix /* Call Kernal and pass in flat A matrix and B vector Matrix Multiply A and B and store output in C array */ __global__ void mat...
4,406
#include "includes.h" __global__ void sequence_gpu(int *d_ptr, int length) { int elemID = blockIdx.x * blockDim.x + threadIdx.x; if (elemID < length) { d_ptr[elemID] = elemID; } }
4,407
#include <iostream> int main() { int devices; cudaGetDeviceCount(&devices); cudaDeviceProp prop; cudaGetDeviceProperties(&prop, 0); printf(" Device name: %s\n", prop.name); printf(" Memory Clock Rate (KHz): %d\n", prop.memoryClockRate); printf(" Memory Bus Width (bits): %d\n", prop.mem...
4,408
#include "includes.h" __global__ void Bprop1(const float* dlayer1, const float* dlayer1i, const float* dlayer1o, const float* in, float* dsyn1, float* dsyn1i, float* dsyn1o, const float alpha) { int i = blockDim.y*blockIdx.y + threadIdx.y; //64 int j = threadIdx.x; //256 int k = blockIdx.x; ...
4,409
#include <stdio.h> #include <CL/cl.h> extern int N; #define CHECK_ERROR(err) \ if (err != CL_SUCCESS) { \ printf("[%s:%d] OpenCL error %d\n", __FILE__, __LINE__, err); \ exit(EXIT_FAILURE); \ } char *get_source_code(const char *file_name, size_t *len) { char *source_code; size_t length; FILE *file ...
4,410
#include "includes.h" /* * This file is an attempt at producing what the generated target code * should look like for the multiplyMatrixMatrix routine. */ /* Prototype matrix representation. */ struct dag_array_t{ size_t rows; size_t cols; int* matrix; }; /* DAG Primitive. Here, we leverage the NVIDIA developer examp...
4,411
#include <stdio.h> #include <cuda.h> //----------------------------------------------------------------------------- // TheKernel: basic kernel containing a print statement. //----------------------------------------------------------------------------- __global__ void TheKernel() { // Give the kernel something to k...
4,412
#include "includes.h" __global__ void device_apply_scale(float* coords, float scale, size_t total_size){ for(size_t i = blockIdx.x * blockDim.x + threadIdx.x; i < total_size; i += blockDim.x * gridDim.x){ coords[i] = coords[i] * scale; } __syncthreads(); }
4,413
/****************************************************************************** /* @file Impl of gaussian_blur.cuh /* /* There can be a lot optmized (e.g. for separable filters) but the current /* implementation is quite straight forward and simple, leading to /* okay-ish results. /* /* TODO rename /* /* @author la...
4,414
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdio.h> #define M 16 //row #define N 16 #define THREAD_PER_BLOCK_X 2; #define THREAD_PER_BLOCK_Y 2; __global__ void transposeMatrix(int *a, int *c) { int row = blockIdx.x * blockDim.x + threadIdx.x; int column = blockId...
4,415
#include <stdio.h> #define SIZE 1024 __global__ void VectorAdd(int *a, int *b, int *c, int n) { int i = threadIdx.x; if (i < n) c[i] = a[i] + b[i]; } int *a, *b, *c; int main() { // init a = (int *)malloc(SIZE * sizeof(int)); b = (int *)malloc(SIZE * sizeof(int)); c = (int *)malloc(S...
4,416
extern "C" __global__ void hitsearch_float64(const int n, const double* spectrum, const double threshold, const double drift_rate, double* maxsnr, double* maxdrift, unsigned int* tot_hits, const float median, const float stddev) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim....
4,417
// centroid: [ 92.6200991 -157.6624484 -666.61104378] // scale: [1.38349843 0.99729681 2.00067234 inline __host__ __device__ float3 operator-(float3 a, float3 b) { return make_float3(a.x - b.x, a.y - b.y, a.z - b.z); } inline __host__ __device__ float3 cross(float3 a, float3 b) { return make_float3(a.y*...
4,418
#include <stdio.h> __global__ void kernel(double *a, int n, double k) { int idx = threadIdx.x + blockIdx.x * blockDim.x; int idy = threadIdx.y + blockIdx.y * blockDim.y; int offsetx = blockDim.x * gridDim.x; int offsety = blockDim.y * gridDim.y; int i, j; for(i = idx; i < n; i += offsetx) for(j = idy; j < n; j...
4,419
// Add with a single thread on the GPU #include <stdio.h> __global__ void add(int a, int b, int *c) { *c = a + b; } int main() { int c; // host copies int *dev_c; // device copies int size = sizeof(int); // Allocate space on device cudaMalloc((void **) &dev_c, size); // Launch add() on GP...
4,420
extern "C" __global__ void getIndex(int *out, int N) { int myblock = blockIdx.x + blockIdx.y * gridDim.x; int blocksize = blockDim.x * blockDim.y * blockDim.z; int subthread = threadIdx.z*(blockDim.x * blockDim.y) + threadIdx.y*blockDim.x + threadIdx.x; int idx = myblock * blocksize + subthread; ...
4,421
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <unistd.h> #include <sys/time.h> /* Problem size. */ #define NX 4096 #define NY 4096 #ifndef M_PI #define M_PI 3.14159 #endif const unsigned int THREADS_PER_BLOCK = 64; void init_array(double *x, double *A) { int i, j; for (i =...
4,422
//optimization homework #4 cs 677 Theodore Jagodits #include <stdio.h> #include <stdlib.h> #include "string.h" #include <iostream> #define DEFAULT_SIZE 128 #define TILE_SIZE 16 __global__ void unknown_algo(float *inp1, float *inp2, float *result, int size){ // make shared int id = blockIdx.x * blockDim.x + threadI...
4,423
#include "includes.h" __global__ void stencil_1d(int *in, int *out){ __shared__ int temp[BLOCK_SIZE + 2 * RADIUS]; int gindex = threadIdx.x + blockIdx.x * blockDim.x; int lindex = threadIdx.x + RADIUS; // Debugging---------------------- //int *debug_sample = (int *)malloc(3*sizeof(int)); // Read input elements into ...
4,424
#include "includes.h" __global__ void Subsample_Bilinear_uchar4(cudaTextureObject_t uchar4_tex, uchar4 *dst, int dst_width, int dst_height, int dst_pitch, int src_width, int src_height) { int xo = blockIdx.x * blockDim.x + threadIdx.x; int yo = blockIdx.y * blockDim.y + threadIdx.y; if (yo < dst_height && xo < dst_wid...
4,425
/********************************************************************** * DESCRIPTION: * Serial Concurrent Wave Equation - C Version * This program implements the concurrent wave equation *********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math...
4,426
#include <iostream> #include <fstream> #include <vector> #include "vertex.cuh" int main() { std::ifstream vertsFile("verts.bin", std::ios::binary | std::ios::in | std::ios::ate); char* rawBytes = nullptr; if (vertsFile.is_open()) { auto end = vertsFile.tellg(); rawBytes = new char[end]; vertsFile....
4,427
#include <stdio.h> #include <stdlib.h> #define NUM 1048576 #define NUM_THREADS 512 #define NUM_BLOCKS 2048 /* Function to sort threads in each block using merge sort */ __global__ void sort_blocks(int *a) { int i=2; __shared__ int temp [NUM_THREADS]; while (i <= NUM_THREADS) { if ((threadIdx.x % i)==0...
4,428
#include <stdio.h> #include <stdlib.h> __global__ void add(int *d_a, int *d_b, int *d_c){ int index = threadIdx.x + blockIdx.x * blockDim.x; d_c[index] = d_a[index] + d_b[index]; } int main(int argc, char ** argv){ int N = 12; int size = N * sizeof(int); int a[N], b[N], c[N]; int *d_a, *d_b, *d_c; //A...
4,429
__global__ void exemple(void){ int identifiant_local = threadIdx.x; int identifiant_global = blockIdx.x * blockDim.x + threadIdx.x; } int main(){ exemple<<<512,512>>>(); return 0; }
4,430
#include "includes.h" __global__ void rotatewin(float* aframe2, float *aframe, float *win, int N, int offset){ int k = threadIdx.x + blockIdx.x*blockDim.x; aframe2[(k+offset)%N] = win[k]*aframe[k]; }
4,431
#include "includes.h" __global__ void fillarray_kernel(float *x, float v, int np) { int ii = threadIdx.x + blockIdx.x * BLOCKSIZE; while (ii < np) { x[ii] = v; ii += BLOCKSIZE * gridDim.x; //grid strides } }
4,432
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/copy.h> #include <thrust/fill.h> #include <thrust/sequence.h> #include <thrust/partition.h> #include <iostream> #include <math.h> #include <thrust/generate.h> __device__ int getGlobalIdx(){ int numInRow = blockDim.x * gridDim.x; ...
4,433
/* * dist.cu */ #include <math.h> #include <stdlib.h> // arithmetic modulus __device__ double arithmeticfmod(double x, double d) { double angle = fmod(x, d) ; if (angle < 0) { angle += d; } return angle; } // Euclidean distance __device__ double euclidean_distance(const double* v, const double* u, int...
4,434
__global__ void kernel(int *a, int *b) { if(threadIdx.x == 0) { a[threadIdx.x] = 0; } a[threadIdx.x] = b[threadIdx.x]; a[threadIdx.x] = b[2*threadIdx.x]; if(threadIdx.x%2 == 0) { a[threadIdx.x] = 0; } } int main() { int a[10] = {2}; int b[10] = {1}; int *a_d; i...
4,435
/** * Author: Kapil Gupta <kpgupta98@gmail.com> * Organization: XantheLabs * Created: January 2017 */ #pragma once #ifndef HOUGH_PEAKS_H_ #define HOUGH_PEAKS_H_ #endif // HOUGH_PEAKS_H_
4,436
#include "includes.h" /* Kintsakis Athanasios AEM 6667 */ #define inf 9999 __global__ void funct(int n, int k, float* x, int* qx) { int ix= blockIdx.x*blockDim.x + threadIdx.x; //Epeksigisi /* float temp2=x[i*n+k] + x[k*n+j]; omws i=ix/n; kai j=ix%n = ix&(n-1) i*n = ix/n * n = ix-ix%n= ix-j */ int j=ix&(n-1)...
4,437
#include <cuda_runtime.h> #include <iostream> #define WIDTH 15 #define TILE_WIDTH 5 void MatrixMulOnDevice(float *M, float *N, float *P, int Width); __global__ void MatrixMulKernel(float *Md, float *Nd, float *Pd, int Width); void PrintMatrix(float *X, int Width, char ch); int main() { float A[WIDTH * WIDTH]; fl...
4,438
#include "LBM_GPU.cuh" ifstream fin_GPU("in_GPU.txt"); ofstream fout_GPU("out_GPU.dat"); ofstream fout_GPU_Cd("out_GPU_Cd.dat"); ofstream fout_GPU_Ux0("out_GPU_Ux0.dat"); ofstream fout_GPU_Ux("out_GPU_Ux.dat"); LBM_GPU::LBM_GPU() { // ============================================================================ // // ...
4,439
#include <stdio.h> #include <stdlib.h> #define MAX_NONCE 1000000000 // 100000000000 //char* tohexadecimal void mine(long blockNum, char *trans, char *preHash, int prefixZero){ //char prefix[] = "0000" ; for(int i = 0; i < MAX_NONCE; i++){ //printf("mining...\n") ; srand(i*blockNum*(trans[...
4,440
#include <iostream> #define N 512 __global__ void dot(int *a, int *b, int *c) { __shared__ int temp[N]; temp[threadIdx.x] = a[threadIdx.x] * b[threadIdx.x]; __syncthreads(); if (0 == threadIdx.x) { int sum = 0; for(int i = 0; i < N; i++) sum += temp[i]; *c = sum; ...
4,441
#include "includes.h" extern "C" { } const double TOLERANCE = 1.0e-10; /* cgsolver with CUDA support solves the linear equation A*x = b where A is of size m x n */ __global__ void mvm_gpu(double *A_cuda, double *X_cuda, double *Y_cuda, int *m_locals_cuda, int *A_all_pos_cuda, int n, int nthreads){ int t = blockIdx.x...
4,442
#include <stdio.h> #include <time.h> __global__ void vecAdd(int *a, int *b, int *c, int length){ int tid = blockIdx.x*blockDim.x + threadIdx.x; if(tid < length) c[tid] = a[tid] + b[tid]; } int main(int argc, char* argv[]){ int size = 16384; int *a,*b,*c; int *dev_a,*dev_b,*dev_c; int totalSize = size*sizeo...
4,443
#include "includes.h" __global__ void float4toUchar4(float4 *inputImage, uchar4 *outputImage, int width, int height) { int offsetBlock = blockIdx.x * blockDim.x + blockIdx.y * blockDim.y * width; int offset = offsetBlock + threadIdx.x + threadIdx.y * width; float4 pixelf = inputImage[offset]; uchar4 pixel; pixel.x = (u...
4,444
// https://devblogs.nvidia.com/even-easier-introduction-cuda/ #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> #include <math.h> cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); __global__ void addKernel(int *c, const int *a, cons...
4,445
#include <cuda.h> #include <cuda_runtime.h> __global__ void addKernel01(int *c, int *a, int *b, int repeat) { __shared__ unsigned char s[48 * 1024]; int i = threadIdx.x; int j = i; for (int n = 0; n < repeat; n++) s[i % 64] = 1; for (int n = 0; n < repeat; n++) c[j] = a[i] + b[i] + s[i % 64]; } __global__ void ...
4,446
// Undone __global__ void reduction_variance( double *h_input, double *h_output, double mean, int ARRAY_SIZE, int ARRAY_BYTES ){ // Create, Allocate, Calculate, Free Memory, and Return return; }
4,447
float h_A[]= { 0.5203431404205534, 0.8397212236917517, 0.8480297885975157, 0.5826219921812311, 0.8835936178913075, 0.5035784748336407, 0.7515095002498209, 0.9251304241177449, 0.7090255192089898, 0.8358676530410938, 0.8610267321433007, 0.5111123121975225, 0.5228948919205396, 0.8433140045336898, 0.8026350145159813, 0.578...
4,448
#include <iostream> #include <math.h> using namespace std; __global__ void add(int n,float* a,float* b){ int index = blockIdx.x*blockDim.x+threadIdx.x; int stride = blockDim.x*gridDim.x; for(int i=index;i<n;i+=stride) a[i] = a[i]+b[i]; } int main(void){ int N=1<<20; float *x,*y; cudaMallocManaged(&x,N,sizeof(fl...
4,449
#include <cuda_runtime.h> #define min(a, b) ((a) < (b) ? (a) : (b)) #define num_threads 512 typedef unsigned char uint8_t; struct Size{ int width = 0, height = 0; Size() = default; Size(int w, int h) :width(w), height(h){} }; // 计算仿射变换矩阵 // 计算的矩阵是居中缩放 struct AffineMatrix{ /* 建议先阅读代码,若有...
4,450
#include "includes.h" using namespace std; //using namespace std::chrono; int test_reduce(int* v); using namespace std; __global__ void reduce0(int *g_idata, int *g_odata) { extern __shared__ int sdata[]; // each thread loads one element from global to shared mem unsigned int tid = threadIdx.x; unsigned int i = b...
4,451
#include <cuda.h> #include <stdio.h> __global__ void dkernel (unsigned* arr) { unsigned id = blockIdx.x * blockDim.x * blockDim.y * blockDim.z + threadIdx.z * blockDim.y * blockDim.x + threadIdx.y * blockDim.x + threadIdx.x; arr[id] = 0; // printf ("threadIdx. x, y, z = %d, %d, %d\n", threadIdx....
4,452
#include "includes.h" __global__ void AccuracyDivideKernel(const int N, float* accuracy) { *accuracy /= N; }
4,453
#pragma once #define CUDA_CALL(x) do { if((x) != cudaSuccess) { \ printf("Error at %s:%d -- %s\n",__FILE__,__LINE__, cudaGetErrorString(x));}} while(0)
4,454
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <math.h> #include <string.h> #include <sys/time.h> using namespace std; //************************************************************************** double cpuSecond() { struct timeval tp; gettimeofday(&tp, NULL); return((double)tp.tv_sec + (dou...
4,455
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <iostream> #include <fstream> __global__ void simple_histo(unsigned int * d_bins, unsigned int * d_in, unsigned int BIN_SIZE, unsigned int IN_SIZE) { unsigned int myId = threadIdx.x + blockDim.x * blockIdx.x; // checking for out-of-bounds if ...
4,456
#include <cuda.h> #include <stdio.h> #include <stdlib.h> __global__ void mandelKernel(float stepX, float stepY, float lowerX, float lowerY, int* img_result, int maxIterations, int pitch, int groups) { // To avoid error caused by the floating number, use the following pseudo code // // float x = lowerX + th...
4,457
#include <iostream> #include <cuda.h> extern "C" __global__ void kernel(volatile float *A, volatile float *B) { unsigned Idx = blockDim.x*blockIdx.x + threadIdx.x; float Temp = A[Idx+1]; float Temp1 = A[Idx+2]; float Temp2 = A[Idx+3]; if (threadIdx.x > 100000) { B[Idx+2] = Temp + Temp1 + Temp2; }...
4,458
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #include "device_launch_parameters.h" // compute the A1 operator __global__ void A1_kernel(double* r, double* v, double dt, size_t N) { size_t id = blockIdx.x*blockDim.x + threadIdx.x; r[id] += v[id] * dt; } // compute the A2 o...
4,459
#include "stack.cuh" #include <stdio.h> __host__ __device__ Stack::Stack(int max_size){ // this->stack_data = new int[ max_size ]; // memset(this->stack_data, 0, max_size); this->top = 0; this->size = max_size; } __host__ __device__ Stack::~Stack(){ // delete [] stack_data; } __host__ __device__ ...
4,460
/* Contributors: Yizhao Gao (yizhaotsccsj@gmail.com) */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "io.cuh" //rasterStat inputFileName inputCount inputPCcount xMin yMin xMax yMax cellSize outputFileName int rasterStat(char * inputFileName, int minRzn, int numRzn, char * inputPCName, float xM...
4,461
#include "includes.h" /* Hello world of wave propagation in CUDA. FDTD acoustic wave propagation in homogeneous medium. Second order accurate in time and eigth in space. Oleg Ovcharenko Vladimir Kazei, 2019 oleg.ovcharenko@kaust.edu.sa vladimir.kazei@kaust.edu.sa */ /* Add this to c_cpp_properties.json if linting is...
4,462
#include <iostream> #include <math.h> #include <vector> #include <iomanip> #include <sstream> #include <string> #include <fstream> #include <thread> #include <ctime> #include <stdio.h> #define BLOCK_SIZE (128) #define WORK_SIZE_BITS 16 #define SEEDS_PER_CALL ((1ULL << (WORK_SIZE_BITS)) * (BLOCK_SIZE)) #define GPU_ASS...
4,463
#include <stdio.h> __global__ void hello_kernel() { printf("hello world from cuda thread %d\n", int(threadIdx.x)); } int main(void) { hello_kernel<<<1, 32>>>(); cudaDeviceSynchronize(); return 0; }
4,464
#include "includes.h" __global__ void updateWalkers ( const int dim, const int nwl, const float *xx1, const float *q, const float *r, float *xx0 ) { 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 ) { //if ( q[j] > r[j] ) { xx0[t...
4,465
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> using namespace std; int main() { int count; cudaGetDeviceCount(&count); cudaDeviceProp prop; for (int i = 0; i < count; ++i) { cudaGetDeviceProperties(&prop, i); cout << "Device " << i << ": " << prop.name << endl; cou...
4,466
extern "C" __global__ void multiply(int sizeB, int max, double** A, double* B, double* C, double* Displacement) { int tid = threadIdx.x + blockIdx.x * blockDim.x; if(tid < sizeB){ double sum = 0.0; int index_neighbor; for(int i = 0; i < max; i++) { index_neighbor = (...
4,467
// // sumaMatrices.cu // // // Created by Amilcar Meneses Viveros on 15/02/18. // // #include <stdio.h> #define M 8192 #define N 8192 double a[M][N], b[M][N], c[M][N]; __global__ void kernelSumaMatrices(double *a, double *b, double *c, int m, int n) { int i = threadIdx.x+blockIdx.x*blockDim.x; in...
4,468
#include "includes.h" __global__ static void k_zero_comp_xyz(float *data, uint n, uint stride) { uint i = blockIdx.x * blockDim.x + threadIdx.x; uint p = blockIdx.y; if (i < n) { data[i + p * stride] = 0.f; } }
4,469
#include <stdio.h> #define M 3 #define N 3 #define P 3 __global__ void kernel(float*,float*,float*); void random_floats(float*,int); void print_matrix(float*,int,int); int main(int argc,char** argv) { /** * Init all variables */ int a_size = sizeof(float)*M*N, b_size = sizeof(float)*N*P, ...
4,470
#include <cstdio> #include <cstdlib> #include <cuda_runtime.h> #include <device_launch_parameters.h> __global__ void hello(char *a, int *b) { for (int i=0; i<7; ++i) { a[i] += b[i]; } } int main(int argc, char* argv[]) { // Hello Array char a[7] = "Hello "; // Array with paddings (last one must be ...
4,471
#include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #include <time.h> #define __DEBUG #define VSQR 0.1 #define TSCALE 1.0 #define CUDA_CALL( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) #define CUDA_CHK_ERR() __cudaCheckError(__FILE__,__LINE__) extern int tpdt(double *t, double dt, double end_tim...
4,472
#include <stdio.h> __global__ void helloFromGPU (int n) { printf("Hello from GPU with grid %d and thread %d\n", n, threadIdx.x); //printf("From:%d, %d ", n, blockIdx.x); } int main (void) { helloFromGPU<<<1,10>>>(1); cudaDeviceSynchronize(); helloFromGPU<<<5,2>>>(2); cudaDeviceSynchronize(); printf("Hello CP...
4,473
/* Produced by CVXGEN, 2017-11-20 12:18:48 -0500. */ /* CVXGEN is Copyright (C) 2006-2017 Jacob Mattingley, jem@cvxgen.com. */ /* The code in this file is Copyright (C) 2006-2017 Jacob Mattingley. */ /* CVXGEN, or solvers produced by CVXGEN, cannot be used for commercial */ /* applications without prior written permis...
4,474
#include "includes.h" # define MAX(a, b) ((a) > (b) ? (a) : (b)) # define GAUSSIAN_KERNEL_SIZE 3 # define SOBEL_KERNEL_SIZE 5 # define TILE_WIDTH 32 # define SMEM_SIZE 128 __global__ void initializeSobel(float *d_sobelKernelX, float *d_sobelKernelY) { int ix = threadIdx.x; int iy = threadIdx.y; int weight = SOBEL_KER...
4,475
//#include "techniqueMegakernel.cuh" #ifndef PROC_MAX_NUM #define PROC_MAX_NUM 64 #endif #ifndef SM_MAX_NUM #define SM_MAX_NUM 50 #endif #ifndef MEGAKERNEL_MAX_PROC_NUM #define MEGAKERNEL_MAX_PROC_NUM 10 #endif __device__ void* queuePointers[PROC_MAX_NUM]; namespace Megakernel { __device__ volatile int doneCounte...
4,476
#include <stdio.h> #define N 64 __global__ void square(float * d_out,float * d_in){ int idx=threadIdx.x; float f=d_in[idx]; d_out[idx] = f*f/255; } void wrapper_square(float * d_out,float * d_in){ square<<<1,N>>>(d_out,d_in); } int main(int argc,char ** argv){ const int ARRAY_BYTES = N * sizeof(float); float h_in...
4,477
#include<stdio.h> #include<stdlib.h> __global__ void blur (int *dev_a) { int i = blockIdx.x; int j = threadIdx.x; int self[3], top[3], bottom[3], left[3], right[3]; self[0] = dev_a[i*263+j] & 0xff; self[1] = (dev_a[i*263+j]>> 8) & 0xff; self[2] = (dev_a[i*263+j]>>16) & 0xff; if (i==0) { top[0] = 0; ...
4,478
#include <stdio.h> __global__ void sumArraysOnGpu(const float *a, const float *b, float *c){ const size_t i = threadIdx.x; c[i] = a[i] + b[i]; } void launch_cuda(const size_t n, const size_t nBytes, const float * a, const float * b, float * c){ float *d_A, *d_B, *d_C; cudaMalloc((float**) &d_A, nBytes); ...
4,479
/****************************************************** * CUDA Sum Reduction * By: Sairam Krishnan * Date: May 6, 2014 * Compile command: nvcc -arch=sm_20 reduction.cu ******************************************************/ #include <cuda.h> #include <stdio.h> #define N 10 #define NTHRDS 4 #define NBLKS (((N) + ...
4,480
#define I(d,i,j) (i)*(d)+(j) #define B(i) (i+1) #define BLOCK_DIM 16 typedef struct{ float *v; int d; int size; } Grid; __global__ void cero(Grid m) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if(i<=m.d && j<=m.d) m.v[I(m.d,i,j)]=0.0; } __global__ void rand...
4,481
#include "includes.h" __device__ void OFConvertXY2AngleSize (float*of, int id, int imageSize, float& of_size, float& of_angle){ float2 OF_value; OF_value.x = of[id]; OF_value.y = of[id+imageSize]; of_size = (float) sqrt( (OF_value.x+OF_value.y) * (OF_value.x+OF_value.y) ); // normalized to be <0,1> of_angle = (floa...
4,482
// test calling kernels from different threads, in parallel (can be different kernels, or same. either way, should work, not crash :-) ) #include <iostream> #include <memory> #include <cassert> #include <sstream> using namespace std; #include <cuda.h> // const int N = 1024; int main(int argc, char *argv[]) { ...
4,483
#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...
4,484
#include <iostream> #include <cstdlib> #include <math.h> #include <stdio.h> #include <assert.h> #include <fstream> #include <time.h> #include <stdlib.h> #define TILE_WIDTH 16 #define maskCols 5 #define maskRows 5 #define FH 21 #define FW 21 #define TW 32 #define TH 32 // Max 1024 Threads per Block #define BH 32 ...
4,485
#include "includes.h" __global__ void attentionKernel(float *x, int rows, int cols) { int j = blockIdx.x * blockDim.x + threadIdx.x; if (j >= cols) return; float sum = 0; for (int k = 0; k < rows; k++) { sum += x[k * cols + j]; } for (int k = 0; k < rows; k++) { x[k * cols + j] *= sum; } }
4,486
#include <stdio.h> __global__ void add_2d_numbers(int *d_out,int *d_in) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; int index = row * col + row; if(index == 8){ printf("Checkpoint!\n"); } d_out[index] = d_in[index]; } void call_2d_parallel_computing(vo...
4,487
float h_A[]= { 0.7175049743623347, 0.7483295476728882, 0.5428045722921292, 0.6670388593622318, 0.8285250757988448, 0.6493922330544046, 0.9155831240661374, 0.5175069123492884, 0.7144072115954666, 0.8263031546197478, 0.7624806464646448, 0.9122238073039419, 0.5566906615344596, 0.8168905807336863, 0.6933761370918536, 0.839...
4,488
#include "includes.h" __global__ void kernelInitNablaW(float *nabla_w,int tws) { if ((blockIdx.x*blockDim.x+threadIdx.x)<tws) { nabla_w[blockIdx.x*blockDim.x+threadIdx.x]=0.0; } }
4,489
#include <math.h> #include <stdio.h> #include <vector> __global__ void vecAddKernel(float* A, float* B, float* C, int size) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < size) { C[i] = A[i] + B[i]; } } void vecAdd(float* h_A, float* h_B, float* h_C, int n) { float* d_A; float* d...
4,490
#include<cuda.h> #include<cuda_runtime.h> #include<stdio.h> #include<stdlib.h> #include<cmath> #define TILE_SIZE 2 __device__ void store_full(float*,float*,int); __device__ void load_full(float*,float*,int); __device__ void potrf_tile(float*,int,int); __device__ void trsm_tile(float*,int,int,int); __device__ void syrk_...
4,491
template <class T, unsigned int blockSize> __device__ void reduce(T *g_idata, unsigned n, unsigned tid, unsigned i, T sdata[]) { if (blockSize >= 512) { if (tid < 256) { sdata[tid] += sdata[tid + 256]; } __syncthreads(); } if (blockSize >= 256) { if (tid < 128) { sdata[tid] += sdata[tid + 128]; } __syncthreads(); } ...
4,492
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> __global__ void funcao() { } int main() { //declaração de todas variáveis // alocação de memória principal (host) // Alocação dinâmica de memória para ser utilizada na GPU. // Carrega variáveis no host. // Cop...
4,493
#include <stdio.h> #include <cuda_runtime_api.h> #include "device_launch_parameters.h" #include <ctime> #include <cstdlib> #define NUM_BINS 256 #define N 9192 #define NUM_THREADS 512 __global__ void histogram(int * histogramm, int * arrays) { int tid = blockIdx.x * blockDim.x + threadIdx.x; int num = arrays[tid...
4,494
#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 "BFSLevels.cu" #include<chrono> #include<iostream> using namespace std; using namespace std::chrono; int blocks_[20][2] = {{8,8},{16,16},{24,24}...
4,495
#include "includes.h" __global__ void assemble_boundary_accel_on_device(float * d_accel, const float * d_send_accel_buffer, const int num_interfaces, const int max_nibool_interfaces, const int * d_nibool_interfaces, const int * d_ibool_interfaces){ int id; int iglob; int iloc; int iinterface; id = threadIdx.x + (blockI...
4,496
#include <iostream> #include "../ginkgo/GOrderHandler.h" #include <thrust/device_vector.h> #define def_dvec(t) thrust::device_vector<t> using namespace std; __global__ void test(){ // Creating an OrderHandler struct gpu_ginkgo::OrderHandler<100, 10> ggoh(1024, 10); ggoh.showOrderBookInfo(); ggoh.loadS...
4,497
#include <cuda.h> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> // Multiplicacion de Mini Matriz - Matriz __global__ void multMatKernel(double *d_a, double *d_b, double *d_c, int NRA, int NCA, int NCB) { int row = blockIdx.y * blockDim.y + threadIdx.y; ...
4,498
// Ref: https://github.com/PacktPublishing/Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA/blob/master/Chapter2/01_variable_addition_value.cu #include <iostream> #include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> __global__ void gpuAdd(int d_a, int d_b, int* d_c) { *d_c = d_a + d_b; } ...
4,499
#include <cuda_runtime.h> #include <iostream> #include <stdlib.h> #define BLOCK_SIZE 16 #define HISTOGRAM_LENGTH 256 /* kernel to convert image to unsigned char format */ __global__ void greyscale(float* input, unsigned char* output, int height, int width, int channels) { // shared memory __shared__ float rgb...
4,500
#include <stdio.h> #include <cuda_runtime.h> #include <unistd.h> #include <vector> #include <assert.h> #include <signal.h> #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort = true) { if (code != ...