serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
17,901
#include "includes.h" __device__ float gpu_applyFilter(float *image, int stride, float *matrix, int filter_dim) { //////////////// // TO-DO #5.2 //////////////////////////////////////////////// // Implement the GPU version of cpu_applyFilter() // // // ...
17,902
/** * Copyright 1993-2014 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...
17,903
#include <iostream> template <unsigned int blockSize> __device__ void warpReduce(volatile int* sdata, int tid){ if (blockSize >= 64) sdata[tid] += sdata[tid+32]; if (blockSize >= 32) sdata[tid] += sdata[tid+16]; if (blockSize >= 16) sdata[tid] += sdata[tid+8]; if (blockSize >= 8) sdata[tid] += sdata[ti...
17,904
#include "includes.h" __global__ void MatrixMul_tileKernel(float* Md, float* Nd, float* Pd, int Width){ int Row = blockIdx.y*TILE_WIDTH + threadIdx.y; int Col = blockIdx.x*TILE_WIDTH + threadIdx.x; int tx = threadIdx.x, ty = threadIdx.y; __shared__ float a[TILE_WIDTH][TILE_WIDTH], b[TILE_WIDTH][TILE_WIDTH]; float Pval...
17,905
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cstdint> #include <vector> #include <map> #include <iostream> #include <fstream> #include <sstream> #include <ctime> using namespace std; __constant__ int lookup_table[256]; __global__ void generate_candidate(uint32_t *itemSets, uint32_t *tr...
17,906
/* 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,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float ...
17,907
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> // RG*RG*MAXN must fit within mytype #define MAXN 100000 #define RG 10 #define USECPSEC 1000000ULL #define nTPB 256 #define DSIZE 8192 //cuda error checking macros #ifdef DEBUG #define CUDA_CALL(F) if( (F) != cudaSuccess ) \ {printf("...
17,908
#include "includes.h" __global__ void accumulateColsKernel(float *input, float *output, int channels, int h, int w) { // global column index (of all `channels * w` columns in this image) int colIdx = BLOCK_SIZE * BLOCK_SIZE * blockIdx.x + threadIdx.x; if (colIdx < channels * w) { // jump to current channel input += (...
17,909
#include <stdio.h> int main() { int runtime; int driver; cudaError_t runtime_err = cudaRuntimeGetVersion(&runtime); cudaError_t driver_err = cudaRuntimeGetVersion(&driver); printf("Runtime Version: %d. %s\n", runtime, cudaGetErrorString(runtime_err)); printf("Driver Version: %d. %s\n", driver, cudaGetErrorStri...
17,910
//errorcheck.cu - The program is designed to produce output 'data = 7' //however, errors have been intentionally placed in the program //as an error checking exercise. #include <stdio.h> #include <stdlib.h> __global__ void setData(int *ptr) { *ptr = 7; } void checkError(const char *info="") { cudaError_t erro...
17,911
#include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #define NUM_ROWS 10000 #define NUM_COLS 1000 int a[NUM_ROWS][NUM_COLS]; int b[NUM_ROWS][NUM_COLS]; int c[NUM_ROWS][NUM_COLS]; __global__ void add(int *a, int *b, int *c) { int tx = threadIdx.x; int ty = blockDim.x * threadIdx.y; int bx = bl...
17,912
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> using namespace std; #define N 8 void cpuMatMul(float A[N][N], float B[N][N], float out[N][N]); __global__ void gpuMatMul(float *A, float *B, float *out, int W); int main(){ float A[N][N]; float B[N][N]; float C[N][N...
17,913
#include <stdio.h> #include <stdlib.h> #include <time.h> #define ITER 340000 #define SIZE 500 #define BLOCK 1 #define THREAD 1 void stopwatch(int); __global__ void manymanyLocal(); __global__ void manymanyGlobal(int*,int* ); __global__ void manymanyShared(); int main() { printf("SIZE : %d\nBLOCK : %d\nTHREAD : %...
17,914
#include "includes.h" __global__ void poly_div6(float* poli, const int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < N) { float x = poli[idx]; float y = 1.0/x; poli[idx] = 5 + x * ( 7 - x * (9 + x * (5 + x * (5 + x))))+y; } }
17,915
#include "includes.h" __global__ void callOperationSharedDynamic(int *a, int *b, int *c, int n) { int tid = blockDim.x * blockIdx.x + threadIdx.x; if (tid >= n) { return; } extern __shared__ int data[]; int *s_a = data; int *s_b = &s_a[size]; int *s_c = &s_b[size]; s_a[tid] = a[tid]; s_b[tid] = b[tid]; if (s_a[tid...
17,916
#include "includes.h" __global__ void calc_psf_hat(float* d_psf, float *d_psf_hat, int psf_rows, int psf_cols) { int row = threadIdx.y + blockIdx.y * blockDim.y; int col = threadIdx.x + blockIdx.x * blockDim.x; if(row < psf_rows && col < psf_cols) { int index = (psf_rows - row - 1) * psf_cols + psf_cols - col - 1; d_ps...
17,917
#include "includes.h" #ifdef __INTELLISENSE__ void __syncthreads(); #endif // image dimensions WIDTH & HEIGHT #define WIDTH 256 #define HEIGHT 256 // Block width WIDTH & HEIGHT #define BLOCK_W 16 #define BLOCK_H 16 // buffer to read image into float image[HEIGHT][WIDTH]; // buffer for resulting image float final...
17,918
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #define __u32 unsigned int #define __u8 unsigned char cudaError_t addWithCuda(__u32 SHA1Sum[], __u8 SHA1Data[], int *retVal); #define FETCH_32(p) \ (((__u32)*((const __u8 *)(p) + 3)) | \ (((__u32)*((const __u8 *)(p) + 2)...
17,919
void CudaFnInit() { }
17,920
#include "includes.h" __global__ void ppcg_init( const int x_inner, const int y_inner, const int halo_depth, const double theta, 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 = gid % x_inner; cons...
17,921
#include "MathLibrary.cuh" using namespace std; //Point Point createPoint(double x, double y, double z) { Point point; point.x = x; point.y = y; point.z = z; return point; } void printPoint(Point point); //Vector Vector createVector(Point origin, double deltaX, double deltaY, double deltaZ) { Point end; end ...
17,922
#include <iostream> using namespace std; using T = double; constexpr T range_min = 2.0; constexpr T range_max = 4.0; constexpr T range = range_max - range_min; constexpr auto all_threads = 4096; constexpr auto block_size = 16; constexpr auto thread_size = all_threads / block_size; constexpr auto warmup = 300; const...
17,923
/*************************************************************************** ************************************************************************** Spherical Harmonic Transform Kit 2.7 Copyright 1997-2003 Sean Moore, Dennis Healy, Dan Rockmore, Peter Kostelec Copyright 2004...
17,924
#include "snippet.cuh" /** * @brief Compute the squared Euclidean distance between this snippet and * another. * @param other Another Snippet to compare. * @return The squared Euclidean distance between `this` and `other`. * * Snippets in different spaces (i.e., channel or frame counts don't match) * are define...
17,925
#include <stdio.h> int main() { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("Device Number: %d\n", i); printf(" Device name: %s\n", prop.name); printf(" Version %d.%d\n", prop.major, prop....
17,926
#include <iostream> #include <math.h> #include <stdio.h> #include <algorithm> #include <stdlib.h> #include <time.h> using namespace std; __device__ int xgcd(int a, int b, int *x, int *y) { int prevx = 1, x1 = 0, prevy = 0, y1 = 1; while (b) { int q = a/b; prevx = x1; x1 = prevx - q*x1; prevy...
17,927
// Jin Pyo Jeon // Lab 02 #include <cuda.h> #include <stdlib.h> #include <time.h> #include <stdio.h> #include <math.h> #define T 1024 // Shared needs to be known at compile time?? #define B 128 #define N (1024 * 1024) #define cudaCheckError() { \ cudaError_t e = cudaGetLastError(); \ if (e != cudaSuccess) { \ pr...
17,928
#include <iostream> #include <chrono> #include <cstdlib> using namespace std; using namespace std::chrono; __global__ void reduce(float *g_idata, float *g_odata){ extern __shared__ float sdata[]; //each thread loads one element from global to shared mem unsigned int tid = threadIdx.x; unsigned int i =...
17,929
extern "C" { __global__ void kernel_vadd(const float *a, const float *b, float *c) { int i = blockIdx.x *blockDim.x + threadIdx.x; c[i] = a[i] + b[i]; } }
17,930
/* Date: 01-03-2017 Author: Omer Anjum Description: Copying Outer halos from host to GPU Comments: Date: March 14, 2017 Omer Anjum Very first version of code written. */ #include <stdio.h> /****************************************************************************************************************/ __...
17,931
// System includes #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <assert.h> // CUDA runtime #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> //#include <thrust/host_vector.h> //#include <thrust/device_vector.h> //#include <thrust/copy.h> //#incl...
17,932
/* * Please write your name and net ID below * * Last name: Will * First name: Peter * Net ID: pcw276 * */ /* * This file contains the code for doing the heat distribution problem. * You do not need to modify anything except starting gpu_heat_dist() at the bottom * of this file. * In gpu_heat_dist() y...
17,933
#include <stdio.h> #include <errno.h> #include <math.h> // Kernel function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { int bx = blockIdx.x; int by = blockIdx.y; // Thread index int tx = threadIdx.x; int ty = threadIdx.y; printf("%d %d %d %d\n", bx, by, tx...
17,934
#include "includes.h" __global__ void kernel(const unsigned char * src, unsigned char * dst, int level, const size_t width, const size_t height) { const size_t xIndex = blockIdx.x * blockDim.x + threadIdx.x; const size_t yIndex = blockIdx.y * blockDim.y + threadIdx.y; if (xIndex < width && yIndex < height) { size_t o ...
17,935
#include <cuda.h> #include <iostream> #include <random> #include <vector> using namespace std; __global__ void histoKernel(int* data, int* count, int size) { int tid = blockIdx.x*blockDim.x + threadIdx.x; if(tid < size) atomicAdd(&count[data[tid]/4], 1); } __global__ void histoKernelPrivatized(int* d...
17,936
#include <iostream> #include <cuda.h> using namespace std; __global__ void AddIntsCuda(int *a, int *b){ for(int i = 0; i<10000005; i++) a[0] +=b[0]*b[0]; } int main(){ int h_a=2, h_b=3; int *d_a, *d_b; //Device pointer // Allocate memory to device if(cudaMalloc((void**)&d_a, sizeof(int))!=cudaSuccess){ cou...
17,937
#include "includes.h" __global__ void cu_sum(const float* src, float* sum, float *global_mem, const int n){ unsigned int tid = blockIdx.x * blockDim.x + threadIdx.x; // load input into __shared__ memory float x = 0; if(tid < n){ x = src[tid]; } global_mem[threadIdx.x] = x; __syncthreads(); // contiguous range pattern f...
17,938
/* This program is written to find the nearest neighbour of each point in 3 deminsional space by implementing the brute force algorithm. The brute force approach can easily be converted into a embarassingly parallel algorithm for the GPU where there is no interaction between the threads. Benchmarking is done to compare...
17,939
// In this assignment you will write a kernel for vector addition // you will also go through generalized processing from of a // GPU accelerated application. // These are: // 1) initialize the host and data (allocate memory, load data, ...) // 2) initialize the device (allocate memory, set its prope...
17,940
#include "kernel_shared.cuh" #include "kernel_render.cuh" #include "cuda_globals.cuh" #include "globals.cuh" #include "const.cuh" static uchar4* d_displayBufferCuda = NULL; __device__ uchar4 COLORS[] = { {0, 0, 0, 255}, // CELL_EMPTY {0, 0, 255, 255}, // CELL_ELECTRON_HEAD {255, 0, 0, 255}, ...
17,941
#include "includes.h" __global__ void cudaSNormalizeROIs_kernel( unsigned int inputSizeX, unsigned int inputSizeY, unsigned int nbProposals, unsigned int batchSize, unsigned int scoreIdx, unsigned int nbCls, unsigned int maxParts, unsigned int maxTemplates, bool keepMax, bool generateParts, bool generateTemplates, cons...
17,942
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #define N 4 #define NUM_BLOCKS N * N / NUM_THREADS #define NUM_THREADS 4 #define THRESHOLD 0.001 void printMatrix(char *id, double matrix[N * N]) { char *s = (char *) malloc(10000 * sizeof(char)); sprintf(s, "%s\n", id)...
17,943
#include "includes.h" /******************************************************* * Copyright (c) 2015-2019, ArrayFire * All rights reserved. * * This file is distributed under 3-clause BSD license. * The complete license agreement can be obtained at: * http://arrayfire.com/licenses/BSD-3-Clause **************************...
17,944
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <cuda.h> #define MAXPOINTS 1000000 #define MAXSTEPS 1000000 #define MINPOINTS 20 #define PI 3.14159265 void check_param(void); void init_line(void); void update (void); void printfinal (void); __device__ void do_math(float*, float*, f...
17,945
#include<stdio.h> __global__ void reverseArrayBlock(int *inArray, int *outArray) { outArray[blockDim.x-1-threadIdx.x] = inArray[threadIdx.x]; } int main() { int *h_a; int *d_a; int *d_b; int dimA=256; int nblocks = 1; int tpb = dimA; size_t memSize; memSize = nblocks*tpb*sizeof(int); h_a = (int*...
17,946
#include <iostream> #include <math.h> #include <cuda.h> using namespace std; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++! // Divergence of a Vector with variable coefficient ! //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++! void DivC...
17,947
#include <iostream> #include <string> #include <fstream> #include <chrono> #include <math.h> #include <time.h> #include <sys/types.h> #include <unistd.h> using namespace std; const int FILTER_WIDTH = 9; const int BLOCK_SIZE = 256; // Display the first and last 10 items void displayResult(const int original[], const ...
17,948
#include <cstdlib> #include <iostream> #define NUM_BLOCKS 16 #define NUM_THREADS_PER_BLOCK 16 #define N 16 using namespace std; cudaEvent_t start, stop; void startKernelTime (void) { cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); } void stopKernelTime (void) { cudaEventRecord(stop); ...
17,949
#include "includes.h" __global__ void pw_scatter_cu_z( double *c, const double *pwcc, const double scale, const int ngpts, const int nmaps, const int *ghatmap) { const int igpt = (gridDim.x * blockIdx.y + blockIdx.x) * blockDim.x + threadIdx.x; if (igpt < ngpts) { c[2 * ghatmap[igpt] ] = scale * p...
17,950
void init_temp(float *M, int N_x, int N_y, int N_z){ int i, j, k; for (i=0; i<N_x; i++){ for (j=0; j<N_y; j++){ for (k=0; k<N_z; k++){ int i3d = k*(N_x*N_y) + j*(N_x) + i; if (i == 0 || j == 0 || k == 0){ M[i3d] = 10.0; ...
17,951
// This example demonstrates how to check for CUDA errors, // which indicate programming bugs, or otherwise broken // program behavior. #include <stdlib.h> #include <stdio.h> // our old friend, the "fill-with-7" kernel __global__ void kernel(int *array) { int index = blockIdx.x * blockDim.x + threadIdx.x; array[...
17,952
/* * Copyright (C) 2010, Florian Kummer, Technische Universitaet Darmstadt, Fachgebiet fuer Stroemungsmechanik * * Use, modification and distribution is subject to 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) * * Authors: ...
17,953
#include <cuda.h> #include <stdio.h> #include <time.h> #include <stdlib.h> // kernel __global__ void convolution_2D_Kernel(float* d_m, float* d_mask, float* d_n, size_t a, size_t b, size_t maskWidth) { // indexing variables int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + th...
17,954
#include <cmath> #include <float.h> #include <sstream> #include <iomanip> #include <dirent.h> #include <cstring> #include <stdio.h> #include "utility.cuh" using namespace std; void dumpDiaCSVpointer(vector<double> data1, vector<double *> data2, size_t s1, std::string varName) { std::string path = CSVFILEPATH; ...
17,955
#include "includes.h" /*This file is part of quantumsim. (https://github.com/brianzi/quantumsim)*/ /*(c) 2016 Brian Tarasinski*/ /*Distributed under the GNU GPLv3. See LICENSE.txt or https://www.gnu.org/licenses/gpl.txt*/ //kernel to transform to pauli basis (up, x, y, down) //to be run on a complete complex density ...
17,956
#include <iostream> //#include "error_checks_1.h" int main() { int dev = 0; cudaDeviceProp devProp; cudaGetDeviceProperties(&devProp, dev); std::cout << "using GPU device " << dev << ": " << devProp.name << std::endl; std::cout << "SM nums:" << devProp.multiProcessorCount << std::endl; std::cou...
17,957
// This example demonstrates how to launch two dimensional grids of CUDA threads. #include <stdlib.h> #include <stdio.h> __global__ void kernel(int *array) { // compute the two dimensional index of this particular // thread in the grid // do the usual computation separately in each dimension: int index_x = ...
17,958
#include <algorithm> #include <cfloat> #include <chrono> #include <random> #include <vector> #include <string> #include <cstring> #include <cctype> #include <cstdlib> #include <cstdio> #include <iostream> #include <fstream> #include <bitset> #include <random> #include "csv.hpp" using namespace std; // A small data s...
17,959
// vector sum with pinned memory (page-locked) #include "stdio.h" #define N 100 // 10 // 32 // 100 #define NumThPerBlock 64 // 32 //256 #define NumBlocks 2 // 1 static void HandleError( cudaError_t err, const char *file, int line) { if (err != cudaSuccess) { printf("%s in %s at line %d\n", cudaGetErrorString( e...
17,960
#include<stdio.h> #define CHECK_FOR_CORRECTNESS 1 #define MIN(a,b) (( (a) < (b) )?(a):(b)) /* Kernel Function1 - Initialize the array */ __global__ void initializeArray(int* A, int* B, int N) { int i = threadIdx.x; if(i<N) B[i] = A[i]; printf("Setting B[%d] = %d , from A[%d] = %d\n", i, B[i], i, A[i]); } /* Kerne...
17,961
// everything is done in the .cu file int ass;
17,962
/*-- --*/ #include "../include/Generic_function.cuh" __device__ void general_copy(float *af, float *be, int dims){ for(int i = 0; i < dims; i ++){ af[i] = be[i]; } } __device__ float input_saturation(float in, float *constraint, int k){ float ret = in; if( in < constraint[k * DIM_U]){ ...
17,963
#include "includes.h" __global__ void bf_2flags(int *Na, int *src, int *F1, int *F2, int *exists, int *Sa, int *Ea, int threadsPerBlock ) { int id = blockIdx.x * threadsPerBlock + threadIdx.x; if (exists[id]==1) { Na[id] = 65000; //MAX INT Value F1[id] = 0; F2[id] = 0; if (id == *src) { //Starting node conditions Na...
17,964
#include "op.hh" #include <algorithm> #include <iostream> #include <stdexcept> #include "graph.hh" namespace ops { namespace { std::string unique_name(std::string str) { auto id = Graph::instance().ops_by_name().size(); return str + ":" + std::to_string(id); }...
17,965
#include <stdio.h> #include <stdlib.h> #define N (2048*2048) // 2048*2048=4194304 #define THREADS_PER_BLOCK 512 __global__ void add(int *d_a, int *d_b, int *d_c){ int index = (blockIdx.x * blockDim.x) + threadIdx.x; d_c[index] = d_a[index] + d_b[index]; } void random_ints(int* x, int size){ for (int i=0; i<size;...
17,966
#include "includes.h" __global__ void addTwoArraysSharedDynamic(int *v1, int *v2, int *r, int n) { int tid = blockDim.x * blockIdx.x + threadIdx.x; if (tid >= n) { return; } extern __shared__ int arrays[]; int *s_v1 = arrays; int *s_v2 = &s_v1[n]; int *s_r = &s_v2[n]; s_v1[tid] = v1[tid]; s_v2[tid] = v2[tid]; s_r[...
17,967
#pragma once #include<iostream> #include<random> void initialize_projection_plane(float* m, int numbers, float sigma=1, float mu=0){ std::default_random_engine generator; std::uniform_real_distribution<float> distribution(-1, 1.0); for (int i = 0; i < numbers; ++i) { m[i] = sigma * distributi...
17,968
#include "includes.h" __global__ void addForces_k(float2 *v, int dx, int dy, int spx, int spy, float fx, float fy, int r, size_t pitch) { int tx = threadIdx.x; int ty = threadIdx.y; float2 *fj = (float2*)((char*)v + (ty + spy) * pitch) + tx + spx; float2 vterm = *fj; tx -= r; ty -= r; float s = 1.f / (1.f + tx*tx*tx*...
17,969
#include <iostream> using namespace std; __global__ void add(int *a, int *b, int *c, int n) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < n) { c[id] = b[id] + a[id]; } } int main() { cout << "Enter the no of elements" << endl; int n; cin >> n; int a[n], b[n],...
17,970
// Assignment For Module 04: // // // Author: Justin Renga // NOTE: This implementation was inspired from the sample code from // https://devblogs.nvidia.com/how-optimize-data-transfers-cuda-cc/ // and, as such, there may be similarities between them. #include <stdio.h> #include <stdlib.h> #define BLOCKSIZE 8 #defin...
17,971
#include <iostream> using namespace std; class a{ public: int x; a(){ } a(int i){ x = i; } void check(){ disp(); } virtual void disp() = 0; }; class b : public a{ public: b(){ } b(int i) : a(i){ } void get(){ check(); } void disp(){ cout<<x; } }; int main(int argc, char const *argv[...
17,972
/* This program launches a kernel on 256 GPU threads Author: Martin Wass */ #include <stdio.h> // printf // __global__ qualifier states the kernel is launched by host and ran on device __global__ void greeting() { int threadnum = blockIdx.x*blockDim.x + threadIdx.x; printf("Hey world, from thread %d\n", threadnum...
17,973
#include <stdio.h> #include <cuda_runtime_api.h> #include "device_launch_parameters.h" #include <math.h> #include <unistd.h> #include <errno.h> #include <time.h> typedef struct point_t{ double xIntercept; double yIntercept; }point_t; struct timespec start, end; long long int time_taken; int n_data = 1000; __device__...
17,974
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> #include <math.h> #include <cuda.h> #include <curand.h> #define CUDA_CALL(x) do { if((x)!=cudaSuccess){ \ printf("Error at %s:%d\n",__FILE__,__LINE__); \ return EXIT_FAILURE;}} while(0) #define CURAND_CALL(x) d...
17,975
#include <stdio.h> extern "C" // CUDA allocating function, with naive error handling double* cuda_allocate(const size_t size) { double *dev_matrix; if (cudaMalloc((void**)&dev_matrix, size) != cudaSuccess) { printf("Error allocating\n"); return 0; } else { return dev_matrix; ...
17,976
/* Write a CUDA program that includes a host function to compute the square of a N dimensional square matrix, N being 16 */ // Author: Naoki Atkins #include <stdio.h> #include <cuda.h> #include <time.h> #include <stdlib.h> #include <limits.h> #define N 16 __host__ int generator(int rank){ int rand_num; sr...
17,977
#include <stdio.h> #include <stdlib.h> #include <cufft.h> #define BSZ 32 __global__ void real2complex(float *f, cufftComplex *fc, int N){ int i = threadIdx.x + blockIdx.x*blockDim.x; int j = threadIdx.y + blockIdx.y*blockDim.y; int index = j*N+i; if (i<N && j<N){ fc[index].x = f[index]; fc[index]....
17,978
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <cuda.h> #define MAT_SIZE 10000 #define GIGA 1000000000. #define NSEC 1000000000. #define THREADS 32 __host__ cudaError_t matmatCuda(int, int, int, int, int, int, double *, double *, double *); __glo...
17,979
/* ********************************************** * CS314 Principles of Programming Languages * * Spring 2020 * ********************************************** */ #include <stdio.h> #include <stdlib.h> __global__ void collateSegments_gpu(int * src, int * scanResult, int * output, in...
17,980
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <math.h> #include <iostream> #if !defined(ARRAY_SIZE) #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0])) #endif /************************************************ Examples here are based on the quick guide https://github.com/th...
17,981
#include "use_matrix.cuh" int use_matrix() { int m = 4, n = 4; matrix A(m, n); std::cout << "Matrix A has " << rows(A) << " rows" <<"\n"; std::cout << "Matrix A has " << columns(A) << " columns" <<"\n\n"; std::cout << "The newly created matrix, A looks like: \n\n"; std::cout << A; ...
17,982
/* * Copyright 1993-2010 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 related...
17,983
#define _NTHREAD 512 #define _NBLOCK 65535 #include<cuda.h> __global__ void _AFFINE_KERNEL(int* ,int ,int ,int ,int ,int ,int ); #include<stdio.h> #include<stdlib.h> int main() { int a[50],i; for(i=0;i<50;i++) { a[i]=2*i; } int _SZ_a_1 = 50; int *_DEV_a; cudaMalloc((void**) &_DEV_a, sizeof(...
17,984
#include "OperationHandler.cuh" #include <stdio.h> __global__ void matrixMult(const float *a, const float *b, int n, float *c) { int bX = blockIdx.x; int bY = blockIdx.y; int tX = threadIdx.x; int tY = threadIdx.y; float sum = 0.0f; int indexOfA = n * BLOCK_SIZE * bY + n * tY; int indexOfB = BLOCK_SIZE * b...
17,985
#include <iostream> #include <type_traits> #include <typeinfo> #include <vector> template <class... T> struct list {}; template<class T> struct type_ { using type = T; }; namespace detail { template<class, class> struct dup_append_list; template<template<class...> class List, class... Ts, class... Us> struct ...
17,986
namespace { __global__ void kernel(long long int sleep_cycles) { auto start = clock64(); while (true) { auto now = clock64(); if (now - start > sleep_cycles) { break; } } return; } } void spin_device(cudaStream_t st, int giga_cycles) { kernel<<<1, 1, 0, st>>>((long long int)(1) * 1000 * 100...
17,987
#include "transpose.cuh" __global__ void transposeDiagonal(float *odata, float *idata, int width, int height, int nreps) { __shared__ float tile[TILE_DIM][TILE_DIM+1]; int blockIdx_x, blockIdx_y; // diagonal reordering if (width == height) { blockIdx_y = blockIdx.x; blockIdx_x = (blockIdx.x+blockIdx.y)%grid...
17,988
#include <algorithm> #include <cassert> #include <fstream> #include <iostream> #include <numeric> #include <vector> using std::accumulate; using std::cout; using std::generate; using std::ios; using std::ofstream; using std::vector; // Number of bins for our plots constexpr int BINS = 7; constexpr int DIV = ((26 + BI...
17,989
#include "includes.h" #define BLOCK_SIZE 16 __device__ float* GetSubMatrix(float * a, int tam, int row, int col) { float* aSub; aSub = &a[tam * BLOCK_SIZE * row + BLOCK_SIZE * col]; return aSub; } __global__ void MultiplyGPUMult(float * a, float *b, float *c,int t) { int blockRow = blockIdx.y; int blockCol = blockI...
17,990
#include <cuda.h> #include <stdio.h> #include <math.h> #define NUM_BANKS 8 #define LOG_NUM_BANKS 3 #define CONFLICT_FREE_OFFSET(n) \ ((n) >> NUM_BANKS + (n) >> (2 * LOG_NUM_BANKS)) // Print device properties void printDevProp(cudaDeviceProp devProp) { printf("Major revision number: %d\n", devProp.major);...
17,991
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 10000 #define BLOCK_SIZE 32 __global__ void reduce0(int *g_idata, int *g_odata) { __shared__ int sdata[10000]; // each thread loads one element from global to shared mem unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x*block...
17,992
/* * * Jason Yik * jyik@usc.edu * EE451 Final Project * * CUDA implementation of DCSC matrix multiplication. * * Run on USC HPC: * srun -n1 --gres=gpu:1 ./parallel <n> <nnz> * * Run with executable in a graphs folder containing n_nnz_x graphs * */ #include <stdio.h> #include <stdlib.h> #include <time....
17,993
#include "includes.h" __global__ void add(int a, int b, int *c) { *c = a+b; }
17,994
#include "stdio.h" #include <stdlib.h> __global__ void MatAdd(int* A, int* B, int* C, int nx, int ny) { int ix = threadIdx.x + blockIdx.x * blockDim.x; int iy = threadIdx.y + blockIdx.y * blockDim.y; int idx = iy * nx + ix; C[idx] = A[idx] + B[idx]; } void GenerateMatrix(int* m, int size) { for (...
17,995
#include <cstdio> int main(void) { fprintf(stdout, "Hello world\n"); int deviceCount = 0; cudaError_t error_id = cudaGetDeviceCount(&deviceCount); if (error_id != cudaSuccess) { printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)error_id, cudaGetErrorString(error_id)); printf("Res...
17,996
#include "nne.cuh" #include "cuda.h" #include "cuda_runtime_api.h" #include "device_launch_parameters.h" #include <cstdlib> __global__ void nodeCal(float* inList, float* wList, float* outList); __global__ void nodeLog(float* outputList, float sigmoidConst); __global__ void nodeGradCal(float* wList, float* outputList, ...
17,997
/* Matrix normalization. * Compile with "gcc matrixNorm.c" */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #include <sys/types.h> #include <sys/times.h> #include <sys/time.h> #include <time.h> /* Program Parameters */ #define MAXN 8000 /* Max value of N */ int N; /* Matrix size *...
17,998
#include <math.h> #include <stdio.h> #include <stdlib.h> __device__ void helper(float const *J,float *If,float *Z,int size,int icenter,int jcenter,int xcenter,int ycenter,int rows,int columns,float const filtSigma,float const *H); __device__ void adjFunction(float const *J,float *If,float *Z,int icenter ,int jcenter,f...
17,999
#include <iostream> #include <cuda.h> #include <cuda_runtime.h> #include <algorithm> #include <stdio.h> constexpr int ids = 557432; int trans[ids]; void trans_init() { trans[557312] = 1; trans[528384] = 3; trans[65536] = 4; trans[0] = 0; trans[8] = 0; trans[136] = 0; trans[557364] = 1; ...
18,000
#include "includes.h" __global__ void matrixMul_sharedMemory(float *M, float *N, float *P, int m, int j, int n) { __shared__ float Mds[TILE_WIDTH][TILE_WIDTH]; __shared__ float Nds[TILE_WIDTH][TILE_WIDTH]; int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x; int ty = threadIdx.y; int Row = by * TILE_WIDTH ...