serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
1,401
extern "C" __global__ void mmkernel( float* a, float* b, float* c, int pitch_a, int pitch_b, int pitch_c, int n, int m, int p ) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y; float sum = 0.0; for( int k = 0; k < p; ++k ) sum += b[i+pitch_b*k] * c[k+pitch_c*j]; a[i+pi...
1,402
#include "cuda_profiler_api.h" #include <stdio.h> void print_gpu_memory_usage() { size_t free_byte; size_t total_byte; cudaError_t cuda_status = cudaMemGetInfo(&free_byte, &total_byte); if (cudaSuccess != cuda_status) { printf("Error: cudaMemGetInfo fails, %s \n", cudaGetErrorString(cuda_stat...
1,403
#include <stdio.h> #include <math.h> #include <iostream> using namespace std; #define TDB 1024 //Tamaño del bloque #define hy 0.34 #define hx 0.34 #define LT 1 //lado tuberia __device__ double my_floor(double num) { if (num >= LLONG_MAX || num <= LLONG_MIN || num != num) { return num; } int n = ...
1,404
// You need to write a simple program to perform computation with 1D array in CPU and GPU, then compare the result. // includes, system #include <stdio.h> #include <assert.h> #include <cuda_runtime.h> // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char *msg); // Part 3 of 5: im...
1,405
#include <iostream> using namespace std; // Derived class class Rectangle { public: Rectangle() { width = (int *)malloc(sizeof(int)); height = (int *)malloc(sizeof(int)); } int getArea() { return (*width * *height); } int* width; int* heig...
1,406
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> static const int M = 16;//行 static const int N = 32;//列 #define CHECK_STATUS(status) \ if (status != cudaSuccess) \ fprintf(stderr, "File: %s\nLine:%d Function:%s>>>%s\n", __FILE__, __LINE__, __FUNCTION__,\ cudaGet...
1,407
#include <iostream> int main(void) { int n; cudaGetDeviceCount(&n); std::cout << n << " CUDA devices found." << std::endl; return 0; }
1,408
//////////////////////////////////////////////////////////////////////////////// // // FILE: burrows_wheeler_encoder.cu // DESCRIPTION: uses bitonic sort to encode a string with BWT // AUTHOR: Dan Fabian // DATE: 4/5/2020 #include <iostream> #include <stdio.h> using std::cout; using std::endl; // ...
1,409
#include <stdio.h> #include <stdlib.h> #include <algorithm> // Change the code here: // This should be changed to GPU kernel definition void vecAdd(int numElements, const float* a, const float* b, float* c) { for (int i = 0; i < numElements; i++) { c[i] = a[i] + b[i]; } } int main() { int num...
1,410
#include "includes.h" __global__ void ConvolutionRowGPU(double *d_Dst, double *d_Src, double *d_Filter, int imageW, int imageH, int filterR){ int k; double sum=0; int row=blockDim.y*blockIdx.y+threadIdx.y; int col=blockDim.x*blockIdx.x+threadIdx.x; for (k = -filterR; k <= filterR; k++) { int d = col+ k; if (d >= 0 &...
1,411
#include <thrust/sequence.h> #include <thrust/count.h> #include <thrust/execution_policy.h> #include <thrust/copy.h> #include <thrust/find.h> #include <iostream> #include <utility> using namespace std; struct saxpy { int *N; saxpy(int a) { cudaHostAlloc(&N, sizeof(int), 0); *N = a; } __host__ __device__ bool ...
1,412
#include<stdio.h> #include<cuda.h> void printDevProp(cudaDeviceProp devProp) { printf("%s\n", devProp.name); printf("Major revision number: %d\n", devProp.major); printf("Minor revision number: %d\n", devProp.minor); printf("Total global memory: %u", devProp.totalGlobalMem); ...
1,413
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand_kernel.h> #include <math_constants.h> #include <cuda_runtime.h> #define N 20000 #define GRID_D1 20 #define GRID_D2 2 #define BLOCK_D1 512 #define BLOCK_D2 1 #define BLOCK_D3 1 extern "C" { __global__ void rtruncnorm_kernel(float *vals, int...
1,414
#include "includes.h" __global__ void third_and_fourth_normal_component(float* z, float* xx, float* yy, float* zx, float* zy, int npix, float* N3) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < npix) { N3[i] = -z[i] - (xx[i]) * zx[i] - (yy[i]) * zy[i]; N3[npix + i] = 1; } }
1,415
#include<stdio.h> __global__ void safty(int *a, int N,int arg) { int i = threadIdx.x + blockIdx.x*blockDim.x; if(arg ==0) { if(i < N) { a[i] = 1; } } else { if(i <N) { a[i]*=2; printf("%d",a[i]); } } } int main() { int *a; size_t size = 100; int N = siz...
1,416
#include "includes.h" __global__ void Pi_GPU(float *x, float *y, int *totalCounts, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; // номер элемента int threadCount = gridDim.x * blockDim.x; //cмещение int countPoints = 0; for (int i = idx; i < N; i += threadCount) { if (x[i] * x[i] + y[i] * y[i] < 1) { co...
1,417
extern "C" __global__ void mmkernel( float* a, float* b, float* c, int pitch_a, int pitch_b, int pitch_c, int n, int m, int p ) { int tx = threadIdx.x; int i = blockIdx.x*64 + tx; int j = blockIdx.y*2; __shared__ float cb0[32], cb1[32]; float sum0 = 0.0, sum1 = 0., sum2 = 0.0, sum3 = 0.0; f...
1,418
#include <stdio.h> __global__ void print_hello_world(void) { printf("Hello world from GPU\n"); } int main(int argc, char **argv) { printf("Hello world from CPU!\n"); print_hello_world<<<2, 5>>>(); cudaDeviceSynchronize(); return 0; }
1,419
#include<stdio.h> #define ROW 1000 #define COL 1000 __global__ void mat_vect(int *a, int *b, long *c, int m, int n) { int col = blockIdx.x * blockDim.x + threadIdx.x; long sum = 0; if (col < n){ for(int i = 0; i < n; i++) { printf("matrix value: %d, vect value: %d \n", a[...
1,420
#include <stdio.h> #include <cuda.h> //be careful the block_size*block_size should not exceed 1024 #define BLOCK_SIZE 32 __global__ void pictureKernel(float* d_pix,int X, int Y); int main() { float *h_pixin, *h_pixout, *d_pix; int x=76,y=62,i; //2D data size int grid_x=x/BLOCK_SIZE,grid_y=y/BLOCK_SIZE; int size=x*...
1,421
#include <stdio.h> #include <stdlib.h> #include <math.h> #define size 1024 __global__ void sqrtvec(float *b, const float *a) { int i = threadIdx.x; b[i] = sqrtf(a[i]); } int main() { float a[size]; for (int i = 0; i < size; i++) { a[i] = (float)i; } float b[size] = {0}; float *da, *db; cudaMalloc((void**)&...
1,422
#include<stdio.h> // __global__ is the global kernel specifier. // identifies a kernel function (cuda c functions) __global__ void cuda_hello(){ // to print printf("Hello World from GPU!\n"); } int main() { // <<< >>> is the execution configuration syntax // it specify the number of threads that wi...
1,423
#include <stdio.h> #include <unistd.h> #define ALLOC_SIZE 1024 __global__ void access_offset_kernel(int offset) { int devMem[ALLOC_SIZE]; devMem[0] = 0; devMem[1] = devMem[0]; // for init/unused warnings if (offset >= 0) offset += (ALLOC_SIZE-1); // this slight difference in the condition...
1,424
#include <stdio.h> #include <cuda.h> __global__ void K1(int num) { num += num; ++num; } __device__ int sum = 0; __global__ void K2(int num) { atomicAdd(&sum, num); } __global__ void K3(int num) { __shared__ int sum; sum = 0; __syncthreads(); sum += num; } int main() { for (unsigned ii = 0; ii < 100; ++ii) { ...
1,425
// Check that types, widths, etc. match on the host and device sides of CUDA // compilations. Note that we filter out long double, as this is intentionally // different on host and device. // RUN: %clang --cuda-host-only -nocudainc -target i386-unknown-linux-gnu -x cuda -E -dM -o - /dev/null > %T/i386-host-defines //...
1,426
#include <cuda_runtime.h> #include <iostream> #include <stdlib.h> #include <time.h> __global__ void add(int * d_a,int *d_b,int n) { int idx = threadIdx.x; int i = 2,j = 1; do{ if(idx % i == 0) d_a[idx] += d_a[idx + j]; i *= 2; j *= 2; }while(n/=2); d_b[0] = d_a[0]; } int main() { int blag = 1; int n =...
1,427
#include "includes.h" __global__ void init_topp_id_val(int* topp_id_val_buf, int* topp_offset_buf, const int batch_size, const int vocab_size) { int tid = threadIdx.x; int bid = blockIdx.x; if(bid == 0) { for(int i = tid; i < batch_size + 1; i+= blockDim.x) { topp_offset_buf[i] = i * vocab_size; } } while(tid < vocab...
1,428
// // Created by lifan on 2021/5/17. //
1,429
#include <cmath> #include <vector> #include <cstring> #include <algorithm> using namespace std; typedef pair<int, int> prime_pot; //MAX determines the primes limit const unsigned MAX = 100010/60, MAX_S = sqrt(MAX/60); unsigned w[16] = {1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59}; unsigned short c...
1,430
/** * blockAndThread.cu * description: fill two arrays with blockId and threadId values * notes: compile with nvcc and parent code: * "nvcc blockAndThread.c blockAndThread.cu" * Program is similar to one that appears in Dr. Dobbs Journal. * The tutorial is available at: * http://www.ddj.com/hpc-high-perfo...
1,431
#define GEOMETRY_STAGE_GLOBAL #include "geometry_stage.cuh"
1,432
/* #ifndef __CUDACC__ #define __CUDACC__ #endif #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> __constant__ int M[3]; __global__ void convolution_1D_basic(int *N, int *P,int Mask_Width, int Width) { int i = blockIdx.x*blockDim.x + threadIdx...
1,433
#include <chrono> #include <fstream> #include <stdio.h> #include <string> #include <iostream> #include <math.h> __constant__ int DbMToWattConstDivisor = 1000; __constant__ double CTen = 10; __constant__ int P = 1; __device__ void d_dbm_to_watts( const int& dbm, double& results ) { const double pow = (P * dbm) / C...
1,434
#include "includes.h" __global__ void matrixMulCUDA2(float *C, float *A, float *B, int n) { /* Each thread computes more than 1 matrix elements */ // Define the starting row and ending row for each thread int startRow = threadIdx.y * TILE_WIDTH; int endRow = startRow + TILE_WIDTH; // Define the starting column and en...
1,435
#define dis2(a_x, a_y, b_x, b_y) (((a_x) - (b_x)) * ((a_x) - (b_x)) + ((a_y) - (b_y)) * ((a_y) - (b_y))) #define normalize(x) ((x) > 1.0? 1.0: ((x) < 0.0? 0.0: (x))) extern "C" __device__ double half_tan( unsigned a_x, unsigned a_y, unsigned b_x, unsigned b_y, unsigned c_x, unsigned c_y ) { double ac2 ...
1,436
#include <iostream> #include <memory> #include <cassert> using namespace std; #include <cuda.h> struct MyStruct { float *floats; float afloat; }; struct MyStruct2 { float *floats1; float *floats2; float afloat; }; __global__ void getValue(struct MyStruct mystruct, float *data) { data[0] = m...
1,437
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #define N 512 #define CLUSTER 10 __global__ void histrogram_atomic(int* d_a, int* d_b){ int threadId = threadIdx.x + blockIdx.x * blockDim.x; if (threadId < N) { int val = d_a[threadId]; //atomicAdd(&(d_b[val])...
1,438
/** * Sum two square matrix (A = B + C) * Exercise 3.1 of programming massively parallel processors book * Solution provided with matrix view as array * @author Niccolò Bellaccini */ #include <cuda.h> #include <stdio.h> #include <stdlib.h> //rand #include <time.h> //rand #include <math.h> //ceil #include <iostre...
1,439
#include <stdio.h> int reduceByHost(int *a, int n){ int sum = 0; for(int i = 0; i < n; i++){ sum += a[i]; } return sum; } /* a0 -- a1 -- a2 -- a3 -- a4 -- a5 -- a6 -- a7 :step0 -- b0 -------- b1 -------- b2 ---------b3 -- :step1 ---------c0 -------- c1 ---------c2--------- :step2 --------------...
1,440
#include "includes.h" __global__ void kernel_histo_iterated( unsigned int *ct, unsigned int *histo, unsigned int offset ){ extern __shared__ unsigned int temp[]; unsigned int index = threadIdx.x + offset; temp[index] = 0; __syncthreads(); int i = threadIdx.x + blockIdx.x * blockDim.x; unsigned int size = blockDim.x *...
1,441
#include <stdio.h> /* Host = CPU stuff Device = GPU Stuff */ __global__ void mykernel(void){ /*global indicates a function that runs on device called from host */ } int main(void) { mykernel<<<1,1>>>(); //Calls from host to device printf("hello world! \n"); return 0; }
1,442
#include "includes.h" extern "C" { } #define IDX2C(i, j, ld) ((j)*(ld)+(i)) #define SQR(x) ((x)*(x)) // x^2 __global__ void multiply_arrays(double* signals, double const* weights){ signals[blockIdx.x * blockDim.x + threadIdx.x] *= weights[blockIdx.x * blockDim.x + threadIdx.x]; }
1,443
// // Created by harish on 10.03.21. // #include "cudaData.cuh" #include <iostream> using namespace std; int* cudaData::getData(int dataSize,int* hostData) { int* deviceVec; cudaMallocManaged(&deviceVec,dataSize*sizeof(int)); cudaMemcpy(deviceVec, hostData, dataSize*sizeof (int),cudaMemcpyHostToDevice); ...
1,444
#include <stdio.h> #include <stdlib.h> #define TPB 512 __global__ void oddPopulate(int *A, int *O, int n, int *numOdds){ __shared__ int odds; if(threadIdx.x){ odds = 0; } __syncthreads(); int index = blockIdx.x * blockDim.x + threadIdx.x; if(index < n){ if(A[index] % 2 == 0){ ...
1,445
extern __device__ void BiAverage(double *A, double *B, int p0, int datasize, int logsize) { int stride = datasize; for (int q = 1; q <= logsize; q++) { stride = stride >> 1; if (p0 < stride) { A[p0] += A[p0 + stride]; } else { if (p0 < 2 * stride) { B[p0 - stride] += B[p0]; } } __s...
1,446
/* * Written by Sangho Lee (sangho@gatech.edu) */ #include <stdio.h> #include <unistd.h> #include <stdint.h> #define SIZE 2*1024*1024*1024 // 1 GiB // Tesla has 2687 MiB of Global Memory void cudasafe(cudaError_t error, char *message) { if (error != cudaSuccess) { fprintf(stderr, "ERROR: %s : %s\n", message, ...
1,447
#include <time.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> // cache size constant for convenience/readability const size_t CACHESIZE = 1.5 * (1<<20); // function to handle CUDA API call error val returns void check_error(cudaError_t cudaerr) { if (cudaerr != cudaSuccess) { printf("FAIL...
1,448
#include "includes.h" __global__ void matrixMultiplyShared(float * A, float * B, float * C, int numARows, int numAColumns, int numBRows, int numBColumns, int numCRows, int numCColumns) { __shared__ float sA[TILE_SIZE][TILE_SIZE]; // Tile size to store elements in shared memory __shared__ float sB[TILE_SIZE][TILE_SIZE...
1,449
// Created 25-Jan-2014 by Daniel Margala (University of California, Irvine) <dmargala@uci.edu> #include <iostream> int main(int argc, char **argv) { int deviceCount; cudaGetDeviceCount(&deviceCount); if (deviceCount == 0) { std::cout << "No CUDA GPU has been detected" << std::endl; ret...
1,450
/* objective * C = A*B // A[m][k], B[k][n], C[m][n] * compile: nvcc --gpu-architecture=compute_60 --gpu-code=sm_60 -O3 matmul_double.cu -o matmul_double */ #include <iostream> #include <cstdlib> #include <math.h> # define BLK_SIZE 4 #define EC(ans) { chkerr((ans), __FILE__, __LINE__); } inline void chkerr(cudaEr...
1,451
#include <malloc.h> #include <string.h> #include <stdio.h> #include <vector> #include <fstream> #include <iostream> using namespace std; #include <cufft.h> #define BATCH 1 //размер данных для обработки #define CUDA_CHECK_RETURN(value) {\ cudaError_t _m_cudaStat = value;\ if (_m_cudaStat != cudaSuccess) {\ fprintf...
1,452
#include <stdio.h> #include <stdlib.h> #include <cuda.h> __global__ void kernelTest() { int i; i = 100; i = i - i + i; } extern "C" void testGpu() { printf("start test kernel...\n"); kernelTest<<<1, 1>>>(); printf("end of test lernel...\n"); }
1,453
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <string.h> #include <cuda.h> #include "math.h" #include "time.h" #include <iostream> #include <fstream> #include <iomanip> #define BLOCK_SIZE 32 __global__ void kernel_global(float* a, float* b, int n, float* c) { int bx = b...
1,454
#include <stdio.h> #include <stdlib.h> // Variables float* h_A; // host vectors float* h_C; float* d_A; // device vectors float* d_C; // Functions void RandomInit(float*, int); __global__ void FindMax(const float*, float*, int); // Host Code int main(){ // Settings // gid -> GPU device id (0, 1, ......
1,455
#include "includes.h" __global__ void add(int*a, int*b, int*c) { c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x]; }
1,456
/* Copyright 2017 the arraydiff authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, so...
1,457
#include <algorithm> #include <cstdlib> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <sstream> #include <stdio.h> #include <string> #include <unordered_map> #include <vector> using namespace std; map<string, double> GetTwissHeader(string filename) { vector<strin...
1,458
#include <time.h> #include <stdlib.h> #include <stdio.h> #define NUMTHREADS 32 #define N 129 #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 %...
1,459
/****************************************************************************** *cr *cr (C) Copyright 2010 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr *****************************************************************...
1,460
#include "includes.h" __global__ void findMaxIndMultipleDetector(float *input, int* maxInd, int size) { int maxIndex = 0; int count = 1; for (int i = 1; i < size; i++){ if (input[maxIndex] < input[i]){ maxIndex = i; count = 1; } else if (input[maxIndex] == input[i]){ count++; } } if(count>1) maxInd[0] = -1; else maxIn...
1,461
#include <stdio.h> #ifndef COMMON_CU #define COMMON_CU #define BLOCK_SIZE (4 * 1024) #endif
1,462
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <cstring> #include <time.h> // define kernel __global__ void mem_trans_ex(int *input) { int tid = threadIdx.x + blockDim.x * threadIdx.y + ((blockDim.x * blockDim.y * blockDim.z) * gridDim.y) * gridDim.z ...
1,463
#include <cuda_runtime.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <cmath> #define COUNT_UNIT8_T_HASH 16 #define MD5_CHUNKS_BYTE 512/8 #define MD5_TEXT_LEN 448/8 //#define DEBUG #define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c)))) __host__ __device__ void to_...
1,464
/* Task #8 - Gustavo Ciotto Pinton MO644 - Parallel Programming */ #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #define COMMENT "Histogram_GPU" #define RGB_COMPONENT_COLOR 255 #include <cuda.h> #define THREAD_PER_BLOCK 1024 /* Tesla k40 supports 1024 threads per block */ typede...
1,465
/// /// vecAddKernel01.cu /// /// This Kernel adds two Vectors A and B in C on GPU /// with using coalesced memory access. /// __global__ void AddVectors(const float* A, const float* B, float* C, int N) { int blockStartIndex = blockIdx.x * blockDim.x * N; int threadStartIndex = blockStartIndex + threadIdx.x; ...
1,466
#include "includes.h" #define TOLERANCE 0.00001 #define TRUE 1 #define FALSE 0 long usecs(); void initialize(double **A, int rows, int cols); int calc_serial(double **A, int rows, int cols, int iters, double tolerance); int calc_serial_v1(double **A, int rows, int cols, int iters, double tolerance); int calc_omp(doub...
1,467
#include <stdio.h> #include <time.h> // by lectures and "CUDA by Example" book #define ind(k, i, j, rows, cols) (k * (rows * cols) + i * cols + j) // device code: matrices sum calculation __global__ void sum_matrices_kernel(int* mat_stack, int* mat, int rows, int cols, int num) { // row and col that correspond ...
1,468
//pass //--blockDim=1024 --gridDim=1 --no-inline #include <cuda.h> #include <stdio.h> #define N 2 //1024 __global__ void definitions (int* A, unsigned int* B, unsigned long long int* C) { atomicMax(A,10); atomicMax(B,1); atomicMax(C,5); }
1,469
#include "includes.h" __global__ void GPUMult(int *A, int *B, int *C, int WIDTH) { int sol=0; int i;i = threadIdx.x; int j; j= threadIdx.y; if (i < WIDTH && j < WIDTH) { for (int k = 0; k < WIDTH; k++) { sol += A[j * WIDTH + k] * B[k * WIDTH + i]; } C[j * WIDTH + i] = sol; } }
1,470
#include "includes.h" #define SIZ 20 #define num_inp 4 using namespace std; typedef struct edge { int first, second; } edges; __global__ void initialize_vertices(int *vertices, int starting_vertex) { int v = blockDim.x * blockIdx.x + threadIdx.x; if (v == starting_vertex) vertices[v] = 0; else vertices[v] = -...
1,471
#include "includes.h" __global__ void sync_deconv_groups() { }
1,472
/* This code illustrates the use of the GPU to perform vector addition on arbirarily large vectors. Author: Naga Kandasamy Date modified: May 3, 2020 */ #include <stdlib.h> #include <stdio.h> #include <time.h> #include <string.h> #include <math.h> #include <float.h> /* Include kernel code during preproce...
1,473
// Lanzar un Kernel #include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #define N 8 __global__ void suma(int *vector_1, int *vector_2, int*vector_suma, int n) { // identificador de hilo int myID = threadIdx.x; // inicializamos el vector 2 vector_2[myID] = (n -1) - myID; // escritura d...
1,474
#include <cuda_runtime.h> __global__ void powf_global(float x, float y, float *r) { *r = __powf(x, y); } float cuda_pow(float x, float y) { float *gpu_result, result; cudaMalloc((void **)&gpu_result, sizeof(float)); powf_global<<<1, 1>>>(x, y, gpu_result); cudaMemcpy(&result, gpu_result, sizeof(i...
1,475
#include "includes.h" // Device code for ICP computation // Currently working only on performing rotation and translation using cuda #ifndef _ICP_KERNEL_H_ #define _ICP_KERNEL_H_ #define TILE_WIDTH 256 #endif // #ifndef _ICP_KERNEL_H_ __global__ void CalculateDistanceIndexEachPoint(double point...
1,476
/* Mmult application Written by: Riccardo Fontanini Start date: 3 May 2018 Note: This program is created to multiply 3 matrix R O T A S O P E R A T E N E T A R E P O S A T O R */ #include <stdio.h> #ifndef N #define N 1024 #endif #ifndef BLOCKDIM #define BLOCKDIM 32 #en...
1,477
#include "Atomic.cuh" __device__ bool tryAtomicStore(volatile int* ref, int oldValue, int newValue) { int replaced = atomicCAS((int*)ref, oldValue, newValue); return replaced == oldValue; } __device__ bool tryAtomicStore(volatile float* ref, float oldValue, float newValue) { return tryAtomicStore((volatile int*)r...
1,478
#include <stdio.h> __global__ void VectorAdd(int *a, int *b, int *c) { int tid = blockIdx.x * blockDim.x + threadIdx.x; c[tid] = a[tid] + b[tid]; } int main() { const int size = 512*65535; const int BufferSize = size*sizeof(int); int *InputA, *InputB, *Result; InputA = (int*)malloc(BufferSize); InputB = (int*...
1,479
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void add(int *a, int *b, int *alpha) { int i = blockIdx.x; b[i]=*alpha*a[i]+b[i]; } int main(void) { int MAX = 10; int a[MAX], b[MAX], alpha; int *d_a, *d_b, *d_c; int size = size...
1,480
// pour compiler : nvcc vecAdd.cu -o vecAdd #include <stdio.h> #include <stdlib.h> #include <math.h> // CUDA kernel. Each thread takes care of one element of c __global__ void vecAdd(float *a, float *b, float *c, int n){ // identifiant global du thread dans la grille 1D int tid = blockIdx.x * blockDim.x + threadId...
1,481
#include<stdlib.h> #include<stdio.h> #include<time.h> void init_array(double *a, const int N); void print_array(double *a,const int N); __global__ void vecAdd(double*a,double*b,double*c,int n) { //get thread id int id = blockIdx.x*blockDim.x + threadIdx.x; if(id<n) c[id]=a[id]+b[id]; } int main() { srand(t...
1,482
#include "includes.h" /*****************************************************************************/ // nvcc -O1 -o bpsw bpsw.cu -lrt -lm // Assertion to check for errors __global__ void kernel_trialDiv (long* n, int* r) { int bx = blockIdx.x; // ID thread int tx = threadIdx.x; int i=0; // Identify the row and...
1,483
/**************************************** * CUDA kernel for transposing matrices * ****************************************/ #include <stdio.h> #define CUDA_SAFE_CALL( call ) { \ cudaError_t err = call; \ if( cudaSuccess != e...
1,484
/* * Copyright (c) 2019 Opticks Team. All Rights Reserved. * * This file is part of Opticks * (see https://bitbucket.org/simoncblyth/opticks). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the ...
1,485
#include "HeatEquationKernels.cuh" __global__ void HeatEquation_kernel(float3* target, float3* source, unsigned int gridSize, float deltaTime) { unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < (gridSize * gridSize)) { unsigned int x = i / gridSize; unsigned int y = i % gr...
1,486
// // main.cpp // DS // // Created by Shubham Gupta on 31/03/17. // Copyright © 2017 Shubham Gupta. All rights reserved. // Modified by Utkarsh Aashu Mishra on 5/02/2014 // Copyright © 2018 Utkarsh Aashu Mishra. All rights reserved. #include <stdio.h> #include <iostream> #include <cmath> #include <string.h> #inc...
1,487
#include <cstdio> #include <stdio.h> int main(void) { int a[100000]; int b[100000]; int *ary1; int *ary2; int *ary3; for(int i=0;i<100000;i++) { a[i] = i; } cudaMalloc((void**)&ary1 , 100000*sizeof(int)); cudaMalloc((void**)&ary2 , 100000*sizeof(int)); cudaMalloc((void**)&ary3 , 100000*sizeof(int)); cu...
1,488
#include <stdio.h> #include "cuda.h" #include "cuda_runtime.h" #define get_idx() (threadIdx.x) __global__ void sum(float *x) { int idx = get_idx(); x[idx] += 1; } int main() { int N = 32; int nbytes = N * sizeof(float); float *dx = NULL, *hx = NULL; /* allocate GPU memory */ cudaMalloc((void **)&dx, nbytes)...
1,489
#include "includes.h" __global__ void gray(unsigned char *In, unsigned char *Out,int Row, int Col){ int row = blockIdx.y*blockDim.y+threadIdx.y; int col = blockIdx.x*blockDim.x+threadIdx.x; if((row < Col) && (col < Row)){ Out[row*Row+col] = In[(row*Row+col)*3+2]*0.299 + In[(row*Row+col)*3+1]*0.587+ In[(row*Row+col)*3]...
1,490
#include <stdio.h> static __global__ void generateFilter(float* filter, float lambda, float theta, float psi, float sigma, float gamma, int2 center, int2 size) { int xCoord = blockIdx.x * blockDim.x + threadId...
1,491
#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(){ float value = 3.14f; // cudaMemcpyToSymbol(devData, &value, sizeof(float)); float *dptr =...
1,492
#include "includes.h" __global__ void bcnn_op_cuda_relu_grad_kernel(int n, float *x, float *dx) { int i = (blockIdx.x + blockIdx.y * gridDim.x) * blockDim.x + threadIdx.x; if (i < n) { dx[i] *= ((float)(x[i] > 0)); } return; }
1,493
#include <stdio.h> #include <stdlib.h> #include <math.h> //CUDA kernel __global__ void vecAdd(float *a, float *b, float *c, int n) { int id = blockIdx.x * blockDim.x + threadIdx.x; // ensure we are within bounds if (id<n) c[id] = a[id] + b[id]; } int main( int argc, char* argv[]) { // vector size int n = 2000...
1,494
#include <stdio.h> __global__ void printValue( int *value) { printf("value %d\n",value[0]); printf("value %d\n",value[1]); } void hostFunction(){ int *value; cudaMallocManaged(&value, 2 * sizeof(int)); value[0]=1; value[1]=2; printValue<<< 1, 1 >>>(value); cudaDeviceSynchronize(); cudaFree(value); } int main() { h...
1,495
#include <stdio.h> #include <cuda_runtime.h> __global__ void kernel(void) { printf("GPU bockIdx %i threadIdx %i: Hello World!\n", blockIdx.x, threadIdx.x); } int main(int argc, char* argv[]) { kernel <<<6,2>>>(); cudaDeviceSynchronize(); return 0; }
1,496
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> int main(int argc, char **argv) { double *buf_d = NULL; fprintf(stderr, "Allocating...\n"); cudaMalloc((void **) &buf_d, sizeof(double) * 1024); fprintf(stderr, "Allocating DONE.\n"); return 0; }
1,497
//Matrix Multiplication #include <stdio.h> #include <stdlib.h> #define BLOCK_SIZE 2 #define GRID_SIZE 2 #define N GRID_SIZE * BLOCK_SIZE __global__ void MatrixMul(float *A, float *B, float *C, int n) { // Each thread computes a single element of C int row = blockIdx.y*blockDim.y + threadIdx.y; int col = blockIdx.x...
1,498
#include "CudaEuler.cuh" #include <stdio.h> __device__ int modulo(int a, int b){ int r = a%b; return r< 0 ? r + b : r; } __global__ void CudaCalculateDerivative(inttype N, fptype rate, fptype* derivative, fptype* mass, fptype* val, inttype* ia, inttype* ja, inttype* map, inttype offset) { int inde...
1,499
#include <stdio.h> #include <stdlib.h> #include <cuda.h> __global__ void Add(int *a, int *b, int* c) { *c = *a + *b; } int main() { // Host numbers int hostA; int hostB; int hostC; // Device numbers int* devA; int* devB; int* devC; // Allocate memory for device numbers ...
1,500
#include "includes.h" __global__ void blur( float * input, float * output, int height, int width) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if(x<height && y<width) { for(int k=0;k<3;k++) { float sum=0; int count=0; for(int i=x-BLUR_SIZE; i<= x+BLUR_SIZE; i++) { fo...