serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
16,401
//xfail:BOOGIE_ERROR //--warp-sync=32 --blockDim=32 --gridDim=1 --equality-abstraction --no-inline //kernel.cu:10 #include <cuda.h> #include <cuda_runtime_api.h> #include <stdio.h> #include <assert.h> #define N 2//32 __global__ void foo(int * A) { A[0] = 1; A[1] = 1; A[threadIdx.x] = 0; //__assert(A[0] ==...
16,402
#include "includes.h" __global__ void convolutionGlobal(float *imgIn, float *kernel, float *imgOut, int w, int h, int nc, int kernelSize){ size_t x = threadIdx.x + blockDim.x * blockIdx.x; size_t y = threadIdx.y + blockDim.y * blockIdx.y; size_t k = kernelSize; int r=k/2; //check for boundarys of the block if(x>=w ||...
16,403
#include <stdio.h> __global__ void helloCUDA() { printf("Hello from thread (%d, %d) block (%d, %d)\n", threadIdx.x, threadIdx.y, blockIdx.x, blockIdx.y); } int main() { dim3 grid(2, 4); dim3 block(8, 16); helloCUDA<<<grid, block>>>(); cudaDeviceSynchronize(); return 0; }
16,404
#include "includes.h" __global__ void cudaising(int* G, double* w, int* newG) { int index = threadIdx.x + blockIdx.x * blockDim.x; double newSpin = 0.0; for (int ii = -2; ii <= 2; ii++) { for (int jj = -2; jj <= 2; jj++) { newSpin += w[(jj + 2) + (ii + 2) * 5] * G[((jj + threadIdx.x + blockDim.x) % blockDim.x) + ((bl...
16,405
#include "includes.h" // helper for CUDA error handling __global__ void getTestWeights( const double* restoredEigenvectors , const double* meanImage , const double* testImages , double* testWeights , std::size_t testImageNum , std::size_t pixelNum , std::size_t componentNum ) { std::size_t row = blockIdx.x; std::siz...
16,406
// dynamic alloc __global__ void sharedMemoryDemo1( ) { extern __shared__ float shared_data_dynamic[]; float *data = (float*)shared_data_dynamic; int id = threadIdx.x; data[id] = 0.0f; // initialization } // static alloc __global__ void sharedMemoryDemo2( ) { __shared__ int shared_data_static[16]; int...
16,407
#include "cuda_runtime.h" #include "device_launch_parameters.h" //#include <stdio.h> //device functions __device__ int getGlobalIdx_1D_1D() { return blockIdx.x *blockDim.x + threadIdx.x; } __device__ int getGlobalIdx_1D_2D() { return blockIdx.x * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; } ...
16,408
#include <stdio.h> #include <cuda_runtime.h> #define tile_size 32 #define N (1<<9) ///////////Functions that check if matrix was multiplied void matrix_multiply_seq(float *a, float *b, float *ab, size_t width){ int i, j, k; for(i=0; i<width; i++) for(j=0; j<width; j++){ ab[i*width+j]=0.0; for(k=0; k<width; k...
16,409
/* example is to show how to use shared memory and every block has seperate entity for shared memory. no impact on other block's shared memory. and we can't use memcpy to set init value for shared memory since its addr space not in global linear. but how to init it, not clear now. */ #include <iostream> using namesp...
16,410
#include <stdio.h> #define KERNEL_RADIUS 8 #define KERNEL_LENGTH (2 * KERNEL_RADIUS + 1) #define TILE_SIZE 1024 __constant__ float c_M[KERNEL_LENGTH]; const int Width = 10240000; const int nIter = 300; float * h_Kernel,*h_Input,*h_Output; float * d_Kernel, *d_Input, * d_Output; __global__ void convolution_1D_basic_...
16,411
#include <stdio.h> //compilar: nvcc matrizMultiplicacaoCompartilhada.cu -o matrizMultiplicacaoComp //for i in `seq 1 10`; do ./matrizMultiplicacaoComp; done #define N 64 #define B 32 #define TILE_WIDTH 32 __global__ void matrix_multi(float *a, float *b, float *c) { int y = blockIdx.x * blockDim.x + threadIdx.x; in...
16,412
#include <bits/stdc++.h> #include <cuda.h> using namespace std; #define N ((int)1e3) #define CEIL(a, b) ((a-1)/b +1) __global__ void multiply(float *d_a, float *d_b, float *d_c) { int x = blockIdx.x*blockDim.x + threadIdx.x; int y = blockIdx.y*blockDim.y + threadIdx.y; if(x >= N || y >= N) return; float cij=...
16,413
#include <cstdio> extern "C" { __global__ void find_roots(int N, int chunk, int* parents) { int jump = N/chunk; int x = (blockIdx.x * blockDim.x) + threadIdx.x; bool flag = true; while (flag) { flag = false; for (int i=0; i<chunk; ++i) { if (parents[x + i*jump] != parents[parents[x+ ...
16,414
#include "kernel.cuh" #define N 100 __global__ void gpuAddKernel(int const* const d_a, int const* const d_b, int* d_c) { int tid = blockIdx.x; if (tid < N) d_c[tid] = d_a[tid] + d_b[tid]; } void gpuAdd(int const * const h_a, int const * const h_b, int* h_c) { int *d_a, *d_b, *d_c; cudaMalloc...
16,415
#include <assert.h> #include <stdio.h> #include <unistd.h> #define ALLOC_SIZE 126 #define ACCESS_MODE 0 __global__ void pitched_offset_negative_one(cudaPitchedPtr devMem) { int *d_p = (int*)devMem.ptr; #ifdef R volatile int i = d_p[-1]; #elif W d_p[-1] = 42; #endif } __global__ void pitched_offset_pitch(...
16,416
// C++ Libraries. #include <iostream> // CUDA libraries. #include <cuda.h> #include <cuda_runtime.h> #include "cuComplex.h" // Define max number of concurrent threads. #define MAX_BLOCKSIZE 512 // Define optimal number of search inquries per thread. #define OPTIMAL_INQUIRES 12 //////////////////////////////////...
16,417
#include "vector.cuh" #include <assert.h> #include <stdio.h> __host__ __device__ Vec3::Vec3() { x = 0.0; y = 0.0; z = 0.0; } __host__ __device__ Vec3::Vec3(float a, float b, float c) { x = a; y = b; z = c; } __host__ __device__ float Vec3::length() { return sqrt(x * x + y * y + z * z); }...
16,418
#include <algorithm> #include <ctime> #include <fstream> #include <iostream> #include <sstream> #include <string> #include "cuda.h" using namespace std; /* use this to set the block size of the kernel launches. CUDA kernels will be launched with block size blockDimSize by blockDimSize. */ constexpr int blockDimSi...
16,419
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <cuda.h> #define NUM_THREADS 1024 #define NUM_BLOCKS 32768 #define NUM_VALUES NUM_THREADS*NUM_BLOCKS void InitV(int *v); void bitonic_sort(int *dev_values); void test(int *v); __global__ void bitonic_sort_step(int *dev_values, int j, int ...
16,420
#include "includes.h" __global__ void gpu_find_vac( const int num_atoms, const int correlation_step, const double* g_vx, const double* g_vy, const double* g_vz, const double* g_vx_all, const double* g_vy_all, const double* g_vz_all, double* g_vac_x, double* g_vac_y, double* g_vac_z) { int tid = threadIdx.x; int bid = b...
16,421
#include <stdio.h> #include <stdlib.h> #include <assert.h> #define BLOCK_SIZE 32 #define cudaCheckError() { \ cudaError_t e = cudaGetLastError(); \ if (e != cudaSuccess) { \ printf("CUDA Failure %s:%d: '%s'\n", __FILE__, __LINE__, cudaGetErrorString(e)); \ e...
16,422
/* * this program is a simple test of the atomicAdd function for serial-dependent * addition of results * */ #include <iostream> #define TOTAL_SIZE 100000 #define nTPB 256 #define NUM_ATOMS 20 #define NUM_THREADS 12 #define NUM_BLOCKS 10 #define LENGTH_LOOKUP 240 #define cudaCheckErrors(msg) \ do { \ ...
16,423
#include <stdio.h> #include <iostream> #include <math.h> #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), ...
16,424
__global__ void _add_32_12(int n, float *x, int sx, int nx, float *y, int sy, int ny, float *z) { int i = threadIdx.x + blockIdx.x * blockDim.x; while (i < n) { float xi = (nx==n ? x[i] : sx==1 ? x[i%nx] : nx==1 ? x[0] : x[(i/sx)%nx]); float yi = (ny==n ? y[i] : sy==1 ? y[i%ny] : ny==1 ? y[0] : y[(i/sy)%ny]...
16,425
#pragma once #ifdef __INTELLISENSE__ void __syncthreads(); #endif #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cuda.h> #include <stdio.h> #include <time.h> #include <ctime> #define BLOCK_DIM 4 #define ARRAY_SIZE 12 __global__ void maxValue(int *a, int *d) { __share...
16,426
//pass //--gridDim=1 --blockDim=2 --no-inline //This kernel is racy. // //The memcpy destination is unaligned so we have to handle the arrays in and out //at the byte-level. #define memcpy(dst, src, len) __builtin_memcpy(dst, src, len) typedef struct { short x; short y; } s_t; //< sizeof(s2_t) == 4 __global__ v...
16,427
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <math.h>
16,428
#include <cuda.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <cmath> #include <iostream> #include <cstring> using namespace std; #define NUM_THREADS_PER_BLOCK 512 #define NO_OF_CHARS 256 #define NO_OF_CHUNKS 32 /*****************************************************************/ // Function de...
16,429
#include<stdio.h> #include<time.h> #include<cmath> __global__ void getmotionmatrixKernel(int b, int n, const float * __restrict__ inp_axis_xyz, const float * __restrict__ inp_axis_uvw, const float * __restrict__ inp_rspeed, const float * __restrict__ inp_tspeed, float * __restrict__ out) { for(int i=blockIdx.x;i<b;...
16,430
#include<iostream> #include<chrono> using namespace std; using namespace std::chrono; __global__ void vecAdd(int *a, int *b, int *c, int n) { int block = blockIdx.x; if(block<n) c[block] = a[block]+b[block]; } int main() { int n; cin>>n; int *a=new int[n]; int *b=new int[n]; int *c=new int[n]; for(int i=...
16,431
/** * @file diffmat.cu * @author Daniel San Martin (dsanmartinreyes@gmail.com) * @brief Build differentiation matrices in device * @version 0.1 * @date 2020-09-01 * * @copyright Copyright (c) 2020 * */ #include <stdlib.h> #include "include/diffmat.cuh" /** * @brief Finite difference matrix for first deriv...
16,432
#include <iostream> //#include "cuda_runtime.h" //#include "device_launch_parameters.h" #include <curand_kernel.h> #include <ctime> #include <cstdio> #include <thrust/transform.h> #include <thrust/functional.h> #include <thrust/device_vector.h> struct saxpy_functor { const float a; saxpy_functor(float _a) : a(_a)...
16,433
/*#include<stdio.h> #include<cuda.h> #include<cuda_runtime.h> __global__ void gpuAdd(int h_inp1, int h_inp2, int *d_out) { *d_out = h_inp1 + h_inp2; } int main(void) { int h_inp1 = 3; int h_inp2 = 8; int h_out; int *d_out; cudaMalloc((void**)&d_out, sizeof(int)); gpuAdd << <10000, 500 >> >(h_inp1,h_inp2,d_...
16,434
#include <stdio.h> #define SIZE 64 #define BLOCKS 1 __global__ void device_global(unsigned int *array_a, unsigned int *array_b, int num_elements) { int my_index = blockIdx.x * blockDim.x + threadIdx.x; __shared__ unsigned int my_shared[SIZE]; my_shared[my_index] = my_index; __syncthreads(); if (array_a[my...
16,435
double S_ref[301] = {43716166.13166, 43691573.83772, 43617873.30096, 43495293.20306, 43324213.48052, 43105163.53515, 42838819.74297, 42526002.27734, 42167671.26519, 41764922.29986, 41318981.33708, 40831199.00498, 40303044.36179, 39736098.13861, 39132045.50697, 38492668.41405, 37819837.53039, 37115503.85699, 36381690.04...
16,436
#include<stdio.h> #include<cstdint> typedef uint32_t u32; __global__ void gen(u32 *src, int nsrc, u32 *choice, int nchoices, u32 *dest, int bufsize, int *ngen) { __shared__ u32 some[256]; int tid = threadIdx.x + blockIdx.x * blockDim.x; int nthreads = blockDim.x * gridDim.x; for (int i = threadIdx.x; i < ncho...
16,437
float h_A[]= { 0.8644007844753756, 0.991341870200789, 0.9880222697475953, 0.570450763393592, 0.8031015625532092, 0.9535702933749093, 0.9352722931309332, 0.5267298661220345, 0.573337707453843, 0.933796259049405, 0.9105574421018927, 0.7652699522557431, 0.8627578203954644, 0.5859265955674149, 0.5096021900293861, 0.7909869...
16,438
#include <iostream> #include <chrono> #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { // cudaGetErrorString is an api that will pop out an error to user screen else all er...
16,439
#include "includes.h" __global__ void fill_A_expansion(float* A, int* rowind, int* colind, float* val, int npix, int nimages) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < npix*nimages) { rowind[i] = i; colind[i] = i % npix; val[i] = A[i]; } }
16,440
#include <stdio.h> #define N 1250 #define T 250 __global__ void vecAssign(int *a){ int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < N){ a[i] = i * 2; } } int main(int argc, char *argv[]){ int size = N * sizeof(int); int a[N], *devA; int blocks; //Compute the blocks in case t...
16,441
#include <stdio.h> #define N 16 __device__ float sum(float *input){ float sums=0; for(int i=0;i<N;i++){ sums += input[i]; } return sums; } __device__ float sum_of_power(float *input){ float sums=0; for(int i=0;i<N;i++){ sums += input[i]*input[i]; } return sums; } __device__ float sum_of_mul(float *input1,fl...
16,442
#include<stdio.h> #include<stdlib.h> __global__ void print1() { printf("Hello! tid = %d bid = %d\n", threadIdx.x, blockIdx.x); } int main() { printf("Hello from Host!\n"); print1<<<2, 3>>>(); cudaDeviceSynchronize(); return 0; }
16,443
#include <thrust/host_vector.h> #include <thrust/device_vector.h> int main(int argc, char *argv[]) { // thrust provides host_vector & device_vector containers thrust::host_vector<float> h_vec(1024); thrust::device_vector<float> d_vec; // copy from host to device (overridden equals operator) d_vec ...
16,444
/** @file processMandelbrotElement.cu * * Copyright 2010 The Mathworks, Inc. * $Revision: 1$ * $Date: 2010-11-08$ */ /** Work out which piece of the global array this thread should operate on */ __device__ size_t calculateGlobalIndex() { // Which block are we? size_t const globalBlockIndex = blockIdx.x +...
16,445
#include "includes.h" /* * JCudaVec - Vector operations for JCuda * http://www.jcuda.org * * Copyright (c) 2013-2015 Marco Hutter - http://www.jcuda.org */ extern "C" //=== Vector arithmetic ====================================================== extern "C" extern "C" extern "C" extern "C" extern "C" //===...
16,446
#include <iostream> #include <stdlib.h> #include <ctime> typedef struct{ int width; int height; float* elements; } Matrix; __global__ void MatAddKernel(Matrix A, Matrix B, Matrix C) { int idx = threadIdx.x + blockDim.x*blockIdx.x; //thread in x int idy = threadIdx.y + blockDim.y*blockIdx.y; //thread in y int t...
16,447
#include <math.h> #include <stdio.h> #define N 512 __global__ void add(int *a, int *b, int *c) { c[threadIdx.x] = a[threadIdx.x] + b[threadIdx.x]; } void random_ints(int *p, int n) { int i; for (i = 0; i < n; i++) { p[i] = rand(); } } int main(void) { int *a, *b, *c, *d; // host copies of a, b...
16,448
#include <iostream> // Calculate the multiplication of two 32*32 matrices A and B on gpu and store the result in C. // Each block calculate one element of C. __global__ void Mul(int* d_A, int* d_B, int* d_C) { int tid = blockDim.x * blockIdx.x + threadIdx.x; int num_threads = blockDim.x * gridDim.x; for (int...
16,449
#include "includes.h" __global__ void histo_kernel( unsigned char *buffer, long size, unsigned int *histo ) { // clear out the accumulation buffer called temp // since we are launched with 256 threads, it is easy // to clear that memory with one write per thread __shared__ unsigned int temp[256]; temp[threadIdx.x] = ...
16,450
#include "stdio.h" #include "stdlib.h" //#include "conio.h" __global__ void what_is_my_id(int * block, int * thread, int * wrap, int * calc_thread){ const int thread_idx = (blockIdx.x * blockDim.x) + threadIdx.x; block[thread_idx] = blockIdx.x; thread[thread_idx] = threadIdx.x; wrap[thread_idx] = threadIdx.x ...
16,451
#include "includes.h" __global__ void trapz_kernel(float* y, float* x, float* auc, int num_selected) { __shared__ float s_auc; s_auc = 0.0f; __syncthreads(); int gid_base = blockIdx.x * blockDim.x + threadIdx.x; for (int gid = gid_base; gid < num_selected - 1; gid += blockDim.x * gridDim.x) { float a = x[gid]; float b ...
16,452
#include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <math.h> using namespace std; // CUDA KERNEL FUNCTIONS __global__ void Hello() { //int globalidx = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; int globalidx = blockIdx...
16,453
/* Collatz code for CS 4380 / CS 5351 Copyright (c) 2018, Texas State University. All rights reserved. Redistribution in source or binary form, with or without modification, is *not* permitted. Use in source and binary forms, with or without modification, is only permitted for academic use in CS 4380 or CS 5351 at Te...
16,454
/***************************************************************************//** * \file LHS2.cu * \author Christopher Minar (minarc@oregonstate.edu) * \brief kernels to generate the left hand side for the poission solve */ #include "LHS2.h" namespace kernels { __global__ void LHS2_mid(int *row, int *col, double ...
16,455
#include<cstdio> #include <cassert> #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define THREADS_PER_BLOCK 32 #define ATTRACT_STEP 0.9 extern "C" { #define weight_index(neuron, i) ((neuron) * (input_dim) + (i)) __global__ void attract(int input_dim, double *neuron_weight, int neuron_index, ...
16,456
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> void check(cudaError x) { // fprintf(stderr, "%s\n", cudaGetErrorString(x)); } void showMatrix2(char* v1, int width, int height) { // printf("---------------------\n"); for (int i = 0; i < width; i++) ...
16,457
#include "includes.h" __global__ void profileSubphaseSmootherSetup_kernel() {}
16,458
#include"svd.cuh" #include <assert.h> #include <cuda_runtime.h> #include <cublas_v2.h> #include <cusolverDn.h> void transpose_device(int rows, int cols, float * d_Matrix) { if (rows == 1 || cols == 1) { return; } cudaError_t cudaStat = cudaSuccess; float * d_Result = NULL; cudaStat = cudaMalloc((void**)&d_Resul...
16,459
#include <stdio.h> #include <iostream> #include <float.h> #define tile 4096 __global__ void sdt_gpu(unsigned char * bitmap,int sz_edge, int* edge_pixels, float *sdt, int width, int height) { __shared__ int s[tile]; int tx = threadIdx.x; int bx = blockIdx.x; int bdx = blockDim.x; int global_idx = bx * bdx + ...
16,460
#include <math.h> __device__ __host__ float dif(float x, float y, float z, float step) { return (x - 2 * y + z) / step / step; } //TODO change step and matrix_size to vector __global__ void potential_establish(float *prev_phi, float *next_phi, float *sum, float *step, int *matrix_size ) { // __shared__ floa...
16,461
#include <stdio.h> /** * Kernel routine */ __global__ void d1conv(const float* a, const float *c, float *o, const int size) { int id = blockDim.x * blockIdx.x + threadIdx.x; if(id<size) { float co = 0; for(int i=id-2;i<=id+2;i++) if(i>=0&&i<size) co += a[i]*c[i-id+2...
16,462
#include<stdlib.h> #include <stdio.h> #include <string.h> #include<time.h> #define Size 10 #define patternSize 3 #define patternNum 20 #define ThreadNum 20 #define BlockNum 1 __device__ void preKmp(char *x, int m, int kmpNext[]) { int i, j; i = 0; j = kmpNext[0] = -1; while(i < m) { while(j>-1 && x[i]!=x[j]) ...
16,463
#include<stdio.h> #define START 32 //first char to make hist ascii code #define STOP 127 //last char to make hist ascii code #define NBR_CHAR 68 int main(int argc, char** argv){ if(argc <= 2){ fprintf(stderr, "Arguments non valide"); return 1; } FILE *f_input; FILE *f_...
16,464
#include <cuda_runtime.h> #include <device_launch_parameters.h> /** * @brief cuda kernel -- compute id of a thread * @param array that stores thread ids * @return return is not allowed */ __global__ void computeThreadID(unsigned int* threadID); __global__ void computeThreadID(unsigned int* threadID) { int tid...
16,465
#include "includes.h" __global__ void AddIntegers(int *a, int *b) { a[0] += b[0]; }
16,466
#include "cuda.h" #include <stdio.h> #include <stdlib.h> #include <sys/time.h> inline double gettime_ms() { struct timeval t; gettimeofday(&t,NULL); return (t.tv_sec+t.tv_usec*1e-6)*1000; } __device__ int cost_func(int costX){ int tem=0; for(int i=0;i<costX;++i){ tem++; } return t...
16,467
// // Created by DJtheRedstoner on 5/5/2021. // #include <iostream> #include "SimpleRandom.cu" __device__ inline int getGenericEnchantability(SimpleRandom& random, int bookshelves) { int first = random.nextInt(8); int second = random.nextInt(bookshelves + 1); return first + 1 + (bookshelves >> 1) + second...
16,468
#define TILE_DIM 32 #define UNROLL 8 /** * Matrix transpose kernel * matrix dimensions mxn must be a multiple of TILE_DIM * Usage: matrix_transpose <<<grid, block>>> (matrix_dev, matrix_transposed_dev, m, n) * where block = dim3(TILE_DIM, UNROLL) * and grid = dim3((n + TILE_DIM - 1) / TILE_DIM, (m + TILE_DIM - 1) / ...
16,469
#include "includes.h" __global__ void ppcg_calc_sd( const int x_inner, const int y_inner, const int halo_depth, const double alpha, const double beta, const double* r, double* sd) { const int gid = threadIdx.x+blockIdx.x*blockDim.x; if(gid >= x_inner*y_inner) return; const int x = x_inner + 2*halo_depth; const int col...
16,470
#include <iostream> #include <vector> __global__ void ifpairmabite( int * v, std::size_t size ) { // Get the id of the thread ( 0 -> 99 ). auto tid = threadIdx.x; // Each thread fills a single element of the array. if (!(v[tid] % 2)) v[ tid ] *= 2; } int main() { std::vector< int > v( 100 ); int * v_d = ...
16,471
#include "includes.h" #define L2HYS_EPSILON 0.01f #define L2HYS_EPSILONHYS 1.0f #define L2HYS_CLIP 0.2f #define data_h2y 30 //long h_windowx=Imagewidth/Windowx; //long h_windowy=ImageHeight/Windowy; //dim3 blocks(h_windowx,h_windowy);//h_windowx=ImageWidth/Windowx,h_windowy=ImageHeight/Windowy //dim3 thr...
16,472
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> #include <chrono> #define ROWS 1024 #define COLUMNS 16 using namespace std; int rand_int(int fMin, int fMax) { return fMin + (std::rand() % (fMax - fMin + 1)); } void printMatrix(int* A, int rows, int columns)...
16,473
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <stdbool.h> #define TILE_SIZE 512 #define WARP_SIZE 32 extern "C" void CSRmatvecmult(int* start, int* J, float* Val, int N, int nnz, float* x, float *y, bool bVectorized); extern "C" void ELLmatvecmult(int N, int num_cols_per_row , int * indices...
16,474
#include "includes.h" __global__ void kAddToEachPixel(float* mat1, float* mat2, float* tgtMat, float mult, unsigned int width, unsigned int height, unsigned int num_pix) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int numThreads = blockDim.x * gridDim.x; for (unsigned int i = idx; i...
16,475
#include <iostream> #include <stdio.h> #include <cuda_runtime.h> #include <curand_kernel.h> #include <algorithm> #include <time.h> using namespace std; #define THREADS_PER_BLOCK 32 #define NUM_BLOCKS 32 typedef double HighlyPrecise; const int GENOME_LENGTH = 14; const int GENE_MAX = 1; const float MUTATION_FACTOR =...
16,476
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<stdio.h> __global__ void Even(int* a,int n) { int k; int tid = threadIdx.x; if(tid%2 == 0 && tid != n-1) { //printf("etid = %d\n",tid); if(a[tid] > a[tid+1]){//printf("even : %d\n",a[tid]); k = a[tid]; a[tid] = a[tid+1]; a[tid+1] = ...
16,477
#include "includes.h" #ifdef INFINITY /* INFINITY is supported */ #endif float **A, **D, *d2; //Table A distance, D minimum distance,d2 tempTable 1-d __global__ void calc(float *d_D, int n, int k){ int i = blockIdx.x * blockDim.x + threadIdx.x; //We find i & j in the Grid of threads int j = blockIdx.y * blockDim.y ...
16,478
/** * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. * * Please refer to the NVIDIA end user license agreement (EULA) associated * with this source code for terms and conditions that govern your use of * this software. Any use, reproduction, disclosure, or distribution of * this software and relat...
16,479
/* * Null model based on cell link strength * ranged between 0 and 1 * * CUDA version * * compile with nvcc nco.cu -o nco -lcuda */ #include <stdlib.h> #include <stdio.h> #include <cuda.h> #include <math.h> #include <time.h> #include <curand_kernel.h> __global__ void nullmodel(float *M, int *out, curandState...
16,480
/* * Neuron.cpp * * Created on: Jun 22, 2016 * Author: trabucco */ #include "Neuron.cuh" long long Neuron::n = 0; Neuron::Neuron(int nConnections) { activation = 0; activationPrime = 0; connections = nConnections; default_random_engine g(time(0) + (n++)); normal_distribution<double> d(0, 1); weighted...
16,481
#include <cuda_runtime.h> #include <stdio.h> __device__ float devData; __global__ void checkGlobalVariable() { printf("Device: the value of the global variable is %f\n", devData); devData += 2.0f; } int main(void) { float value = 3.14f; cudaMemcpyToSymbol(devData, &value, sizeof(float)); printf("...
16,482
#include "includes.h" __global__ void checkIndex(void) { printf("threadIdx:(%d, %d, %d)\n", threadIdx.x, threadIdx.y, threadIdx.z); printf("blockIdx:(%d, %d, %d)\n", blockIdx.x, blockIdx.y, blockIdx.z); printf("blockDim:(%d, %d, %d)\n", blockDim.x, blockDim.y, blockDim.z); printf("gridDim:(%d, %d, %d)\n", gridDim.x, g...
16,483
__device__ float minmod(float a, float b, float c) { float ab = fminf(fabsf(a), fabs(b)) * (copysignf(1.0f, a) + copysignf(1.0f, b)) * 0.5f; return fminf(fabsf(ab), fabsf(c)) * (copysignf(1.0f, ab) + copysignf(1.0f, c)) * 0.5f; } __global__ void ReconstructFreeSurface(float *U, float *BottomIntPts, float *U...
16,484
#include "stdio.h" #define BLOCK_SIZE 4 #define N 32 __global__ void prod(int *A, int *B, int *C) { int blockRow = blockIdx.y; int blockCol = blockIdx.x; int Cvalue = 0; int row = threadIdx.y; int col = threadIdx.x; for (int m = 0; m < (N / BLOCK_SIZE); ++m) { __shared__ int ...
16,485
#include <stdio.h> #include <cuda.h> /* Lab8 Additional 1 * Input matrix MxN * Output matrix MxN where each element is the sum of elements in the same row and col. */ __global__ void rowColSum(int* a, int *b, int m, int n){ int tid = threadIdx.x; // Get row and col index int rowIndex = tid % m; ...
16,486
#include<iostream> #include<cuda_runtime.h> #define NUM_BLOCKS 16 #define BLOCK_WIDTH 1 __global__ void hello() { printf("\n Hello World ! I am thread in block %d ", blockIdx.x); } int main() { hello<<<NUM_BLOCKS, BLOCK_WIDTH>>>(); cudaDeviceSynchronize(); printf("\n Thats all !"); getchar(); return 0; }
16,487
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> const int INF = 10000000; const int V = 10010; void input(char *inFileName); void output(char *outFileName); void block_FW(); int ceil(int a, int b); void callP1(int r); void callP2(int r, int *block_start_x, int *block_start_y, int *block_height, int...
16,488
/** * Vector reverse: A[i] = B[SIZE - i]. * */ #include <stdio.h> #include <cuda_runtime.h> // SIZE is defined to be multiple of the number of threads #define SIZE 8 #define THREADS_PER_BLOCK 2 __global__ void vectorRev( int *A, int *B, int size) { int index = blockDim.x * blockIdx.x + threadIdx.x; B[ i...
16,489
#include "includes.h" __global__ void x_avpb_py_i32 (int* x, int a, int* v, int b, int* y, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { y[idx] += x[idx] * (a * v[idx] + b); } }
16,490
#include <cstdio> class Layer_info { public: int M, N, O; float *opt; float *preact; float *bias; float *weight; float *bp_opt; float *bp_preact; float *bp_weight; Layer_info(int M, int N, int O); ~Layer_info(); void setOutput(float *data); void clear(); vo...
16,491
#if GOOGLE_CUDA #define EIGEN_USE_GPU __global__ void default_function_kernel0(const float* __restrict__ Data, const float* __restrict__ K0, const float* __restrict__ K1, const float* __restrict__ K2, float* __restrict__ Output) { float Output_local[1]; __shared__ float Data_shared[128]; __shar...
16,492
#include <stdio.h> #include <future> #include <thread> #include <chrono> #include <iostream> #define N 1000000 __constant__ int factor = 0; __global__ void vectorAdd(int *a, int *b, int *c) { int i = blockIdx.x*blockDim.x + threadIdx.x; c[i] = factor*(a[i] + b[i]); } __global__ void matrixAdd(int **a,int *...
16,493
#include <iostream> #include <math.h> #include <functional> #include <stdlib.h> /* srand, rand */ #include <time.h> /* time */ #include <chrono> #define ROW_TILE_WIDTH 32 #define COL_TILE_WIDTH 32 #define EPSILON (1e-6) template<typename T> __global__ void naive_matrix_multiply(T *A, T *B, T* C, ...
16,494
#include <stdio.h> #include <iostream> #include <fstream> #include <vector> #include <utility> #include <cstring> #include <stdlib.h> #include <cuda.h> using namespace std; int main(){ ifstream in; in.open("enc_mat"); int r; in >> r; vector<pair<bool,vector<int> > > encmat(r); for(int i = 0; i...
16,495
#include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define ceil(a,b) ((a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1) void check_error (const char* message) { cudaError_t error = cudaGetLastError (); if (error != cudaSuccess) { printf ("CUDA error :...
16,496
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> static struct timeval ti; bool IN(int x, int y, int w, int h) { return (x) >= 0 && (y) >= 0 && (x) < (w) && (y) < (h); } int maxProf(unsigned char * arr, int matDim){ int max_value = 0; for (int i = 0; i < matDim; ++i) { if (arr[i] > max_value) ma...
16,497
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #define DATASIZE 1048756 int data[DATASIZE]; void GenerateNumbers(int *numbers, int size){ for(int i=0; i<size; i++){ numbers[i] = 1; } } __global__ static void sumOfSquare(int *num, int *result, int size){ int i, sum = 0; for...
16,498
#include <thrust/complex.h> #include <stdio.h> #include <stdlib.h> #include <png.h> #include <sys/time.h> #define M 200 #define DIE(...) { \ fprintf(stderr, __VA_ARGS__); \ exit(EXIT_FAILURE); \ } float points[4]; // c0_real, c0_image, c1_real, c1_image int w, h; char cpu_gpu[5]; // do the calculations in cpu...
16,499
#include "includes.h" __global__ void Thumbnail_ushort(cudaTextureObject_t ushort_tex, int *histogram, int src_width, int src_height) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if (y < src_height && x < src_width) { unsigned short pixel = (tex2D<unsigned short>(usho...
16,500
#include<stdio.h> #include<cuda.h> // this is the kernel // this is the function that actually runs on the GPU __global__ void dkernel() { printf("Hello World.\n"); } int main() { // kernel launch, use 1 thread dkernel<<<1,1>>>(); // synchronize CPU and GPU cudaDeviceSynchronize(); return 0; }...