serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
701
#include <math.h> #include <stdio.h> #include <stdlib.h> // functie kernel prin care adunam doi arrays __global__ void vector_add(float *x, float *y, int n) { // calculam indexul - echivalent cu for-ul // threadId.x - id-ul unui thread blocul actual // blockDim.x - dimensiunea blocului actual // blockIdx.x ...
702
#include "includes.h" __device__ bool checkBoundary(int blockIdx, int blockDim, int threadIdx){ int x = threadIdx; int y = blockIdx; return (x == 0 || x == (blockDim-1) || y == 0 || y == 479); } __global__ void mDivergence_TwoDim(float *div, float *u_dimX, float *u_dimY, float r_sStep) { if(checkBoundary(blockIdx.x, bl...
703
#define RADIUS 2 #define BLOCK_SIZE 32 // needs to be equal to blockDim.x __constant__ double WEIGHT = 1. / (2.*RADIUS + 1); __global__ void smoothing_stencil_1d(double *in, double *out, int length) /** Smoothing stencil in one dimension using average over the radius defined by RADIUS . Inspired by ht...
704
/* This is a demonstration of how crazily simple using `thrust` is compared to using the lower-level runtime API. */ #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/sort.h> #include <ctime> #include <cstdio> int myrand() { return rand() % 10; } int main() { int count = 1024;...
705
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //Number of elements of the inpu layers, that correspond to the number of pixels of a picture #define PIXELS 3073 //Number of elements of the first hidden layer #define HIDDEN_LAYER_1 2000 //Number of elements of the second hidden layer #define...
706
/********************************************************************** * DESCRIPTION: * Serial Concurrent Wave Equation - C Version * This program implements the concurrent wave equation *********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math...
707
#include"rbsspfvehicletracker.cuh" //============================================================================== LaserScan * d_scan=NULL; LaserScan h_scan; EgoMotion h_egomotion; //============================================================================== __host__ __device__ void deviceBuildModel(VehicleStat...
708
#include "includes.h" __global__ void normalize_cdf( unsigned int* d_input_cdf, float* d_output_cdf, int n ) { const float normalization_constant = 1.f / d_input_cdf[n - 1]; int global_index_1d = ( blockIdx.x * blockDim.x ) + threadIdx.x; if ( global_index_1d < n ) { unsigned int input_value = d_inp...
709
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <string.h> #include <stdlib.h> __global__ void findSubstr(char *str, char *substr, int *len) { int subStrLen = *len; int k = threadIdx.x; for (int j = 0, i = k; j < subStrLen; j++, i++) { if(str[i] != s...
710
#include "includes.h" /* Copyright 2014-2015 Dake Feng, Peri LLC, dakefeng@gmail.com This file is part of TomograPeri. TomograPeri is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the L...
711
// Date March 26 2029 //Programer: Hemanta Bhattarai // Progarm : To add two arrays #include<stdio.h> #include<stdlib.h> //for random numbers // device kernal __global__ void vecAdd(int *A, int *B, int *C) { int i = threadIdx.x; C[i] = A[i] + B[i]; } int main() { // host function definition int get_random()...
712
//#include "crop_cuda.h" // //#include <stdio.h> //#include <cstdlib> //#include <math.h> //#include <iostream> // //#include "../common/macro.h" // // //namespace va_cv { // //texture<unsigned char, 2> srcTexture2D; //__constant__ int rect[4]; // // //extern "C" __global__ void kernel_crop_grey(unsigned char *dst ) {...
713
/* ------------ * This code is provided solely for the personal and private use of * students taking the CSC367 course at the University of Toronto. * Copying for purposes other than this use is expressly prohibited. * All forms of distribution of this code, whether as given or with * any changes, are expressly...
714
#include "includes.h" __global__ void kEltwiseLogregCost(float* predmap, float* indmap, float*indlogpred, float* correctprobs, int numCases, int numTasks, int per_thread_case) { const int task_id = blockIdx.x; const int start_tx = threadIdx.x * per_thread_case; const int end_tx = min(start_tx + per_thread_case, numCase...
715
__global__ void init(float* xbar, float* xcur, float* xn, float* y1, float* y2, float* img, int w, int h, int nc) { int x = threadIdx.x + blockDim.x * blockIdx.x; int y = threadIdx.y + blockDim.y * blockIdx.y; if (x < w && y < h) { int i; float val; for (int z = 0; z < nc; z++) { i = x + w * y + w * h * z;...
716
#include <cuda_runtime.h> #include <stdio.h> #include <sys/time.h> inline double seconds() { struct timeval tp; struct timezone tzp; int i = gettimeofday(&tp, &tzp); return ((double)tp.tv_sec + (double)tp.tv_usec * 1.e-6); } int total_size = 1024 * 1024; // 1MB void test(int size) { double iStart, iElaps;...
717
#include <stdlib.h> #include <stdio.h> void fill_matrix(double *mat, unsigned numRows, unsigned numCols) { for(unsigned i=0; i < numRows; i++) for(unsigned j=0; j < numCols; j++) { mat[i*numCols + j] = i*2.1f + j*3.2f; } } void print_matrix_to_file(double *mat, unsigned numRows, unsi...
718
#include <stdlib.h> #include <stdio.h> #include <math.h> #define A1 0.31938153 #define A2 -0.356563782 #define A3 1.781477937 #define A4 -1.821255978 #define A5 1.330274429 #define RSQRT2PI 0.3989422804 __device__ double cndGPU(double d) { double K = 1.0 / (1.0 + 0.2316419 * fabs(d)); double ...
719
/* File: vec_add.cu * Purpose: Implement vector addition on a gpu using cuda * * Compile: nvcc [-g] [-G] -o vec_add vec_add.cu * Run: ./vec_add */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <math.h> __global__ void Vec_add(unsigned int x[], unsigned int y[], unsigned int z[], ...
720
#include "includes.h" __global__ void expandKernel(double* values, int n_original, int factor, double* expanded){ int tid0 = threadIdx.x + blockIdx.x*blockDim.x ; int stride = blockDim.x*gridDim.x ; for ( int tid = tid0 ; tid < n_original*factor ; tid += stride){ int idx = floor(double(tid)/factor) ; expanded[tid] = va...
721
#include<stdio.h> __global__ void vecadd(float *a, float *b, float *c, int n) { int i= threadIdx.x + blockDim.x*blockIdx.x; if(i<n) c[i] = a[i]+b[i]; } int main(){ int n; scanf("%d",&n); int a[n],b[n]; for(int i=0; i<n; i++) scanf("%d",&a[i]); for(int i=0;i<n; i++) scanf("%d",&b[i]); int c[n]; float *...
722
#include "includes.h" __global__ void fill(int * v, std::size_t size) { auto id = blockIdx.x * blockDim.x + threadIdx.x; if( id < size) { v [ id ] = id; } }
723
#include "includes.h" /* CUDA MATRIX NORMALIZATION MOHAMMED ARBAAZ SHAREEF A2077541 ASSIGNMENT-4 INTRODUCTION TO PARALLEL AND DISTRIBUTED COMPUTING */ //Incuding all the required libraries /* Program Parameters */ #define MAXN 8000 /* Max value of N */ int N; /* Matrix size */ /* Matrices */ float A[MAXN*MAXN], B[...
724
#include <cuda_runtime.h> #include <stdio.h> #include "includes/kernel.cuh" #include "includes/utils.cuh" #define L1Func(I, x, y) (I) #define L2Func(I, x, y) (powf(I, 2)) #define LxFunc(I, x, y) (x * I) #define LyFunc(I, x, y) (y * I) #define RowCumSum(name, func) \ __...
725
#include "graphs.cuh" #include <ctime> #include <algorithm> using namespace graphs; __global__ void stage1(bool * status, int * d_q_curlen, int * d_q_nexlen, int * d_S_len, int * d_ends_len, int * d_q_cur, int * d_q_next, int * d_sigma, int * d_delta, int * d_S, int * d_ends, int * d_dist,int* d_depth, int * d_no_nod...
726
#include "includes.h" __global__ void kernel_m(unsigned int * ind, unsigned int *scand, unsigned int shift, const unsigned int ne) { unsigned int sosm = 1 << shift; int m_i_b = threadIdx.x + blockDim.x * blockIdx.x; if (m_i_b >= ne) return; scand[m_i_b] = ((ind[m_i_b] & sosm) >> shift) ? 0 : 1; }
727
#include <stdio.h> __global__ void k_lu_f32(int n, float* A, int stride_row, int stride_col){ for (int i=0;i<n;i++){ for (int j=i+1;j<n;j++){ float factor=-A[j*stride_col+i*stride_row]/A[i*stride_col+i*stride_row]; for (int k=i+1;k<n;k++){ A[j*stride_col+k*stride_row]=A[j*stride_col+k*stride_row]+A[i*strid...
728
#include <stdio.h> #include <stdlib.h> /* =================================== scan_cuda.cu =================================== a[39999999] = 799999980000000.000000 real 0m2.485s user 0m1.233s sys 0m1.130s ==27669== NVPROF is profiling process 27669, command: ./scan_cuda a[39999999] = 799999980...
729
extern "C" __global__ void grav(int n, double G, double *mass, double *posX, double *posY, double *rForceX, double *rForceY) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if (i < n && j < n && i != j) { double relX = posX[j] - posX[i]; ...
730
#include <memory> #include <iostream> #include <cuda_runtime.h> int main(void) { int device_count = 0; cudaGetDeviceCount(&device_count); std::cout << "There are " << device_count << " gpus on this computer" << std::endl; }
731
#include "includes.h" #define DOUBLE #ifdef DOUBLE #define Complex cufftDoubleComplex #define Real double #define Transform CUFFT_Z2Z #define TransformExec cufftExecZ2Z #else #define Complex cufftComplex #define Real float #define Transform CUFFT_C2C #define TransformExec cufftExecC2C #endif #define TILE_DIM 8 /...
732
#include <stdlib.h> #include <stdio.h> /* __global__ void kernel10(int *a) { printf("Hello from thread %d in block %d\n", threadIdx.x, blockIdx.x); } */ __global__ void kernel10(int *a) { printf("Hello from thread %d and %d in block %d and %d \n", threadIdx.x, threadIdx.y, blockIdx.x, blockIdx.y); } int...
733
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #define N 5 __global__ void CUDAStrCopy(char *A, char C[N]) { int i = threadIdx.x; C[i] = A[i] - 32; printf("%c\t", C[i]); } int main() { char A[N]; char C[N]; char *pa, *pc; for(int i = 0; i < N; i++) A[i...
734
__global__ void ch1(unsigned char* Pout, unsigned char* Pin, int width, int height) { int channels = 3; int col = threadIdx.x + blockIdx.x * blockDim.x; int row = threadIdx.y + blockIdx.y * blockDim.y; // check if pixel within range if (col < width && row < height){ int gOffset = row * wid...
735
#include <cuda.h> #include <iostream> #define checkCudaErrors(err) __checkCudaErrors (err, __FILE__, __LINE__) inline void __checkCudaErrors( CUresult err, const char *file, const int line ) { if( CUDA_SUCCESS != err) { fprintf(stderr, "CUDA Driver API error = %04d from file <%s>, line ...
736
__global__ void kernel(float4* a, const cudaTextureObject_t* tex){ a[0] = tex3D<float4>(tex[blockIdx.x], 0.1, 0.2, 0.3); }
737
/* * purpose: model the event of infection with avian flu virus * substrain H7N9 known to also affect humans; infection * will be said to occur when a random number from the * interval [0,1] falls into a certain range representing * the fraction of l...
738
#include "arguments.hh" #include <algorithm> Arguments::Arguments(const std::vector<std::string>& args) : args_(args) {} Arguments::Arguments(int argc, char** argv) { for (int i = 0; i < argc; ++i) args_.push_back(argv[i]); } const std::vector<std::string>& Arguments::args_get() const { return args_; } bo...
739
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <cuda_runtime.h> #define WIDTH 1024 #define TILE_WIDTH 16 #define BLOCKSPERGRID WIDTH / TILE_WIDTH int N[WIDTH][WIDTH] = {0}; int T[WIDTH][WIDTH] = {0}; __global__ void transpose(int *Nd, int *Td); __device__ int GetElement(int *matrix, int row, in...
740
#include <iostream> #include <stdio.h> #include <math.h> __global__ void vectorAdd(int a) { }
741
#include <iostream> #include <cuda_runtime.h> #include <device_launch_parameters.h> const size_t GRID_SIZE = 100; const size_t BLOCK_SIZE = 256; // kernel menambahkan vector __global__ void dotProduct( const float *cVectorA, const float *cVectorB, float *dotProductSebagian, const int cJumlahElemen) { __s...
742
__global__ void convolution(float* input, int inputRows, int inputCols, int inputLd, float* kernel, int kernelRows, int kernelCols, int kernelLd, int rowStep, int colStep, float* output, int outputLd) { int row = (blockIdx.y * blockDim.y + threadIdx.y) * ro...
743
// //#include "cuda_runtime.h" //#include "device_launch_parameters.h" //#include <stdlib.h> //#include <stdio.h> // //__global__ void Read_texture_obj_kernel(float *iptr, cudaTextureObject_t tex) { // int x = threadIdx.x + blockIdx.x * blockDim.x; // int y = threadIdx.y + blockIdx.y * blockDim.y; // int offset = x + y...
744
__global__ void simple_copy(const double *a, double *b) { size_t i = threadIdx.x + blockDim.x * blockIdx.x; b[i] = a[i]; }
745
#include <inttypes.h> #include <math.h> #include <stdlib.h> #include <stdio.h> //#include <time.h> #include <sys/time.h> #include <sys/types.h> #include <dirent.h> #include <unistd.h> #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define MAX_STR_LEN 256 struct ponto_capturad...
746
/* matrixmul.cu * * Jonathan Lehman * February 22, 2012 */ #include <cuda.h> #include <stdio.h> #include <math.h> #include <sys/time.h> __global__ void mult( float*, float*, float*, int, int, int, int, int); void buildArrays( int, int ); void checkArgs(int, char**); void checkGPUCapabilities(int, int, int, int,...
747
#include <type_traits> int main(int, char*[]) { return 0; }
748
#include <stdio.h> #include <stdlib.h> #include <cuda.h> __global__ void sumaDatos(int* in, int* out, int size) { int IDx=blockIdx.x*blockDim.x+threadIdx.x; if(IDx>size) return; out[IDx]=in[IDx]+in[IDx]; } int main(int argc, char **argv) { int datosCount=100000000; int* h_datos=(int*)malloc(datosCount*sizeo...
749
#include<iostream> #include<ctime> using namespace std; #define R 32 #define C 32 //#define BY_R __global__ void by_row(int* data) { __shared__ int cache[R][C]; unsigned int idx = threadIdx.y * blockDim.x + threadIdx.x; cache[threadIdx.y][threadIdx.x] = idx; __syncthreads(); data[idx] = cache[threadIdx.y][th...
750
#include <iostream> #include <math.h> #include <ctime> #include <cmath> #include <stdlib.h> #include <fstream> #include <sstream> #define PI 3.14159265358979323846 __device__ double densityW(double Xold, double Xnew, double sigma, double r, double delta, double delta_t){ double f=0, x=0; //x=(1/(sigma*sqrt(delta_t)...
751
#include "includes.h" __global__ void calculateCircuitGraphVertexData( unsigned int * D,unsigned int * C,unsigned int ecount){ unsigned int tid=(blockDim.x*blockDim.y * gridDim.x*blockIdx.y) + (blockDim.x*blockDim.y*blockIdx.x)+(blockDim.x*threadIdx.y)+threadIdx.x; if( tid <ecount) { unsigned int c=D[tid]; atomicExch(...
752
#include "includes.h" __global__ void ModuloKernel(float* input, int divisor, float* output, int size) { int id = blockDim.x * blockIdx.y * gridDim.x + blockDim.x * blockIdx.x + threadIdx.x; if(id < size) { output[id] = (float) (((int)input[id]) % divisor) ; } }
753
/* * @Author: grantmcgovern * @Date: 2015-09-11 12:19:51 * @Last Modified by: grantmcgovern * @Last Modified time: 2015-09-13 15:42:09 */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* * File_Packet * * Contains a small data packet of * the file info (data + size) to * help with dynamic allocati...
754
#include <stdio.h> #include <stdlib.h> #include <math.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #define BLOCK_SIZE 1024 // обработка ошибок #define CSC(call) \ do { \ cudaError_t res = call; ...
755
#include "includes.h" __global__ void useNoTexture(float* pin, float* pout, int len) { unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; unsigned int j = blockIdx.y * blockDim.y + threadIdx.y; unsigned int k = blockIdx.z * blockDim.z + threadIdx.z; auto a = pin[0 + len * (i + c_size.x * (j + k * c_size.y))]; aut...
756
#include "includes.h" __global__ void copy( float *v4, const float *v3, const int n ) { for(int i=blockIdx.x*blockDim.x+threadIdx.x;i<n;i+=blockDim.x*gridDim.x) { v4[i*8+0] = v3[i*6+0]; v4[i*8+1] = v3[i*6+1]; v4[i*8+2] = v3[i*6+2]; v4[i*8+4] = v3[i*6+3]; v4[i*8+5] = v3[i*6+4]; v4[i*8+6] = v3[i*6+5]; } }
757
#include "includes.h" __global__ void FillAdjacencyMatrix(float* adj_mat , float* maskBuffer , int size , int cols , int rows ,int Nsegs){ int idx = blockDim.x*blockIdx.y*gridDim.x + blockDim.x*blockIdx.x + threadIdx.x; int icol = idx % cols; int irow = idx / cols; int seg_id1=-1; if (idx<size){ if (icol<cols-2 && irow...
758
extern "C" { __device__ inline int threadIdx_x() { return threadIdx.x; } __device__ inline int threadIdx_y() { return threadIdx.y; } __device__ inline int threadIdx_z() { return threadIdx.z; } __device__ inline int blockIdx_x() { return blockIdx.x; } __device__ inline int blockIdx_y() { return blockIdx.y; } __device__ ...
759
#include <iostream> #include <cuda_runtime.h> #define CHECK(call) { \ const cudaError_t error = call; \ if (error != cudaSuccess) { \ std::cout << "Error: " << __FILE__ << ":" \ << __LINE__ << std::endl ...
760
/* game.cu * Jonathan Lehman * April 17, 2012 * * Compile with: nvcc -o game game.cu * */ #include <cuda.h> #include <stdio.h> #include <assert.h> #include <stdlib.h> #include <strings.h> #include <math.h> #include <sys/time.h> #define DEBUG 0 /* set DEBUG to flag to 1 for debugging, set flag to 0 for opti...
761
#include <cuda_runtime_api.h> #include <stdio.h> #include <math.h> #include <iostream> __device__ float distance(float2 x1, float2 x2){ return sqrt(pow(x1.x - x2.x,2) + pow(x1.y - x2.y,2)); } __global__ void distance_kernel(float2 *data_in, float *data_out, int n){ const int i = blockIdx.x * blockDim.x + thre...
762
#include <cuda_runtime.h> #include <cstddef> #include <utility> #include <string> #include <system_error> #if defined(__CUDACC__) #define DEVICE __device__ #define HOST __host__ #else #define DEVICE #define HOST #endif #define DEVICE_HOST DEVICE HOST /*! \brief std::error_code category for cudaError */ class cuda_er...
763
#include "includes.h" __global__ void reduction_neighbored_pairs_improved_1( int * int_array, int * temp_array, int size) { int tid = threadIdx.x; int gid = blockDim.x * blockIdx.x + threadIdx.x; //local data block pointer int * i_data = int_array + blockDim.x * blockIdx.x; if (gid > size) return; for (int offset = ...
764
/* @EECE528 Project - BDD Parallelization @Authors: Yu Lei, Haotian Zhang @Date: 2017/12/3 */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #define MAXNODENUM 160000 #define MAXLINE 256 /* Maximum length of each input line read. */ typedef struct bddNode_ { float index; int value; st...
765
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <vector> #include <stdio.h> #include <ctime> #include <fstream> using namespace std; vector<char> add_data(vector<char> data); void copy_data_to_gpu(char* data, int size); int main() { int size = 0; vector<char> data; for (int i = 1; i <= 5...
766
#include "includes.h" #ifndef _KERNEL_H #define _KERNEL_H typedef struct Node { int starting; int no_of_edges; }Node; #endif __global__ void test1(bool* d_graph_visited, int no_of_nodes) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if (tid < no_of_nodes) { d_graph_visited[tid] = true; } }
767
/* Transformer function helper function. Written by tomztyang, 2021/08/23 */ #include <math.h> #include <stdio.h> #define THREADS_PER_BLOCK 256 #define DIVUP(m,n) ((m) / (n) + ((m) % (n) > 0)) // #define DEBUG __global__ void rpe_q_forward( int b, int total_query_num, int local_size, int nhead, int hdim, int l...
768
#include "includes.h" __global__ void g_FullConnectDropout(float * outputs, float * drop, int len) { for(int i = 0; i < len; i += blockDim.x * gridDim.x) { int id = i + blockIdx.x * blockDim.x + threadIdx.x; if(id < len) { outputs[id] = outputs[id] * drop[id]; } } }
769
#include <stdio.h> #define N 2250 #define T 512 __global__ void vecReverse(int *a, int *b){ int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < N){ b[i] = a[N - i - 1]; } } int main(int argc, char *argv[]){ int size = N * sizeof(int); int a[N], b[N], *devA, *devB; int blocks; ...
770
#include "cuda_runtime.h" #include <stdio.h> #include <memory.h> #define N 33 * 1024 #define threadsPerBlock 256 #define blocksPerGrid (N + threadsPerBlock - 1) / threadsPerBlock #define RADIUS 2 // Signal/image element type typedef int element; // 1D MEDIAN FILTER implementation // signal - input signal // ...
771
#include "includes.h" __global__ void BpropH(const float* layer1, float* dlayer1, const float* synH, float* dsynH, const float alpha, const int offset) { int i = blockDim.x*blockIdx.x + threadIdx.x; //256 int j = blockDim.y*blockIdx.y + threadIdx.y; //256 atomicAdd(&dsynH[i*256 + j] , dlayer1[offset*256 + j] * layer1[...
772
#include <iostream> #include <cuda.h> #include <chrono> #define ITER 200 void checkCudaError(cudaError_t msg, int x) { if (msg != cudaSuccess) { fprintf(stderr, "line: %d %s\n", x, cudaGetErrorString(msg)); exit(1); } return; } int main() { float *s, *dev_s; int i, j; std::chrono::time_point<std:...
773
// Includes #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> #include <iostream> #include <iomanip> #include <fstream> #include <ctime> // Definitions #define M_PI 3.14276 #define c 299792458 #define mu0 M_PI*4e-7 #define eta0 c*mu0 // CPU function for source ca...
774
extern "C" __global__ void forceCompute(float* pX,float* pY,float* pZ, float* nX,float* nY,float* nZ, float* FX,float* FY,float* FZ, float* RFX,float* RFY,float* RFZ, float* MX,float* MY,float* MZ, ...
775
#include "includes.h" __global__ void wlcss_cuda_kernel(int32_t *d_mss, int32_t *d_mss_offsets, int32_t *d_ts, int32_t *d_ss, int32_t *d_tlen, int32_t *d_toffsets, int32_t *d_slen, int32_t *d_soffsets, int32_t *d_params, int32_t *d_3d_cost_matrix){ int32_t params_idx = threadIdx.x; int32_t template_idx = blockIdx.x; i...
776
#include <stdio.h> #include <stdlib.h> __global__ void sum_cuda(double* a, double *s, int width) { int t = threadIdx.x; int b = blockIdx.x*blockDim.x; int i; for(i = blockDim.x/2; i > 0; i /= 2) { if(t < i && b+t+i < width) a[t+b] += a[t+b+i]; __syncthreads(); } if(t == 0) s[blockI...
777
#include <cuda.h> #include <stdio.h> __global__ void scaleit_kernel(double *a,int n) { /* Determine my index */ int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { a[i] = a[i] * 2.0l; } } int main(int argc, char **argv) { double *h_a, *d_a; int i,n=16384; dim3 block, grid; /* Allocate...
778
/* #include "SDFDevice.cuh" __host__ SDFDevice::SDFDevice(DistancePrimitive** primitives, SDModification** modifications, size_t modificationCount) : primitives(primitives), modifications(modifications), modificationCount(modificationCount) { } __host__ SDFDevice::~SDFDevice() { } __device__ float SDFDevice::dista...
779
#ifndef M_PI #define M_PI 3.14159265358979323846 #endif __device__ int get_index_x (int ncols, int index ) { if (index == -1) { index = blockDim.x * blockIdx.x + threadIdx.x; } else { index += gridDim.x; } if (index >= ncols) index = -1; return index; } __device__ int get_index_y (int nrows...
780
// https://github.com/thrust/thrust/blob/8551c97870cd722486ba7834ae9d867f13e299ad/examples/sum_rows.cu #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/reduce.h> #include <thrust/functional.h> #include <thrust/random.h> #include <iostream> // convert a li...
781
// pi1.cu /* * A simple CUDA-enabled program that approximates \pi using monte-carlo * sampling. This version generates all the random numbers at the start, * then launches kernels to use them. */ #include <stdio.h> #include <curand.h> __global__ void pi(float* d_out, float* d_rands, int rands_per_kernel, int tri...
782
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #define BLOCK_SIZE 16 __global__ void mandelKernel(int* device_img, float lowerX, float lowerY, float stepX, float stepY, int width, int height, int maxIterations) { // To avoid error caused by the floating number, use the following pseudo code // float ...
783
#include "includes.h" __global__ void bitflip_kernel(float* M, int height, int row, int n) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; int off = blockDim.x * gridDim.x; for (unsigned int i = idx; i < n; i += off){ M[i * height + row] = 1 - M[i * height + row]; } }
784
#include "includes.h" __global__ void MatrVectMul(int *d_c, int *d_a, int *d_b) { int i = blockIdx.x*blockDim.x+threadIdx.x; if(i<N) { d_c[i]=0; for (int k=0;k<N;k++) d_c[i]+=d_a[i+k*N]*d_b[k]; } }
785
#include <cuda_runtime.h> #include <float.h> #include <limits.h> #include <iostream> __global__ void bitonic_sort_step(float *dev_values, int j, int k){ unsigned int i = threadIdx.x + blockDim.x * blockIdx.x; unsigned int ixj = i ^ j; if(ixj > i){ if((i & k) == 0){ if(dev_values[i]...
786
#include "includes.h" __global__ void VanLeerRadialKernel (double *Rinf, double *Rsup, double *QRStar, double *DensStar, double *Vrad, double *LostByDisk, int nsec, int nrad, double dt, int OpenInner, double *Qbase, double *invSurf) { int j = threadIdx.x + blockDim.x*blockIdx.x; int i = threadIdx.y + blockDim.y*blockId...
787
#include <bits/stdc++.h> #include <chrono> using namespace std; __global__ void kernel(float *arr, int n) { int idx = blockDim.x * blockIdx.x + threadIdx.x; // Абсолютный номер потока int offset = blockDim.x * gridDim.x; // Общее кол-во потоков for(int i = idx; i < n; i += offset) { if (arr[i] < 0) ...
788
#include "includes.h" __global__ void totalWithThreadSync(float *input, float *output, int len) { //@@ Compute reduction for a segment of the input vector int tid = threadIdx.x, i = blockIdx.x * blockDim.x + threadIdx.x; for(unsigned int j = blockDim.x/2; j > 0; j = j/2) { if(tid < j) { if ((i + j) < len) input[i] += ...
789
#include <stdio.h> #include "cuda.h" #include "cuda_runtime.h" // Define matrix width #define N 100 #define BLOCK_DIM 32 #define SIGMA 20.0 // Define tile size #define TILE_WIDTH 2 // Non shared version __global__ void computeMatrix(float *dVectorA, float *dVectorB, float *dVectorC, int length, float sigma) { int ...
790
//template<typename T> //__device__ void sliceRows(const T* matrix, const int from, const int to, T* result, // const int numRows, const int numColumns) { // // int bx = blockIdx.x; // int by = blockIdx.y; // int tx = threadIdx.x; // int ty = threadIdx.y; // // int row = by * blockDim.y + ...
791
#include "includes.h" __global__ void prefixSum(float* arr,int step){ int bx = blockIdx.x; int tx = threadIdx.x; int BX = blockDim.x; int i = bx*BX+tx; if(i < step) return; int temp = arr[i-step]; __syncthreads(); arr[i] += temp; }
792
#include <cstdio> #include <cstdlib> __device__ void count(int *pos, int *tmp, int range, int i) { //count position by scan for (int j=1; j<range; j<<=1) { tmp[i] = pos[i]; __syncthreads(); if (i<j) return; pos[i] += tmp[i-j]; __syncthreads(); } } __global__ void bucket_sort(int *bucptr, int ...
793
#include <iostream> #include <math.h> #include <stdio.h> __global__ void add(int n, float *x, float *y, float *c) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx >= n) { return; } c[idx] = x[idx] + y[idx]; } void FillWithData(int n, float* x, float* y) { for (int i = 0; i < n; i++) { x[i]...
794
#include <stdio.h> int main() { const int kb = 1024; const int mb = kb * kb; const int gb = mb * kb; int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("\nDevice %d - GPU Card name : %s\n", i, prop.name);...
795
#include <iostream> //#include <Cuda.h> #include<curand.h> #include<curand_kernel.h> int n = 200; using namespace std; __device__ float generate( curandState* globalState, int ind ) { //int ind = threadIdx.x; curandState localState = globalState[ind]; float RANDOM = curand_uniform( &localState ); g...
796
#include <stdio.h> #include <iostream> #include <string> #include <fstream> #include <sstream> #include <vector> #include <algorithm> #include <numeric> #include <thrust/complex.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" using namespace std; const int MAX_THREADS = 1024; inline cudaError_t c...
797
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #define E 2.71828182845904523536 __global__ void euler_step(float * array, int m, int step) { float dt = powf(10,-3); int tId = threadIdx.x + blockIdx.x * blockDim.x; if (tId < m) { array[tId] = array[tId] + dt*(4*(dt*step)-array[tId]+...
798
#include "includes.h" __global__ void createAnaglyph_kernel(uchar4 *out_image, const float *left_image, const float *right_image, int width, int height, int pre_shift) { const int x = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; const int x_right = x - pre_shift; const int y = __mul24(blockIdx.y, blockDim.y) + thread...
799
#include <cstdio> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <chrono> #define CUDA_RANGE 1000 #define BLOCK_SIZE 512 #define WARP_SIZE 32 struct point { float x; float y; }; const int THREADS = 1 << 20; const int THREADS_PER_BLOCK = 512; __device__ float func(float x) { ...
800
/// LSU EE 7700-2 (Spring 2013), GPU Microarchitecture // /// Homework 3 // // Assignment in: http://www.ece.lsu.edu/koppel/gp/2013/hw03.pdf // /// Your Name: #include <pthread.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <ctype.h> #include <time.h...