serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
501
#include <stdio.h> #include <math.h> #include <time.h> #include <unistd.h> #include <cuda_runtime_api.h> typedef struct point_t { double x; double y; } point_t; int n_data = 1000; __device__ int d_n_data = 1000; point_t data[] = { {76.80,141.84},{73.91,133.16},{65.59,135.84},{77.08,144.27}, {83.32,166.24...
502
/* * Copyright (c) 2018 Preferred Networks, Inc. All rights reserved. */ namespace chainer_trt { namespace plugin { __global__ void transpose_kernel(const float* d_src, float* d_dst, int* d_indexes, int in_size) { int idx = blockIdx.x * blockDim.x + threadIdx.x; ...
503
// This example demonstrates parallel floating point vector // addition with a simple __global__ function. #include <stdlib.h> #include <stdio.h> #include <iostream> #include <time.h> #include <unistd.h> #include <sys/time.h> #include <cuda_runtime.h> #define BLOCK_SIZE 512 // this kernel computes the vector sum c =...
504
#include<stdio.h> #define iteration_max 100 #define CEIL(a, b) (((a) + (b) - 1)/(b)) // Function using of the internet //////////////////////////////////////////////////////////////////////////////// // These are CUDA Helper functions // This will output the proper CUDA error strings in the event that a CUDA host cal...
505
__global__ void force_aux0(long k, double *magx_gpu, double *magy_gpu) { long i,cind; __shared__ double mx,my,mgx[512],mgy[512]; cind=threadIdx.x; mgx[cind]=magx_gpu[cind]; mgy[cind]=magy_gpu[cind]; __syncthreads(); mx=0.0; my=0.0; for (i=0;i<k;i++) { mx+...
506
// Kernel function to add the elements of two arrays __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]; } }
507
#include "includes.h" /** * This is my first program in learning parallel programming using CUDA. * Equivalent to a hello World program :-) * This program basically performs two tasks: * 1. It selects suitable CUDA enabled device(GPU) and prints the device properties * 2. It demonstrate basic parallel addition of two a...
508
#include <iostream> __global__ void add( int*a, int*b, int*c ) { int index = threadIdx.x + blockIdx.x * blockDim.x; c[index] = a[index] + b[index]; } #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define N (1024*1024*16) #define THREADS_PER_BLOCK 1024 int main( void ) { int *a, *b, *c...
509
#include "includes.h" __global__ void chainFunction ( const int dim, const int nwl, const int nst, const int ipr, const float *smpls, float *chnFnctn ) { int i = threadIdx.x + blockDim.x * blockIdx.x; int j = threadIdx.y + blockDim.y * blockIdx.y; int t = i + j * nwl; if ( i < nwl && j < nst ) { chnFnctn[t] = smpls[ipr...
510
#include <fstream> #include <iostream> #include <math.h> #include <cmath> #include <curand_kernel.h> #include <cuda.h> #include <string> #include <time.h> __device__ void rot( float *w, float *vec, const float dt) { float mw = sqrt(w[0]*w[0] + w[1]*w[1] + w[2]*w[2]); float omega[3]; float invmw = 1.0f/mw;...
511
// Second CUDA program // Ping-Che Chen #include <stdio.h> #include <stdlib.h> #include <time.h> #include <cuda_runtime.h> #define BLOCK_SIZE 16 __global__ static void matMultCUDA(const float* a, size_t lda, const float* b, size_t ldb, float* c, size_t ldc, int n) { __shared__ float matA[BLOCK_SIZE][BLOCK_SIZE]; ...
512
#include <stdio.h> #include <cuda_runtime.h> int main(int argc, char **argv) { printf("%s Starting...\n", argv[0]); int deviceCount = 0; cudaError_t error_id = cudaGetDeviceCount(&deviceCount); if (error_id != cudaSuccess){ printf("cudaGetDeviceCount returned %d\n -> %s\n", (i...
513
__global__ void test_while() { int a[5]; int x = 0; int i = 0; while (i++ < 5) { // i == 1..5 // x == 1..5 ++x; a[x] = 42; a[x - 1] = 42; } // i == 6, x == 5 a[i] = 42; a[x] = 42; a[x - 1] = 42; } __global__ void test_large_while() { const int size = 10000; int b[size]; int i = 0; int x = 0; w...
514
/* * JCuda - Java bindings for NVIDIA CUDA driver and runtime API * http://www.jcuda.org * * * This code is based on the NVIDIA 'reduction' CUDA sample, * Copyright 1993-2010 NVIDIA Corporation. */ extern "C" __global__ void reduce(float *g_idata, float *g_odata, unsigned int n) { extern __shared__ float sda...
515
#include <cuda.h> #include <stdio.h> int main (int argc, char **argv){ int ndev, maxtpb; cudaGetDeviceCount(&ndev); printf("Number of GPUs = %4d\n",ndev); for(int i=0;i<ndev;i++){ cudaDeviceProp deviceProps; cudaGetDeviceProperties(&deviceProps, i); maxtpb = deviceProps.maxThreadsPerBlock; ...
516
// Copyright (c) 2017 Madhavan Seshadri // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) extern "C" { __global__ void smvp(double *A_data, int *A_indices, int *A_pointers, double *B, double *C, int *m, int ...
517
#include <stdio.h> #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 + threadIdx.x;...
518
#include "includes.h" __global__ void mapKernel(float* out, int functionCode, float frange_start, float dx) { int id = blockIdx.x * blockDim.x + threadIdx.x; float x = frange_start + id * dx; float y; switch (functionCode) { case 0: y = cos(x); break; case 1: y = tan(x); break; default: y = sin(x); break; } out[2 * ...
519
#include <stdio.h> #include <cuda_runtime.h> __global__ void vectorAdd(float *A, float *B, float *C, int numElements) { int i = blockIdx.x * blockDim.x + threadIdx.x; if(i < numElements) { C[i] = A[i] + B[i]; } } int main() { int numElements = 1000; size_t size = numElements * sizeof(float); float *h_A,...
520
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <complex.h> #include <cufft.h> // Kernel used for assigning values to matrix. __global__ void assign(int N, cufftDoubleComplex* a, cufftDoubleComplex* a_copy){ if (blockIdx.x < N && blockIdx.y < N){ a_copy[blockIdx.x+blockIdx....
521
#include <iostream> #include <cstdio> using namespace std; #include <cuda_runtime.h> #define TIMES 24 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////HELP FUNCTIONS//////////////////////////////////////...
522
/** * 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 4 #define THREADS_PER_BLOCK 4 __global__ void mat_mul( int *A, int *B, int *C, int size) { int thrIdx = blockIdx.x * blockDim.x + threadIdx.x; ...
523
#include <cuda.h> #include <cmath> #include <cstdio> #include <iostream> #include <chrono> using namespace std; // check for errors using cuda runtime api // https://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api // Error: GPUassert: unknown error vecadd.c...
524
#include <stdio.h> #include <stdlib.h> #define DIM 1000 #define CUDA_CHECK( err ) (cuda_checker(err, __FILE__, __LINE__)) static void cuda_checker( cudaError_t err, const char *file, int line ) { if (err != cudaSuccess) { printf("%s in %s at line %d\n", cudaGetErrorString(err), file, line); exit(EXIT_FAILURE);...
525
#include "includes.h" __global__ void transposeDiagonalRow(float *out, float *in, const int nx, const int ny) { unsigned int blk_y = blockIdx.x; unsigned int blk_x = (blockIdx.x + blockIdx.y) % gridDim.x; unsigned int ix = blockDim.x * blk_x + threadIdx.x; unsigned int iy = blockDim.y * blk_y + threadIdx.y; if (ix < ...
526
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/inner_product.h> #include <thrust/for_each.h> #include <cstdlib> #include <vector> typedef double ScalarType; int main(void) { /* // generate 32M random numbers on the host thrust::host_vector<int> h_...
527
#include "includes.h" __global__ void cuda_multiply_f32(float *input_output, size_t size, float multipler) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < size) input_output[idx] = input_output[idx] * multipler; // 7-bit (1-bit sign) }
528
/* simple-warp-divergence.cu */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #include <cuda_runtime.h> #define CHECK_CUDA_CALL(call) \ { \ const cudaError_t error = call; \ \ if (error != cudaSuccess) { \ fprintf(stderr, "Error (%s:%d), code: ...
529
/* * * Programa de Introducci�n a los conceptos de CUDA * Suma dos vectores de enteros e indica qu� partes del c�digo deben modificarse * para implementar la versi�n paralela en el GPU * * Asume un modelo de memoria distribuida */ /* Parte 0: A�adir los archivos .h de CUDA*/ #include <cuda_runtime.h> #include ...
530
#include <stdio.h> #define T 8 // As Threads #define N 16 __global__ void vecMatrixTransposed(int *A, int *B) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y+ threadIdx.y; int width = gridDim.x * T; for( int j = 0; j<T; j+=N ) { B[x*width + (j+y)] = A[(y+j...
531
#include <stdio.h> #include <stdlib.h> #define INPUT_SIZE 8 #define MASK_SIZE 4 #define RES_SIZE (MASK_SIZE+INPUT_SIZE-1) #define THREAD_PER_BLOCK 2 #define N_BLOCKS (RES_SIZE+THREAD_PER_BLOCK-1)/THREAD_PER_BLOCK /* Debug runtime API function */ #define CHECK(call){\ const cudaError_t error=call;\ if( error!=...
532
#include <stdio.h> // // kernel code // __global__ void my_first_kernel() { printf("Hello from block (%d, %d), thread (%d, %d)\n", blockIdx.x, blockIdx.y, threadIdx.x, threadIdx.y); } // // host code // int main(int argc, char **argv) { // set number of blocks, and threads per block dim3 blocks_2d = dim3(...
533
//Editor: Michael Lukiman //Izhikevich spiking neuron network implementation in CUDA with added spatial winner-take-all dynamics //GPU Architecture and Programming - Fall 2018 #include <stdio.h> //Standard input-output #include <stdlib.h> //StandardLibraryfunctions #include <iostream> //For streaming input-output oper...
534
#include <stdio.h> #include <math.h> #include <time.h> #include <unistd.h> #include <cuda_runtime_api.h> #include <errno.h> #include <unistd.h> /****************************************************************************** * This program takes an initial estimate of m and c and finds the associated * rms error. It...
535
//xfail:TIMEOUT //--blockDim=32 --gridDim=64 --no-inline #include "cuda.h" #define N 32 __global__ void foo(int* p) { __shared__ unsigned char x[N]; for (unsigned int i=0; i<(N/4); i++) { ((unsigned int *)x)[i] = threadIdx.x; } }
536
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> cudaError_t backPropagation(double *out, double *x, double *y, double *W, unsigned int row, unsigned int column, double eta); __global__ void subtractKernel(double *out, double *y, unsigned int row) { int t...
537
#include <stdio.h> #include <iostream> __global__ void helloFromGPU() { printf("Hello world from GPU using C++\n"); // A line below doesn't work! // std::cout << "Hello world from GPU using C++" << std::endl; } int main(int argc, char const* argv[]) { std::cout << "Hello world from cpu using C++" << std::endl; ...
538
/* By: Carrick McClain Sources: http://csweb.cs.wfu.edu https://stackoverflow.com http://www.cplusplus.com https://devtalk.nvidia.com https://docs.nvidia.com/cuda/cuda-c-programming-guide */ #include <iostream> #include <stdio.h> #include <cuda.h> #include <cuda_runtime....
539
#include <iostream> // #include <tuple> // thrust includes #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/inner_product.h> #include <thrust/iterator/zip_iterator.h> #include <thrust/transform.h> #include <thrust/transform_reduce.h> #include <thrust/iterator/constant_iterator.h> #inc...
540
__device__ void color(float r, float g, float b, unsigned char* buffer){ if(r>255) buffer[0] = 255; else buffer[0] = (unsigned char)(r); if(r>255) buffer[1] = 255; else buffer[1] = (unsigned char)(g); if(r>255) buffer[2] = 255; else buffer[2] = (unsigned char)(b); } __device__ struct ma...
541
#include <cuda_runtime.h> __global__ void binarizeKernel(uchar4* pData, unsigned char threshold) { // get the position for the current thread unsigned int x = (blockIdx.x * blockDim.x) + threadIdx.x; unsigned int y = (blockIdx.y * blockDim.y) + threadIdx.y; // calculate the memory adress const...
542
#include <stdio.h> #include <time.h> #define TPB 256 #define ARRAY_SIZE 1000000 __global__ void saxpy_gpu(int n, float a, float* d_x, float* d_y) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) d_y[i] = a * d_x[i] + d_y[i]; } void saxpy_cpu(int n, float a, float* x, float* y) { for (int i = 0; i < n...
543
// test the size of shared memory for each block #include <iostream> #include <cstdio> using namespace std; #define N 2500 __global__ void fun() { __shared__ double x[N], y[N]; for (int i=0; i<400; ++i) for (int j=0; j<N; ++j) y[j] += x[j]; } int main() { fun<<<1,1>>>(); cudaDeviceSynchronize(); }
544
//***************************************************************************** //Projet HPC fusion et trie de tableaux sur GPU //Auteur: ROBIN Clement et SAULNIER Solene //Promo: MAIN5 //Date: decembre 2020 //Question 3 //***************************************************************************** #include <stdio.h>...
545
#include "stdio.h" #include<iostream> #include <cuda.h> #include <cuda_runtime.h> //Defining two constants __constant__ float constant_f; __constant__ float constant_g; #define N 5 //Kernel function for using constant memory __global__ void gpu_constant_memory(float *d_in, float *d_out) { //Getting thread index for...
546
#include <stdio.h> #include <sys/time.h> // #include <demo_util.h> // #include <cuda_util.h> #define CLOCK_RATE 1076000 // Titan double cpuSecond() { struct timeval tp; gettimeofday(&tp,NULL); return (double) tp.tv_sec + (double)tp.tv_usec*1e-6; } __device__ void sleep(float t) { clock_t t0 = cl...
547
// a cuda app. we will convert this to opencl, and run it :-) #include <iostream> #include <memory> #include <cassert> using namespace std; #include <cuda_runtime.h> __global__ void setValue(float *data, int idx, float value) { if(threadIdx.x == 0) { data[idx] = value; } } int main(int argc, char ...
548
// Hello Cuda World Program // /* * Author: Malhar Bhatt * Subject : High Performance Computing * */ #include <iostream> /** * Empty Function named Kernel() qualified with __global__ * */ __global__ void kernel (void) { } int main(void) { kernel<<<1,1>>>(); // Calling Empty Function printf("Hello Cuda World !!!\n...
549
#include "includes.h" __global__ void cudaSmult_kernel(unsigned int size, const float *x1, const float *x2, float *y) { const unsigned int index = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int stride = blockDim.x * gridDim.x; for (unsigned int i = index; i < size; i += stride) { y[i] = x1[i] * x2[i]; } }
550
// Homework_5 // Problem_4 // change the array size to 8000. Check if answer to problem 3 still works. // RUN as // nvcc prob4.cu // ./a.out #include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> //Kernel function to initialize array __global__ void initialize(int *arr, int size){ int sectors = blockIdx...
551
__global__ void kernel1(int m, int n, int k, double *d_A, double *d_B, double *d_C){ for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ d_C[i*n + j] = 0.0; } } //mkn for(int i = 0; i < m; i++){ for(int s = 0; s < k; s++){ for(int j = 0; j < n; j++){ ...
552
#include <stdlib.h> #include <stdio.h> #include <iostream> #include <time.h> using namespace std; __global__ void initArray( int *A) { int tid; tid = blockIdx.x * blockDim.x + threadIdx.x; A[tid] = tid; } __global__ void swapArray( int *A, int size, int num_t) { int tid = blockIdx.x * blockDim.x + threadId...
553
// // A simple function that squares all the elements of an array // through a call to a CUDA kernel // #include "cudasquare.cuh" // Square function kernel // It squares all the elements of an array // Arguments: // a: array that must be squared in the GPU // b: squared int array (output) // n: number of elements of ...
554
#include "includes.h" __global__ void kernel_setAllPointsToRemove(int number_of_points, bool *d_markers_out) { int ind=blockIdx.x*blockDim.x+threadIdx.x; if(ind<number_of_points) { d_markers_out[ind] = false; } }
555
// This example is taken from https://cuda-tutorial.readthedocs.io/en/latest/ #include <stdio.h> __global__ void cuda_hello(){ printf("Hello World from GPU!\n"); } int main() { printf("Hello World from CPU!\n"); cuda_hello<<<1,1>>>(); cudaDeviceSynchronize(); return 0; }
556
void cpu_jacobi(double ***u, double ***u_old, double ***f, int N, int delta, int iter_max, int *iter) { int temp_iter = *iter; int i, j, k; double delta_2 = delta*delta; double div_val = 1.0/6.0; double ***temp_pointer; #pragma omp parallel default(none) \ shared(iter_max, N, f, del...
557
#include <iostream> #include <cstdlib> #include <cuda.h> #include <cmath> #define M 2048 #define W 15 #define w 3 #define threshold 80 using namespace std; __global__ void smoothening_kernel(float* d_filter,float* d_raw_image,float* d_hx,float* d_hy,float* d_gx,float* d_gy,float* d_smooth_image,float* d_edged_imag...
558
#include "includes.h" __global__ void updateVelocity_k(float2 *v, float *vx, float *vy, int dx, int pdx, int dy, int lb, size_t pitch) { int gtidx = blockIdx.x * blockDim.x + threadIdx.x; int gtidy = blockIdx.y * (lb * blockDim.y) + threadIdx.y * lb; int p; float vxterm, vyterm; float2 nvterm; // gtidx is the domain ...
559
#include "includes.h" __global__ void kernel_forwardElimination( float * fullMatrix, float * B, unsigned int nComp ) { unsigned int t = threadIdx.x; unsigned int baseIndex = t*nComp*nComp; unsigned int i,j,k; for ( i = 0; i < nComp - 1; i++ ) for ( j = i + 1; j < nComp; j++ ) { double div = fullMatrix[baseIndex+ j*nCo...
560
#include <stdio.h> #include <sys/time.h> int main(int argc, char** argv) { printf("Star timer\n"); // Start the timer struct timeval tim; gettimeofday(&tim, NULL); double t1=tim.tv_sec+(tim.tv_usec/1000000.0); // init vars int malloc_size_bytes, num_mallocs; // not enough args throw error if(argc...
561
#include <iostream> #include <vector> #include <ctime> #include <cstdlib> #include <algorithm> #include <sstream> #include <fstream> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/sort.h> using namespace std; struct element { int key; float value; double nana; __...
562
#include "includes.h" __device__ void timeTest1(int *a){ int t_index = threadIdx.x + (blockIdx.x * blockDim.x); if (t_index < SIZE) { *a +=5; } } __global__ void timeTest() { int t_index = threadIdx.x + (blockIdx.x * blockDim.x); if (t_index < SIZE) { int a = 0; for(int i = 0; i < 10000000; i++){ timeTest1(&a); }...
563
// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #include <iostream> // CHECK: #include <hip/hip_runtime.h> #include <cuda.h> template<typename T> __global__ void axpy(T a, T *x, T *y) { y[threadIdx.x] = a * x[threadIdx.x]; } template<typename T> __global__ void axpy_empty() { } __global__ void empty(...
564
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #include<unistd.h> #define DEVICE_ID 0 /* constants for the number of threads and the integration domain */ /* number of threads in a block, 2^n */ #define NT 1024 /* number of blocks in a grid, 2^n */ #define NB 16 /* length of the...
565
// includes, system #include <stdio.h> #include <assert.h> #include <chrono> // Here you can set the device ID that was assigned to you #define MYDEVICE 0 // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char *msg); ////////////////////////////////////////////////////////////////...
566
#include "includes.h" __global__ void AddIntegers(int *arr1, int *arr2, int num_elements) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < num_elements) { arr1[id] += arr2[id]; } }
567
// Simple starting example for CUDA program // Kees Lemmens, last change May 2012 #include <stdio.h> #include <stdlib.h> #include <cuda.h> #define NRBLKS 4 // Nr of blocks in a kernel (gridDim) #define NRTPBK 4 // Nr of threads in a block (blockDim) void checkCudaError(char *error) { if (cudaGetLastError() != c...
568
#include "k_indices.cuh" namespace timemachine { // Takes a source and destination array. // The value of the src is used as the index and the value in the destination array. Allows combining // a series of indices to get a unique set of values. void __global__ k_unique_indices( const int N, // Number of values in...
569
#include <stdio.h> __global__ void array_reverse(int *array_a_dev, int *array_a_rev_dev, int len) { int tid = threadIdx.x; array_a_rev_dev[len - tid - 1] = array_a_dev[tid]; } __global__ void array_reverse_shared(int *array_a_dev, int *array_a_rev_dev, int len) { int tid = threadIdx.x; __shared__ int ...
570
#ifndef M_PI #define M_PI 3.14159265358979323846 /* pi */ #endif __global__ void mikkola_gpu(const double *manom, const double *ecc, double *eanom){ /* Vectorized C Analtyical Mikkola solver for the eccentric anomaly. See: S. Mikkola. 1987. Celestial Mechanics, 40, 329-334. Adapted from IDL ...
571
#include "3d-test.cuh" #include<iostream> #include<stdio.h> __host__ __device__ void scalingFunction(int array[],int x) { for(int i=0; i<8; i++) { array[i] = array[i] * 2; } } __host__ __device__ void distributeFunction(int array[],int x,int y){ //pencilComputation p2; for...
572
struct ProgramGPUColorRGB { __device__ ProgramGPUColorRGB() { } unsigned char Blue; unsigned char Green; unsigned char Red; unsigned char Alpha; }; // Insaniquarium_Deluxe_Bot.Program extern "C" __global__ void FindPixel( ProgramGPUColorRGB* rgbColors, int rgbColorsLen0, ProgramGPUColorRGB* colors, int colo...
573
#include<iostream> using namespace std; __global__ void add(int a,int b,int *c){ *c=a+b; } int main() { int c; int *dev_c; cudaMalloc(&dev_c,sizeof(int)); add<<<1,1>>>(2,7,dev_c); cudaMemcpy(&c,dev_c,sizeof(int),cudaMemcpyDeviceToHost); cout<<"2+7="<<c<<endl; cudaFree(dev_c); return ...
574
#include "includes.h" /* * Open source copyright declaration based on BSD open source template: * http://www.opensource.org/licenses/bsd-license.php * * This file is part of the OPS distribution. * * Copyright (c) 2013, Mike Giles and others. Please see the AUTHORS file in * the main source directory for a full list of...
575
/* * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. * * NOTICE TO USER: * * This source code is subject to NVIDIA ownership rights under U.S. and * international Copyright laws. Users and possessors of this source code * are hereby granted a nonexclusive, royalty-free license to use this code * ...
576
#include <stdio.h> #include <cuda_runtime.h> #define num_threads 256 #define N (1<<20) void fillArray(float* arr) { //Seed rand() srand(42); for (int i = 0; i < N/2; i++) { arr[i] = rand() % 10; } ///Negatives for (int i = N/2; i < N; i++) { arr[i] = -1*(rand() % 10); }...
577
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "config.cuh" using namespace std; /* * Mapping function to be run for each input. The input must be read from memory * and the the key/value output must be stored in memory at pairs. Multiple * pairs may be stored at the next po...
578
#include <stdio.h> __global__ void matVectMult(float* d_B, float* d_C, float* d_A, int numElements){ int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; float sum = 0.f; if(row < numElements && col < numElements) { for(int i=0; i<numElements; i++) sum += d_B[row+c...
579
#include <iostream> #include <chrono> constexpr size_t kSize = 1000000; class Stopwatch { public: using TimePoint = decltype(std::chrono::high_resolution_clock::now()); Stopwatch(): start(std::chrono::high_resolution_clock::now()) {} ~Stopwatch() { end = std::chrono::high_resolution_clock::now(); std::c...
580
#include <stdio.h> #include <stdlib.h> __global__ void global_reduction_kernel(float *data_out, float *data_in, int stride, int size) { int idx_x = blockIdx.x * blockDim.x + threadIdx.x; if (idx_x + stride < size) { data_out[idx_x] += data_in[idx_x + stride]; } } void global_reduction(float *d_ou...
581
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #define N 10000000 #define MAX_ERR 1e-6 __global__ void vector_add(float *out, float *a, float *b, int n) { int i = blockDim.x*blockIdx.x+threadIdx.x; if (i<n) out[i] = a[i] + b[i]; } int main(){ float *a, *b, *out; ...
582
// // vectorAdd.cu // vector_add_parallel // // Created by poohRui on 2018/10/23. // Copyright © 2018 poohRui. All rights reserved. // #include <stdio.h> #include <math.h> #include <cuda.h> // Predefine the size of block #define BLOCK_DIM 256 /** * This is a kernel function which mainly deal with the computatio...
583
#include "includes.h" cudaError_t cuda(); // clamp x to range [a, b] __global__ void kernel(){ }
584
/*! * @file CudaHelpers.cu * @author Zdenek Travnicek * @date 15.2.2012 * @date 16.2.2013 * @copyright Institute of Intermedia, CTU in Prague, 2012 - 2013 * Distributed under modified BSD Licence, details in file doc/LICENSE * */ #include <cuda.h> namespace yuri { namespace cuda { void* map_arr...
585
/*sums square matrix by reduction*/ __global__ void sum(double sum, double * data, double sz) { const int colIdx = threadIdx.x; const int rowIdx = threadIdx.y; int linearIdx = rowIdx*sz + colIdx; extern __shared__ int sdata[]; // each thread loads one element from global to shared mem sdata[linearId...
586
#include "softmax-cross-entropy-grad.hh" #include "graph.hh" #include "../runtime/node.hh" #include "../memory/alloc.hh" namespace ops { SoftmaxCrossEntropyGrad::SoftmaxCrossEntropyGrad(Op* y, Op* logits) : Op("softmax_cross_entropy_grad", y->shape_get(), {y, logits}) {} void SoftmaxCrossEntropyG...
587
#include <stdio.h> #include <stdlib.h> /** * In this section, we will discover concurrent operation in CUDA * 1) blocks in grid: concurrent tasks, no gurantee their order of execution (no synchronization) * 2) warp in blocks: concurrent threads, explicitly synchronizable (it will be discussed in next section) * ...
588
//16CO212 16CO249 //Computer Architecture Lab Assignment 0 //Question 1 #include <stdio.h> //Printing Properties of the device void printDevProp(cudaDeviceProp device_properties) { printf("\tMajor revision number: %d\n", device_properties.major); printf("\tMinor revision number: %d\n",...
589
#include "includes.h" __global__ void THCudaTensor_kernel_indexSelect( float *tensor, float *src, long* src_stride, float *index, long src_nDim, int dim, long idx_size, long tensor_size, long size_dim ) { int thread_idx = blockIdx.x * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; long flat_size = t...
590
#include "includes.h" __global__ void gpu_sobel_kernel_shared(u_char *Source, u_char *Resultat, unsigned width, unsigned height) { __shared__ u_char tuile[BLOCKDIM_X][BLOCKDIM_Y]; int x = threadIdx.x; int y = threadIdx.y; int i = blockIdx.y*(BLOCKDIM_Y-2) + y; int j = blockIdx.x*(BLOCKDIM_X-2) + x; int globalIndex = ...
591
#include "includes.h" __global__ void inverse_transform(float *in, float *out, int height, int width) { // block elements int my_x, k, t; my_x = blockIdx.x * blockDim.x + threadIdx.x; // iterate through each element, going from frequency to time domain for (k = 0; k < height; k++) { // difference, which will be used t...
592
/*This mixed-precision matrix-vector multiplication algorithm is based on cublasSgemv NVIDIA's CUBLAS 1.1. */ #define LOG_THREAD_COUNT (7) #define THREAD_COUNT (1 << LOG_THREAD_COUNT) #define CTAS (64) #define IDXA(row,col) (lda*(col)+(row)) #define IDXX(i) (startx + ((i) *...
593
__global__ void sgemm (float *A, float *B, float *C, int N) { // Thread identifiers const int r = blockIdx.x; // Row ID const int c = blockIdx.y; // Col ID // Compute a single element (loop a K) float acc = 0.0f; for (int k = 0; k < N; k++) { acc += A[k * N + r] * B[c * N + k]; } // Store the resu...
594
#include "includes.h" __global__ void rgbUtoGreyF_kernel(int width, int height, unsigned int* rgbU, float* grey) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; if ((x < width) && (y < height)) { int index = y * width + x; unsigned int rgb = rgbU[index]; float r = (float)...
595
// includes, system #include <stdio.h> #include <assert.h> #include <stdlib.h> /* srand, rand */ #include <time.h> /* time */ // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char* msg); // Part3: implement the kernel __global__ void max_parallel(double *cmax, dou...
596
#include <iostream> #include <iterator> #include <queue> #include <vector> #include <math.h> #include <assert.h> #define CONV_MATRIX_SIZE 10 #define MAX_POOL_SIZE 10 #define TRIBE_MIN_POPULATION 15 #define RESET "\033[0m" #define BOLDBLACK "\033[1m\033[40m" /* Bold Black */ #define BOLDRED "\033[1m\033...
597
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand.h> #include <cuda_runtime.h> #define PI 3.14159265358979323846 #define N 100000 #define BLOCK_SIZE 1024 __device__ void BoxMuller(float u1, float u2, float *n1, float *n2) { float r = sqrtf(-2*logf(u1)); float theta = 2*PI*(u2); *n1 = r*s...
598
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <cuda.h> __global__ void kernel_grey(uint8_t* start, uint8_t* end, int height, int width) { int i, j, k, l; float blur[3][3] = {{1,2,1}, {2,4,2}, {1,2,1}}; // fil...
599
#include <iostream> #include <stdio.h> #include <sys/time.h> using namespace std; double get_time() { struct timeval tim; gettimeofday(&tim, NULL); return (double) tim.tv_sec+(tim.tv_usec/1000000.0); } //KERNEL __global__ void Add(float *a, float *b, float *c, int N, int BSZ) { int i = blockIdx.x*BSZ + threa...
600
#include <stdio.h> #include <iostream> #define N 512 #define BLOCK_DIM 32 __global__ void matrixAdd(int *d_a, int *d_b, int *d_out){ // Mapping from 2D block grid to absolute 2D locations on matrix int idx_x = blockDim.x * blockIdx.x + threadIdx.x; int idx_y = blockDim.y * blockIdx.y + threadIdx.y; ...