serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
5,401
__global__ void create_combined_escape_carry_newline_count_index(char *file, long n, char *escape_carry_index, int *newline_count_index) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; long normal_chars_per_thread = max((n+stride-1) / stride, 64L); long chars_per_threa...
5,402
/* 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,int var_7,int var_8,int var_9,float var_10,float var_11,float var_12,float var_13,float var_14...
5,403
#include "includes.h" __global__ void SetMatrixVauleMinMaxY( float* matrix, int cols, int size, int id_min, int id_max, float value) { int id = blockDim.x*blockIdx.y*gridDim.x + blockDim.x*blockIdx.x + threadIdx.x; int id_row = id / cols; if (id_row >= id_min && id_row <= id_max && id < size) matrix[id] = value; }
5,404
#include <iostream> #include <math.h> #include <fstream> #include <vector> #include <sstream> #include <time.h> #include <stdlib.h> // For the CUDA runtime routines (prefixed with "cuda_") #include <cuda_runtime.h> using namespace std; const int THREADS_PER_BLOCK = 256; /** * CUDA Kernel Device code */ /********...
5,405
__global__ void f(int * A, int *B) { int tid = threadIdx.x; int diff = (B - A); int x = B[tid]; int y = A[tid + diff - 1]; B[tid] = x + y; }
5,406
#include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/host_vector.h> #include <thrust/transform_reduce.h> #include <iostream> #include <unordered_map> template <uint8_t D> struct Coord { int32_t data_[D]; int32_t& operator[](int i) { return data_[i]; } const int32_t& operator[]...
5,407
/* GPU Kernels for the mesh to particles functions @author: Stefan Hegglin, Adrian Oeftiger */ extern "C" { __global__ void mesh_to_particles_2d( int nparticles, double* particles_quantity, double *mesh_quantity, const int nx, const int ny, double *wij, double *wi1j, double *wij1, double *wi1j1,...
5,408
#include <stdio.h> #include <stdint.h> #include <string.h> #include <math.h> void Print_matrix(int N, FILE *f, double *m, long int n); __global__ void Jacobi(long int n, double *in, double *out); int main(void) { int N = 128; int block = 1024; int grid = N * N / 1024; double *heat = (double *) calloc(size...
5,409
#include <stdio.h> #include <cuda.h> __global__ void K() { printf("%d\n", threadIdx.x + threadIdx.y); } int main() { dim3 block(3, 4); K<<<1, block>>>(); cudaDeviceSynchronize(); return 0; }
5,410
#include "includes.h" __global__ void devFillAffectedTriangles(int nFlip, int *pTaff, int *pTaffEdge, int *pEnd, int2 *pEt) { unsigned int i = blockIdx.x*blockDim.x + threadIdx.x; while (i < nFlip) { int e = pEnd[i]; pTaffEdge[i] = i; pTaffEdge[i + nFlip] = i; pTaff[i] = pEt[e].x; pTaff[i + nFlip] = pEt[e].y...
5,411
#include "includes.h" __global__ void GPUKernel_VpVm_tiled(int a, int bstart, int bsize,int v,double * in,double * outp,double * outm) { int blockid = blockIdx.x*gridDim.y + blockIdx.y; int id = blockid*blockDim.x + threadIdx.x; int v2 = v*v; if ( id >= v2*bsize ) return; // id : b*v2+c*v+d int d = id%v; int...
5,412
/* Furthest point sampling GPU implementation * Original author: Haoqiang Fan * Modified by Charles R. Qi * All Rights Reserved. 2017. */ __global__ void cumsumKernel(int b,int n,const float * __restrict__ inp,float * __restrict__ out){ const int BlockSize=2048; const int paddingLevel=5; __shared__ float bu...
5,413
#include <stdlib.h> #include <stdio.h> __device__ int mandelbrot_point(float x, float y) { int max_iteration = 1000; int iteration; float a,b, new_a, new_b; a = 0.0f; b = 0.0f; new_a =0.0f; new_b =0.0f; iteration = 0; while (a*a + b*b <= 3.0f && iteration < max_iteration) { ...
5,414
#include <time.h> #include <stdio.h> #define N 10000000 __global__ void increment(int *array, int length) { int idx = blockIdx.x*blockDim.x + threadIdx.x; if (idx < length) { array[idx] = array[idx] + 1; } } int main(int x) { int bytes = N*sizeof(int); int* a = (int*)malloc(bytes); in...
5,415
#include "includes.h" __global__ void column_sum(const float* data, float* sum, int nx, int ny, int num_threads, int offset ) { float s = 0.0; const uint idx = threadIdx.x + blockIdx.x*num_threads+offset; for(int i =0; i < ny; i++) { s += data[idx + i*nx]; } sum[idx] = s; }
5,416
#include "includes.h" __global__ void Census_Kernel(unsigned char * MemSrc, unsigned int * MemDst, int eps, int Width, int Height) { //=============================================================================================== // //====================================================================================...
5,417
/* * FileName: RayTracer_Kernel.cu * * Programmer: Jiayin Cao */ //the sum for scan int* g_ScanSum[2]; //some helper functions __device__ void d_normalize( float4* v ) { float s = v->x * v->x + v->y * v->y + v->z * v->z; s = sqrt(s); v->x /= s; v->y /= s; v->z /= s; } //cross product _...
5,418
#include "includes.h" __global__ void NmDistanceKernel(int b,int n,const float * xyz,int m,const float * xyz2,float * result,int * result_i){ const int batch=512; __shared__ float buf[batch*2]; for (int i=blockIdx.x;i<b;i+=gridDim.x){ for (int k2=0;k2<m;k2+=batch){ int end_k=min(m,k2+batch)-k2; for (int j=threadIdx.x;j...
5,419
#include "TDES.cuh" namespace TDESCA { __device__ chunk64 TDES::Encode(chunk64 key1, chunk64 key2, chunk64 key3, chunk64 data) { chunk64 tempData = cipherMachine.Encode(key1, data); tempData = cipherMachine.Decode(key2, tempData); return cipherMachine.Encode(key3, tempData); } __device__ chunk64 TDES::D...
5,420
// 20181201 // Yuqiong Li // a basic CUDA function to test working with device constant memory #include <stdio.h> #include <cuda.h> const unsigned int N = 10; // size of vectors __constant__ float const_d_a[N]; // filter in device const memory int main() { float * a, * b; // a and b are vectors. c is the re...
5,421
#include "cuda.h" #include "cuda_runtime_api.h" #include <inttypes.h> extern "C" __global__ void kernel0(int32_t* input, int32_t input_length, double* output, int32_t output_length, int32_t output_size) { for (int32_t j = blockIdx.x * blockDim.x ...
5,422
// X = H , y = W #include<iostream> #include<stdio.h> #include<cuda.h> #include<ctime> #include<cstdlib> #include<cuda_profiler_api.h> using namespace std; // serially intializing tensor of the image void tensor_init(int * image, int N, int H, int W, int C){ /* Initialise the tensor for the conv...
5,423
#include "cuda_helpers.cuh" // limited version of checkCudaErrors from helper_cuda.h in CUDA examples #define checkCudaErrors(val) check_cuda( (val), #val, __FILE__, __LINE__ ) void check_cuda(cudaError_t result, char const *const func, const char *const file, int const line) { if (result) { std::cerr << ...
5,424
#include "includes.h" __global__ void fillCondensedAdjacencyKernel(int size, int *aggregateIdx, int *adjIndexesOut, int *adjacencyOut, int *permutedAdjIndexesIn, int *permutedAdjacencyIn) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < size) { int oldBegin = permutedAdjIndexesIn[ aggregateIdx[idx] ]; int ne...
5,425
#include <stdint.h> #include <stdio.h> #include <thrust/copy.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #define LIBRARY 0 #define HOST 1 #define DEVICE 2 #define CHECK(call) \ { \ const cudaError_...
5,426
#include <cuda.h> // Kernel definition __global__ void VecAdd(float* A, float* B, float* C) { int i = threadIdx.x; C[i] = A[i] + B[i]; }
5,427
// Compile: nvcc -arch=sm_61 -std=c++11 assignment5-p4.cu -o assignment5-p4 #include <cmath> #include <cuda.h> #include <iostream> const uint64_t N = (1 << 10); using namespace std; __global__ void kernel1(uint64_t* A, uint64_t* B, uint64_t* C) { // SB: Write your code here } __global__ void kernel2(uint64_t* A,...
5,428
#include "scan.cuh" #include "stdio.h" __global__ void hs_scanl(float *g_odata, float *g_idata, int n){// another possible version extern volatile __shared__ float temp[]; // allocated on invocation int thid = threadIdx.x; int thlen = blockDim.x; int blid = blockIdx.x; int id = thlen * blid + thid; int pout ...
5,429
/* * Russell Taylor(rtaylor) * Matt Crusse(macrusse) * CPE458-01 Lab 1 Winter 2013 */ #include <sys/stat.h> #include <sys/mman.h> #include <errno.h> #include <string.h> #include <stdarg.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <stdint.h> #define TILE_SIZE 32 /* C...
5,430
#include <stdio.h> #include <stdint.h> #define BLK_SIZE 128 __global__ void integral_kernel(float* in, float* inSum, float* carry, uint32_t w, uint32_t h) { __shared__ float tmp[2*BLK_SIZE]; int tdx = threadIdx.x; int idx0 = (threadIdx.x + blockIdx.x*blockDim.x)*2 + (blockIdx.y*blockDim.y + threadIdx.y)*w; ...
5,431
/* Copyright (c) 1993-2015, NVIDIA CORPORATION. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of ...
5,432
/** * 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 relate...
5,433
#include "includes.h" __global__ void kernel5( int *a, int dimx, int dimy ) { }
5,434
#include <iostream> #include <ctime> #include <curand.h> using namespace std; #define n 1048576*2 // Size of array M (should be a power of 2 // Function that catches the error void testCUDA(cudaError_t error, const char *file, int line) { if (error != cudaSuccess) { printf("There is an error in file %s at line ...
5,435
#include <iostream> void check(const char *file, const int line, cudaError_t err) { if (err != cudaSuccess) { std::cerr << file << ":" << line << " CUDA call failed with error: " << cudaGetErrorString(err) << std::endl; std::terminate(); } } #define CHECK(x) check(__FILE__, __LINE__, (x)) __global__ v...
5,436
#include <cstdio> #define N 64 #define TPB 32 float scale(int i, int n) { return ((float)i)/(n - 1); } __device__ float distance(float x1, float x2) { return sqrt( (x2 - x1)*(x2 - x1) ); } __global__ void distanceKernel(float *d_out, float *d_in, float ref) { const int i = blockIdx.x*blockDim.x + thread...
5,437
#include <stdio.h> #define QUEENS 10 __device__ void kiir(char *A) { char s[QUEENS*21 + 1]; int k = 0; for(int i = 0; i < QUEENS; i++) { for(int j = 0; j < QUEENS; j++) { if(A[i] == j) s[k++] = 'Q'; else s[k++] = '.'; ...
5,438
//To compile should add "-lfftw3 -lgsl" #include <stdio.h> #include <math.h> // #include <gsl/gsl_rng.h> #include <cstdio> #include <cstdlib> #include <string> #include <iostream> #include <time.h> //#include <fftw3.h> #include <complex> #include <cufft.h> using namespace std; struct particle3D{ int number; double *...
5,439
#include "includes.h" __global__ void GaussianEliminationShared(const int clusterSize,float *x, const float *diagonal_values , const float *non_diagonal_values ,float *y ) { const int index = blockIdx.x ; __shared__ float shared_m[9][9]; // size of cluster for (int i = 0; i < clusterSize;++i) { for (int j = 0; j < clu...
5,440
#include <iostream> #include <chrono> __global__ void polynomial_expansion (float* poly, int degree, int n, float* array) { //TODO: Write code to use the GPU here! //code should write the output back to array int index = blockIdx.x * blockDim.x + threadIdx.x; if( index < n ) { float out = 0.0; flo...
5,441
#include <iostream> #include <cstdlib> #include <ctime> #define MAXN 30000000 #define A (-1.0) #define B (1.0) //säieryhmän koko #define LOCAL_SIZE 1024 //säieryhmien määrä //#define WG_COUNT (MAXN/LOCAL_SIZE+1) //ydin, jolle annetaan kaksi n kokoista vektoria x ja y, sekä //liukuluku m, joille suoritetaan axpy-op...
5,442
#include <cstdio> #include <iostream> #include <chrono> #define N 5000 void cpuAdd(int *h_a, int *h_b, int *h_c) { int tid = 0; while (tid < N) { h_c[tid] = h_a[tid] + h_b[tid]; tid += 1; } } int main(void) { int h_a[N], h_b[N], h_c[N]; for (int i = 0; i < N; i++) { ...
5,443
#include <stdio.h> #define SIZE 1024*1024*4 __global__ void reduce0(unsigned int *g_idata, unsigned int *g_odata, long size){ // dynamically allocated shared memory extern __shared__ unsigned int sdata[]; // set up thread ids: within a blo...
5,444
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> void secuential(const int a[] ,const int b[], int c[], const unsigned int sqrt_dim); __global__ void multiply( const int* A, const int* B,int* C, int width, int tile_width)...
5,445
#include <stdio.h> // Simple transformation kernel __global__ void transformKernel( float* d_output, cudaTextureObject_t texObj, int width){ // Calculate normalized texture coordinates float u = threadIdx.x/(float) blockDim.x; // Read from texture and write to global memory d_output[threadId...
5,446
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<stdio.h> __global__ void print_details_exercise() { printf("threadIdx.x : %d, threadIdx.y : %d, threadIdx.z :%d, blockIdx.x : %d, blockIdx.y : %d, blockIdx.z : %d, blockDim.x : %d, blockDim.y : %d, gridDim.x : %d, gridDim.y : %d\n", threadIdx....
5,447
#include <stdio.h> // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.width + col) typedef struct { int width; int height; float* elements; } Matrix; // Thread block size #define BLOCK_SIZE 16 // Forward declaration of the matrix multiplication kernel __global__ void MatMulKernel(c...
5,448
/* Voxel sampling GPU implementation * Author Zhaoyu SU * All Rights Reserved. Sep., 2019. */ #include <stdio.h> #include <iostream> #include <float.h> // import FLT_EPSILON __device__ int get_batch_id(int* accu_list, int batch_size, int id) { for (int b=0; b<batch_size-1; b++) { if (id >= accu_list[b]...
5,449
#include <cstdio> #define N 64 #define B 2 #define T 32 __global__ void dl(int* in) { int tid = threadIdx.x + blockIdx.x * blockDim.x; if(blockIdx.x % 2 == 0) { if(in[tid] % 2 == 0) in[tid]++; // Fine because conditional synchronization will // happen within a block. __syncthreads(); ...
5,450
#include "includes.h" __global__ void calculation( int *a, int *b, int *c, int constant, int vector_size ) { int tid = (blockIdx.x*blockDim.x) + threadIdx.x; // this thread handles the data at its thread id if (tid < vector_size){ // Read in inputs int prev_a = a[tid>0?tid-1:(vector_size-1)]; int curr_a = a[ti...
5,451
#include "includes.h" __global__ void global_reduce_kernel(float * d_out, float * d_in) { int myId = threadIdx.x + blockDim.x * blockIdx.x; int tid = threadIdx.x; // do reduction in global mem for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1) { if (tid < s) { d_in[myId] += d_in[myId + s]; } __syncthreads(); ...
5,452
#include <stdio.h> #include <pthread.h> #include <unistd.h> //sleep void *hello (void *arg) { int *ptrToThreadNumber = (int *)arg; sleep(5); printf("HelloThread %d\n",*ptrToThreadNumber); return 0; } int main(void) { pthread_t tid; int threadNum=1; //pthread_create creates a new thread and makes it executable...
5,453
struct Point { double* x; double* y; double* z; }; struct Ref { Point pos; Point dir; double* distance; }; struct View { int size; Point pos; Point dir; double* distance; __device__ Ref operator[](int i) const { return {{pos.x + i, pos.y + i, pos.z + i}, {dir.x + i, dir.y + i, d...
5,454
#include <cuda.h> extern "C" { int cudaPyHostToDevice(void*, void*, size_t, size_t); int cudaPyDeviceToHost(void*, void*, size_t, size_t); void* cudaPyAllocArray(size_t, size_t); int cudaPyFree(void*); } int cudaPyHostToDevice(void* dst, void* src, size_t N, size_t tsize) { return cudaMemcpy(dst, src, N * ...
5,455
#include <stdio.h> __global__ void hello_kernel() { printf("Hello from GPU thread (%d, %d) = (%d, %d) * (%d, %d) + (%d, %d)\n", threadIdx.x, threadIdx.y, blockIdx.x, blockIdx.y, blockDim.x, blockDim.y, blockIdx.x * blockDim.x + threadIdx.x, blockIdx.y * blockDim.y + threadIdx.y); } ...
5,456
#include <iostream> #include <math.h> //#include <cuda_runtime.h> // function to copy the elements of an array and decrement to the compiler not override it __global__ void newtonKernel(int n, float4* x, float4* y, float4* z){ float4 result = make_float4 (1.0f,1.0f,1.0f,1.0f); int index = blockIdx.x * blockD...
5,457
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> #include <ctime> __global__ void sumArraysOnDevice(float* A, float* B, float* C, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < N) C[idx] = A[idx] + B[idx]; } __global__ void sumArraysZero...
5,458
//host処理系のグローバル変数定義 #ifndef INCLUDED_HOSTVALUESACCESSER #define INCLUDED_HOSTVALUESACCESSER #include <stdio.h> int cnnOutputNumsNums; int *cnnOutputNums; int execFlg; int execFlgTraining = 0; int execFlgOnline = 1; int sv_xNums; int sv_yNums; int svChannelNums; int miniBatchNums; float *cnnBnBeta; float *cnnBnGamma...
5,459
/****************************************************************************** *cr *cr (C) Copyright 2010 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr *****************************************************************...
5,460
/* Voxel sampling GPU implementation * Author Zhaoyu SU * All Rights Reserved. Sep., 2019. */ #include <stdio.h> #include <time.h> #include <sys/time.h> #include <iostream> #include <vector> #define USECPSEC 1000000ULL __device__ inline int binary_search(const long long* input_voxel_idx, ...
5,461
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <assert.h> static const int WORK_SIZE = /*256*/ 2; /** * This macro checks return value of the CUDA runtime call and exits * the application if the call failed. */ __device__ unsigned int bitreverse1(unsigned int number) { number = ((0xf0f0f0f0 & ...
5,462
//pass: checka a função device (comparar com o cuda69_test2) #include <stdio.h> #include <cuda.h> #include <assert.h> #define N 2//64 __device__ void bar(int* p) { p[threadIdx.x] = 0; //printf(" %d; ", p[threadIdx.x]); } __global__ void foo(int* p) { bar(p); } int main() { int *c; int *dev_c; c = (int*)ma...
5,463
#include "includes.h" __global__ void clock_block(clock_t *d_o, clock_t clock_count) { unsigned int start_clock = (unsigned int) clock(); clock_t clock_offset = 0; while (clock_offset < clock_count) { unsigned int end_clock = (unsigned int) clock(); // The code below should work like // this (thanks to modular arith...
5,464
#include <stdio.h> #include <cuda_runtime.h> __global__ void gpu_add(int* a, int* b, int* c) { *c = *a + *b; } int main() { int a, b, c; /*Variáveis na stack desse programa (na memória principal)*/ int *d_a, *d_b, *d_c; /*Variáveis que alocaremos na memória da GPU*/ cudaMalloc((void **)&d_a, sizeof(int)...
5,465
/* * * Matthew Baron * Homework #4 * 3/16/2015 * CSCI 4150 * CUDA Version #1 * */ #include <stdio.h> #include <stdlib.h> #include <iostream> #include <math.h> #include <ctime> #include <iomanip> #include <cuda.h> #define BLOCK_SIZE 16 using namespace std; //Row-Major Matrix struct typedef struct { int wid...
5,466
#include "kernel.cuh" #include <stdio.h> __global__ void VecAdd(const int* A, const int* B, int* C, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) C[i] = A[i] + B[i]; } __global__ void VecSub(const int* A, const int* B, int* C, int N) { int i = blockDim.x * blockIdx.x + thre...
5,467
#include "includes.h" //original c by brade conte, ported to CUDA by jody #define uchar unsigned char // 8-bit byte #define uint unsigned int // 32-bit word #define DBL_INT_ADD(a,b,c) if (a > 0xffffffff - (c)) ++b; a += c; #define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b)))) #define ROTRIGHT(a,b) (((a) >> (b)) |...
5,468
#include <stdio.h> int main() { int driverVersion = 0; cudaDriverGetVersion(&driverVersion); printf("CUDA driver: %d\n", driverVersion); int runtimeVersion = 0; cudaRuntimeGetVersion(&runtimeVersion); printf("CUDA runtime: %d\n", runtimeVersion); int numDevices; cudaError_t st...
5,469
#include <cuda.h> #include <cuda_runtime_api.h> #define N_LOOPS 100 #define N_FLOPS_PER_BLOCK 24 #define N_FLOPS_PER_LOOP 76800 #define N_FLOPS_PER_KERNEL 76816 #define SHARED_MEM_SIZE 12000 #define FLOPS_BLOCK \ reg0 = reg1 * reg2 + reg3; \ reg5 = reg6 * reg6; \ reg1 = reg2 * reg3 + reg4; \ ...
5,470
#include "cuda_ellipse_overlaps.cuh" #include <vector> #define PI 3.14159265358979 using std::vector; __device__ inline void CalculateRangeAtY(double *elpparm, double y, double *x1, double *x2) { double A, B, C, D, E, F; A = elpparm[0], B = elpparm[1], C = elpparm[2]; D = elpparm[3], E = elpparm[4], F = ...
5,471
#include<iostream> #include <thrust/host_vector.h> #include <thrust/device_vector.h> int main(){ int size = (int)1.6e8; thrust::host_vector<int32_t> test(size); for (int i = 0; i < size; i++) test[i] = i; for (int i = size - 5000 ; i < size; i++) std::cout << test[i] << " " ; re...
5,472
#include <stdlib.h> #include <stdio.h> #include <time.h> #define MATRIX_SIZE 10000 #define RANGE_NUMBERS 10 #define DIM_THREADS 32 __host__ __device__ inline void setAt(int *m, int i, int j, int v) { *(m + i*MATRIX_SIZE + j) = v; } __host__ __device__ inline int getAt(int *m, int i, int j) { return *(m + i*...
5,473
#include "includes.h" __global__ void add(int n, float *x, float *y) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < n) y[i] = x[i] + y[i]; }
5,474
// downloaded from: https://www.cs.usfca.edu/~peter/cs625/code/cuda/vec_add.cu /* 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 <n> * n is the vector length * * Input: None * Output: Resu...
5,475
#include <iostream> #include <stdio.h> #include <stdbool.h> /*helps with bool data type*/ #include <string.h> /* memset */ #include <unistd.h> /* close */ #include <emmintrin.h> #include <sys/time.h> /*allows system type*/ struct timeval start, end; void starttime() { gettimeofday( &start, 0 ); } void endtime(c...
5,476
#include "includes.h" __global__ void vecAdd(unsigned int *A_d, unsigned int *B_d, unsigned int *C_d, int WORK_SIZE) { //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // **** Populate vecADD kernel function **** //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // Get our global thread ID int id = blockIdx.x*blockDim.x+thread...
5,477
#include <stdio.h> #define RADIUS 4 #define BLOCK_DIM_X 32 __constant__ float coef[RADIUS + 1]; __global__ void stencil(float* out, float* in) { __shared__ float smem[BLOCK_DIM_X + (2 * RADIUS)]; int idx = (blockIdx.x * blockDim.x) + threadIdx.x; int sidx = threadIdx.x + RADIUS; smem[sidx] = in[idx]; if (threa...
5,478
#include <cuda.h> #include <stdio.h> #include <time.h> #include <stdlib.h> #define BLOCK_SIZE 1024 // first kernel - does scan for each block __global__ void blockSumScanKernel(float* d_input, float* d_output, size_t size) { __shared__ float blockOutput[BLOCK_SIZE]; // indexing variable int i = threa...
5,479
/* Unified Memory in CUDA makes this easy by providing a single memory space accessible by all GPUs and CPUs in your system. To allocate data in unified memory, call cudaMallocManaged(), which returns a pointer that you can access from host (CPU) code or device (GPU) code. To free the data, just pass the pointer to cu...
5,480
// *************************************************************************** // In Class Activity // Name: Yujin Yoshimura // Parallel Programming Date: April 8, 2020 // *************************************************************************** // This sequential program demonstrates Matrix Multiplication. // // For...
5,481
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #define blockSize 32 #define PROMIEN 30 #define NUM_ELEMENTS 944 //( N = rozmiar tablicy - 2 * R) #define cudaCheck(error) \ if (error != cudaSuccess) {\ printf("BLAD URUCHOMINIA: %s at %s:%d\n", cudaGetErrorString(error), __FILE__, _...
5,482
#include <stdio.h> #include <algorithm> #include <cmath> __global__ void mish(float* tx, float* aten_mul) { float tx_1 = __ldg(tx + (long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)); aten_mul[(long long)(threadIdx.x) + 512ll * (long long)(blockIdx.x)] = tx_1 * (tanhf(tx_1>20.f ? tx_1 : (log1pf(expf(tx_1)...
5,483
#include "includes.h" #define SIZE (100 * 1024 * 1024) __global__ void histo_kernel_optimization(unsigned char *buffer, int size, unsigned int *histo) { __shared__ unsigned int temp[256]; temp[threadIdx.x] = 0; __syncthreads(); int i = threadIdx.x + blockDim.x * blockIdx.x; int stride = blockDim.x * gridDim.x; wh...
5,484
#include "includes.h" __global__ void kSoftMaxGrad(float* mat, float* labels, float* target, unsigned int width, unsigned int height) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int numThreads = blockDim.x * gridDim.x; for (unsigned int i = idx; i < width * height; i += numThreads) ...
5,485
#include <assert.h> #include <errno.h> #ifndef WIN32 #include <getopt.h> #endif #include <limits.h> #include <math.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include "c63cpu.cuh" // Motion estimation for 8x8 bloc...
5,486
#include "includes.h" __global__ void SimpleClone( const float *background, const float *target, const int *mask, float *output, const int wb, const int hb, const int wt, const int ht, const int oy, const int ox ) { const int yt = blockIdx.y * blockDim.y + threadIdx.y; const int xt = blockIdx.x * blockDim.x + threadIdx...
5,487
#include <stdio.h> #include <stdlib.h> __global__ void kernel(int *array){ int index_x = blockIdx.x * blockDim.x + threadIdx.x; int index_y = blockIdx.y * blockDim.y + threadIdx.y; int grid_width = gridDim.x * blockDim.x; int index = index_y * grid_width + index_x; int result = blockIdx.y * gridDim.x + blockIdx.x;...
5,488
#include <iostream> #include <cstdio> using namespace std; #define BLOCK_SIZE 32 __global__ void gpuMM(float *A, float *B, float *C, int N) { // Matrix multiplication for NxN matrices C=A*B // Each thread computes a single element of C int row = blockIdx.y*blockDim.y + threadIdx.y; int col = blockIdx.x*blockDim....
5,489
#include <stdio.h> __global__ void kernel(float* A) { int j = blockDim.x * blockIdx.x + threadIdx.x; int i = blockDim.y * blockIdx.y + threadIdx.y; float cr = float(j) / gridDim.x / blockDim.x * 3.0f - 2.0f; float ci = float(i) / gridDim.y / blockDim.y * 3.0f - 1.5f; float zr = 0.0f; float zi = 0.0f; int i...
5,490
#include <iostream> #include <memory> #include <cassert> using namespace std; #include <cuda.h> __global__ void getValue(float *outdata, float *indata) { outdata[0] = indata[0] + 3.0f; } int main(int argc, char *argv[]) { int N = 1024; CUstream stream; cuStreamCreate(&stream, 0); float *hostF...
5,491
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #define N 500 struct timeval start, end; typedef struct Matrix { int rows; int cols; double ** matrix; } Matrix; Matrix buildMatrix(int r, int c) { Matrix temp; temp.rows = r; temp.cols = c; temp.matrix = (d...
5,492
#include "includes.h" __global__ static void findCBar(double* cOld, double* cCurr, double* cBar, int nx) { // Matrix index int globalIdx = blockDim.x * blockIdx.x + threadIdx.x; int globalIdy = blockDim.y * blockIdx.y + threadIdx.y; // Set index being computed int index = globalIdy * nx + globalIdx; // Find cBar cBar...
5,493
#include <stdio.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #define NUM 10 __global__ void averagePx(int * a, int * c) { int width = blockIdx.x; printf("w: %d\n", width); if(width < NUM*NUM) { c[width] = a[width] / 2; } } int main () { int a[NUM][NUM], c[NUM*NUM]...
5,494
/* Cuda implementation of the VAI forward solver Optimization 2-b: Here we switched to float4 and int4 data types for more effecient memory access and computing indices. Also, loop unrolling in computing the neighboring elements contribution is dones is done Optimization 3 : Since we on...
5,495
#include "includes.h" __global__ void apply_weight_decay_util_kernel( const float4 * __restrict learning_rates, float4 * __restrict weights, float weight_decay, int elem_count) { int elem_id = blockDim.x * blockIdx.x + threadIdx.x; if (elem_id < elem_count) { float4 val = learning_rates[elem_id]; float4 current_weight ...
5,496
#include <cuda.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #include "curand_kernel.h" #include <memory> #include <ctime> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <algorithm> #include <numeric> using defer = std::shared_ptr<void>; #define HEIGHT 32 #define WIDTH 32...
5,497
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void threadCounting_noSync(int *a){ (*a)++; } int main(void){ int a = 0; int *d; cudaMalloc((void**)&d, sizeof(int)); cudaMemset(d, 0, sizeof(int)*1); threadCounting_noSync<<<10240,512>>>(d); cudaDeviceSynchronize()...
5,498
#include<iostream> #include<stdio.h> //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ __global__ void evalJulia(double *d_pixel, double *d_temp){ int x_index = threadIdx.x + 2*t...
5,499
/*! * Compute the Pearson correlation of a cluster in a pairwise data array. * * @param x * @param y * @param labels * @param sampleSize * @param cluster * @param minSamples */ __device__ float Pearson_computeCluster( const float *x, const float *y, const char *labels, int sampleSize, ch...
5,500
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #include <stdio.h> #define BLOCKS_NUM 200 #define BLOCK_SIZE 256 #define DATA_TYPE int __global__ void my_kernel( DATA_TYPE* v1, DATA_TYPE* v2, DATA_TYPE* out ){ unsigned int n = threadIdx.x + blockIdx.x * BLOCK_SIZE; if ( n >= 5000...