serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
201
#include <cuda.h> #include <stdio.h> #include <sys/time.h> inline double nowSec() { struct timeval t; struct timezone tzp; gettimeofday(&t, &tzp); return t.tv_sec + t.tv_usec*1e-6; } __host__ void host_mmul (int *A, int *B, int *C, int N) { for(int i=0; i<N; i++) { for (int j=0; j<N; j++) { for(int k=0; ...
202
#include "includes.h" __global__ void Fprop2(const float* layer1, const float* syn2, float* out) { int i = blockDim.y*blockIdx.y + threadIdx.y; //10 int j = blockIdx.x; //Data.count //int k = threadIdx.x; //256 float x = 0.0; for (int k=0; k < 256; ++k) x += layer1[j*256 + k] * syn2[k*10 + i]; out[j*10 + i] = x; }
203
#include <iostream> int static_cuda11_func(int); int shared_cuda11_func(int); void test_functions() { static_cuda11_func( int(42) ); shared_cuda11_func( int(42) ); } int main(int argc, char **argv) { test_functions(); return 0; }
204
#include <math.h> #include <stdlib.h> //! Ising model evolution /*! \param G Spins on the square lattice [n-by-n] \param w Weight matrix [5-by-5] \param k Number of iterations [scalar] \param n Number of lattice points per dim [...
205
#include <stdio.h> #include <cuda_runtime.h> #include <thrust/device_vector.h> #include <thrust/functional.h> __global__ void calc_pi(double *dev, double step) { int i = blockIdx.x * blockDim.x + threadIdx.x; double x = (i + 0.5) * step; dev[i] = 4.0 /(1.0 + x * x); } int main() { static long num_ste...
206
#include <stdlib.h> #include <stdio.h> // Kernel adding entries of the adjacent array entries (radius of 3) of a 1D array // // initial approach // * 7 kernels, each adding one element to the sum // * data always read from main memory __global__ void kernel_add(int n, int offset, int *a, int *b) { int i = blockDim...
207
#include "includes.h" __device__ float do_fraction(float numer, float denom) { float result = 0.f; if((numer == denom) && (numer != 0.f)) result = 1.f; else if(denom != 0.f) result = numer / denom; return result; } __global__ void get_bin_scores(int nbins, int order, int nknots, float * knots, int nsamples, int nx, f...
208
/** Research 4 Fun metaCuda.cu Purpose: Calculates the n-th Fibonacci number an the Factorial of a number from CUDA + Template Meta-Programming @author O. A. Riveros @version 1.0 28 May 2014 Santiago Chile. */ #include <iostream> #include <ctime> using namespace std; // Begin CUDA ////////...
209
/* infix to postfix expression conversion code by Codingstreet.com */ #include<stdio.h> #include<string.h> int push(char *stack,char val,int *top,int *size); int pop(char *stack,int *top); int isstack_empty(int *top); int isstack_full(int *top,int *size); int isstack_empty(int *top){ if((*top)==0) return 1; r...
210
#include "includes.h" __global__ void matrixAddKernel3(float* ans, float* M, float* N, int size) { int col = blockIdx.x*blockDim.x + threadIdx.x; if(col < size) { for(int i = 0; i < size; ++i) ans[i*size + col] = M[i*size + col] + N[i*size + col]; } }
211
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda.h> __global__ void image_conversion(unsigned char *colorImage, unsigned char *grayImage, long long imageWidth, long long imageHeight) { int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; ...
212
#include <thrust/device_vector.h> //#include<iostream> //using std::cout; //using std::endl; //functor struct Smooth { //starting points of x, y, and m thrust::device_vector<float>::iterator dmIt; thrust::device_vector<float>::iterator dxIt; thrust::device_vector<float>::iterator dyIt; int n; ...
213
#include <iostream> #include <stdio.h> /** * Given a device array of integers, compute the index of first nonzero * entry in the array, from left to right. * * For example, opearting on the array * * 0 1 2 3 4 5 6 * [0, 0, 0, -1, 0, 0, 2] * * gets the index 3. The result is stored into deg_ptr (init...
214
#include "includes.h" __global__ void CalculateDiffSample( float *cur, float *pre, const int wts, const int hts ){ const int yts = blockIdx.y * blockDim.y + threadIdx.y; const int xts = blockIdx.x * blockDim.x + threadIdx.x; const int curst = wts * yts + xts; if (yts < hts && xts < wts){ cur[curst*3+0] -= pre[curst*3+...
215
#include "thrust/host_vector.h" #include "thrust/device_vector.h" __global__ void kernel(int *out, int *in, const int n) { unsigned int i = threadIdx.x; if (i < n) { out[i] = in[i] * 2; } } int main(){ thrust::host_vector<int> hVectorIn(1024); for(int i=0;i<1024;i++){ hVectorIn[i]=i; } thrust:...
216
#include "includes.h" __global__ void box_iou_cuda_kernel(float *box_iou, float4 *box1, float4 *box2, long M, long N, int idxJump) { int idx = blockIdx.x*blockDim.x + threadIdx.x; size_t b1_idx, b2_idx, b1_row_offset, b2_row_offset; float xmin1, xmin2, xmax1, xmax2, ymin1, ymin2, ymax1, ymax2; float x_tl, y_tl, x_br, ...
217
#include <cuda_runtime.h> #include <iostream> #include <stdlib.h> #include <ctime> #include <unistd.h> //workers computing square of rands __global__ void kerSquare(int *randsDev,int* resDev){ int myId = blockIdx.x * blockDim.x + threadIdx.x; //std::cout << myId << ", "; resDev[myId] = randsDev[myId] * r...
218
#include <stdio.h> #include<time.h> #define PerThread 1024*4*8//每个线程计算多少个i #define N 64*256*1024*4//积分计算PI总共划分为这么多项相加 #define BlockNum 32 //block的数量 #define ThreadNum 64 //每个block中threads的数量 __global__ void Gpu_calPI(double* Gpu_list) { //核函数 int tid=blockIdx.x*blockDim.x*blockDim.y+threadIdx.x;//计算线程号 int ...
219
#include <fcntl.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/time.h> #include <time.h> #include <unistd.h> typedef struct { long time; double open; double high; double low; double close; double volume; } Minute; typedef str...
220
#include<iostream> using namespace std; __global__ void add(int *a,int*b,int *c,int n) { int index=blockIdx.x*blockDim.x+threadIdx.x; if(index<n) { c[index]=a[index]+b[index]; } } int main() { cout<<"Enter size of vector"; int n; cin>>n; int a[n],b[n],c[n]; for(int i=0;i<n;i++) { cin>>a[i];...
221
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <cuda.h> #define TILE_WIDTH 16 #define cudaCheckError() { \ cudaError_t e = cudaGetLastError(); \ if (e != cudaSuccess) { \ printf("CUDA error %s:%d: %s\n", __FILE__...
222
#include "includes.h" __global__ void add(int *a, int *b, int *c, int *d, int *e, int *f) { *c = *a + *b; *d = *a - *b; *e = *a * *b; *f = *a / *b; }
223
#include <stdio.h> #include <stdlib.h> #include <curand.h> void output_results(int N, double *g_x); int main(void) { curandGenerator_t generator; curandCreateGenerator(&generator, CURAND_RNG_PSEUDO_DEFAULT); curandSetPseudoRandomGeneratorSeed(generator, 1234); int N = 100000; double *g_x; cudaMall...
224
#include <stdio.h> #include <assert.h> #define N 1000000 __global__ void vecadd(int *a, int *b, int *c){ // determine global thread id int idx = threadIdx.x + blockIdx.x * blockDim.x; // do vector add, check if index is < N if(idx<N) { c[idx]=a[idx]+b[idx]; } } int main (int argc, char **argv){ int...
225
//-------------------------------------------------- // Autor: Ricardo Farias // Data : 29 Out 2011 // Goal : Increment a variable in the graphics card //-------------------------------------------------- /*************************************************************************************************** Includes ***...
226
/* Copyright (c) 2015, 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 * in individ...
227
#include "includes.h" __device__ int sum = 1; __global__ void degreeCalc (int *array){ int i = blockDim.x * blockIdx.x + threadIdx.x; if (i>=1000000){ return; } sum+=array[i]; // if (i==999999){ // printf("%d", sum); // } } __global__ void degreeCalc (int *vertexArray, int *neighbourArray, int *degreeCount, int n...
228
/***************************************************************************** C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Example : cuda-matrix-vector-multiplication.cu Objective : Write CUDA program to compute Matrix-Vector multiplication. Input : None ...
229
/* LA-CC-16080 Copyright © 2016 Priscilla Kelly and Los Alamos National Laboratory. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above c...
230
#include <stdio.h> #include <stdlib.h> #include <math.h> #define NUM_NODES 1024 // Declaration of a structure typedef struct { int startIndex; // starting index in Adj list int numberOfNeighbors; // number of neighbors of each vertices } Node; __global__ void bfs_optimized(Node *gpu_vertex, int *gpu_neighbors, bo...
231
__global__ void leakyrelu_kernel(float* output, float* input, float slope, int dim_xw, int dim_xh){ int tid = threadIdx.x; int idx = blockIdx.x * blockDim.x + threadIdx.x; __shar...
232
// A basic macro used to checking cuda errors. // @param ans - the most recent enumerated cuda error to check. #define gpuErrorCheck(ans) { gpuAssert((ans), __FILE__, __LINE__); } #include <curand_kernel.h> #include <cuda_runtime.h> #include <cfloat> // for FLT_MAX #include <iostream> #include <ctime> // for clock() #...
233
#include <stdio.h> #define NUM_BUCKETS 128 __global__ void compute_histogram(const size_t num_elements, const float range, const float *data, unsigned *histogram) { int t = threadIdx.x; int nt = blockDim.x; __shared__ unsigned local_histogram[NUM_BUCKETS]; for (int i = t; i ...
234
#include <stdio.h> #include <time.h> #define NUM_INTERVALS 1000000 #define THREADS_PER_BLOCK 1000 #define BLOCKS 10 double baseIntervalo = 1.0/NUM_INTERVALS; __global__ void piFunc(double * acum){ int t = threadIdx.x; int threads = blockDim.x; acum[t] = 0; int intervals_per_thread = NUM_INTE...
235
#include <stdio.h> #include <cuda_runtime.h> __global__ void simple_histo(int *d_bins, const int *d_in, const int BIN_COUNT, int ARRAY_SIZE) { unsigned int myId = threadIdx.x + blockDim.x + blockIdx.x; // checking for out-of-bounds if (myId>=ARRAY_SIZE) { return; } unsigned int myItem = d_in[myId]; unsigned ...
236
#include "includes.h" __global__ void skip_128b(float *A, float *C, const int N) { int i = (blockIdx.x * blockDim.x + threadIdx.x)+32*(threadIdx.x%32); if (i < N) C[i] = A[i]; }
237
#include <iostream> #include <cstdlib> #include <stdlib.h> #include <ctime> #include <queue> using namespace std; short iterative_bfs(short **matrix, unsigned long long N, short target, bool **visited_matrix); short recursive_bfs(short **matrix, unsigned long long N, short target, bool **visited_matrix); short recurs...
238
//SEE bao_flow_c2f_classic_kernel.cu
239
#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> #define MAXN 8000 /* Max value of N */ int N; /* Matrix Dimension*/ int numThreads; /* Number of Threads */ /*Random*/ #define randm() 4|2[uid]&3 /*CU...
240
#include <iostream> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/random/linear_congruential_engine.h> #include <thrust/random/uniform_real_distribution.h> int main() { int seed; std::cin >> seed; thrust::minstd_rand eng(seed); thrust::uniform_real_distributio...
241
/* Name: Jonathan Dunlap Course: Introduction to Parallel and Cloud Computing CRN: 75092 Assignment: Refactor ParallelTeam Data: 11/19/2013 */ #include <stdio.h> #include <assert.h> #include <cuda.h> #include <cstdlib> __global__ void incrementArrayOnDevice(int *a, int N, int *count) { int id = blockIdx.x ...
242
extern "C" __global__ void kernel_0arg() {} extern "C" __global__ void kernel_1arg(float * arg0) {} extern "C" __global__ void kernel_2arg(float * arg0, float * arg1) {} extern "C" __global__ void kernel_3arg(float * arg0, float * arg1, float * arg2) {} extern "C" __global__ void...
243
#include "includes.h" __global__ void cudaUZeroInit_kernel(unsigned int size, unsigned int* data) { 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) data[i] = 0U; }
244
#include <stdio.h> #include <time.h> #include <unistd.h> #include <stdlib.h> #include <math.h> __global__ void shared_mem(int x[], int n, int blks) { int thread_id = threadIdx.x + blockIdx.x * blockDim.x; __shared__ float temp_data; while(thread_id < n){ temp_data = x[thread_id]; for(int i=0;i<n;i++)...
245
#include "includes.h" __global__ void cu_fliplr(const float* src, float* dst, const int rows, const int cols, const int n){ int tid = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; while(tid < n){ int c = tid % cols; int r = tid / cols; dst[tid] = src[(cols - c - 1) + r * cols]; tid += stri...
246
#include "kernel.cuh" #define TX 32 #define TY 32 #define RAD 1 #define divUp(a,b) ((a) + (b) - 1) / (b) __device__ unsigned char clip(int n){ return n > 255 ? 255 : (n < 0 ? 0 : n);} __device__ int idxClip(int idx,int idxMax){ return idx > idxMax ? idxMax : (idx < 0 ? 0 : idx); } __device__ int flatten(int col...
247
#include <iostream> using namespace std; void getCudaDeviceInfo() { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); cout << "GPU Device Id: " << i << endl; cout << "Device name: " << pr...
248
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<cmath> #include<iostream> #include <stdio.h> #include<iomanip> #include<fstream> using namespace std; #define precision 1E-8 #define PI 3.141592653589793238462643383 #define divide (8192) #define saving 8192 #define lambdamax 1.5 #define dlamb...
249
/******************************************************************************* * serveral useful gpu functions will be defined in this file to calculate * weno derivatives ******************************************************************************/ __device__ inline double max2(double x, double y) { return (...
250
// // Created by brian on 11/20/18. // #include "complex.cuh" #include <cmath> const float PI = 3.14159265358979f; __device__ __host__ Complex::Complex() : real(0.0f), imag(0.0f) {} __device__ __host__ Complex::Complex(float r) : real(r), imag(0.0f) {} __device__ __host__ Complex::Complex(float r, float i) : real...
251
#include <stdio.h> #include <cuda_runtime.h> /* Application adds two vectors declared in the code */ __global__ void vecAdd(int* a, int* b , int* c, int size){ // calculate thread id int id = blockIdx.x*blockDim.x+threadIdx.x; if(id < size){ c[id] = a[id] + b[id]; } } void printVector(int* ve...
252
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #define N (32) __global__ void inc(int *array, int len) { int i; for (i = 0; i < len; i++) array[i]++; return; } int main(int argc, char *argv[]) { int i; int arrayH[N]; int *arrayD; size_t array_size...
253
#include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void add(float *c, float* a, float *b, int values){ int blockD = blockDim.x; int blockX = blockIdx.x; int threadX = threadIdx.x; int i = blockX * blockD + threadX; if(i < values) c[i] = a[i] + b[i]; //printf("Hello Im thread %d in block %d of...
254
/* * This sample implements a separable convolution * of a 2D image with an arbitrary filter. */ #include <time.h> #include <stdio.h> #include <stdlib.h> unsigned int filter_radius; #define FILTER_LENGTH (2 * filter_radius + 1) #define ABS(val) ((val)<0.0 ? (-(val)) : (val)) #define accuracy 0.0005 ///////////...
255
#include "includes.h" #pragma once /* //åñëè äëÿ âñåõ êàðò õâàòèò âîçìîæíîñòåé âèäåîêàðòû (ÐÀÁÎÒÀÅÒ) */ __global__ void MapAdd1(int* one, const int* result, unsigned int mx, unsigned int width) { const unsigned int ppp = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int rix = ppp % width; const unsigned ...
256
#include <stdio.h> // Device code __global__ void VecAdd(float* A, float* B, float* C, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) C[i] = A[i] + B[i]; } // Initialise the input vectors void initialise_input_vect(float* A, float* B, int N) { for(int i=0; i<N; i++){ A[i]=i; ...
257
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <device_functions.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #define PI 3.1415926535897932 #define MAXEQNS 10 // maximum number of differential equations in the system const int itermax10 = 2; /...
258
#include <cstdio> #include <cstdlib> #include <vector> __global__ void initBucket(int *bucket) { int i = blockIdx.x*blockDim.x + threadIdx.x; // i = threadIdx.x in this code bucket[i] = 0; } __global__ void setBucket(int *bucket, int *key) { int i = blockIdx.x*blockDim.x + threadIdx.x; atomicAdd(&(bucket[key...
259
#include "includes.h" __global__ void assignColIds(int* colIds, const int* colOffsets) { int myId = blockIdx.x; int start = colOffsets[myId]; int end = colOffsets[myId + 1]; for (int id = start + threadIdx.x; id < end; id += blockDim.x) { colIds[id] = myId; } }
260
extern "C" __global__ void sconv_bprop_C128_N128 ( float* param_test, float* param_O, const float* param_I, const float* param_F, float param_alpha, int param_N, int param_K, int param_D, int param_H, int param_W, int param_WN, int param_HWN, int param_DHWN, int param_C, int param_CRST, ...
261
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <cuda.h> #define THREADS_PER_BLOCK 512 #define ARRAY_SIZE 512*512 __global__ void getMin(int* array, int* results, int n){ int i = threadIdx.x + blockIdx.x * blockDim.x; if(i >= n){ array[i] = INT_MAX; } __syncthreads(); ...
262
#include "includes.h" __global__ void StarRadKernel (double *Qbase2, double *Vrad, double *QStar, double dt, int nrad, int nsec, double *invdiffRmed, double *Rmed, double *dq) { int j = threadIdx.x + blockDim.x*blockIdx.x; int i = threadIdx.y + blockDim.y*blockIdx.y; double dqm, dqp; if (i<nrad && j<nsec){ if ((i == ...
263
#include "includes.h" #define N 100000000 __global__ void daxpy_simple(int n, double alpha, double *x, double *y) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { y[idx] += alpha * x[idx]; } }
264
#include <iostream> #include<ctime> using namespace std; __global__ void mini(int *a,int *b,int n) { int tid = threadIdx.x; int minn = INT_MAX; for(int i=0;i<min(tid+256,n);i++) { if(minn>a[i]) minn = a[i]; } b[tid] = minn; } int main() { int *a,*b,size,n; int *d_a,*d_b; cin>>n; size = n*sizeof(int); ...
265
// Copyright 2018,2019,2020,2021 Sony Corporation. // // 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...
266
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <math.h> #include <limits.h> #include "cuda_kernel.cuh" int solveProblem(const int argc, const char* argv[]){ cudaError_t return_value; if(argc == 2){ cudaEvent_t start, stop; float time; int threads = atoi(argv[1]); cudaEventCreate(&sta...
267
#include "includes.h" __device__ float explicitLocalStepHeat( float unjpo, float unjmo, float unj, float r) { return (1 - 2 * r)*unj + r*unjmo + r * unjpo; } __global__ void explicitTimestepHeat( int size, float *d_currentVal, float *d_nextVal, float r ) { int i = threadIdx.x + blockDim.x * blockIdx.x; if (i < size) { ...
268
/** * 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...
269
#include <cstdlib> #define PI 3.1415926535897932384626433832795029f #define PIx2 6.2831853071795864769252867665590058f #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define K_ELEMS_PER_GRID 2048 #define KERNEL_PHI_MAG_THREADS_PER_BLOCK 512 #define KERNEL_Q_THREADS_PER_BLOCK 256 #define KERNEL_Q_K_ELEMS_PER_GRID 1024 ...
270
#include <cstdio> #include <math.h> #include <ctime> #include <iostream> using namespace std; int performanceMeasure1(); int performanceMeasure2(); int performanceMeasure3(); int performanceMeasure4(); int performanceMeasure5(); int countSortSerial1(); int countSortSerial2(); int countSortSerial3(); int countSortSeri...
271
#include "includes.h" __global__ void cube_select(int b, int n,float radius, const float* xyz, int* idx_out) { int batch_idx = blockIdx.x; xyz += batch_idx * n * 3; idx_out += batch_idx * n * 8; float temp_dist[8]; float judge_dist = radius * radius; for(int i = threadIdx.x; i < n;i += blockDim.x) { float x = xyz[i * 3...
272
#include <cuda_runtime.h> __global__ void matmult_gpu1Kernel(int m, int n, int k, double * d_A, double * d_B, double * d_C); extern "C" { void matmult_gpu1(int m, int n, int k, double * A, double * B, double * C){ double * d_A, * d_B, * d_C; cudaMalloc((void **)&d_A, m * k * sizeof(double *)); cudaMalloc((void **...
273
#include <stdio.h> #include <stdlib.h> #include <cuda.h> // CUDA example: finds row sums of an integer matrix m // find1elt() finds the row sum of one row of the nxn matrix m, // storing the result in the corresponding position in the // rowsum array rs; matrix is in 1-dimensional, row-major order // this is the ...
274
#include "includes.h" __global__ void gpu_stencil37_hack2_cp_slices(double * dst, double * shared_rows, double *shared_cols,double *shared_slices,int d_xpitch,int d_ypitch,int d_zpitch,int s_xpitch,int s_ypitch, int s_zpitch, int n_rows, int n_cols,int n_slices, int tile_x,int tile_y, int tile_z){ #ifdef CUDA_CUDA_DEB...
275
#include "includes.h" __global__ void x_avpb_py_f32 (float* x, float a, float* v, float b, float* y, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { y[idx] += x[idx] * (a * v[idx] + b); } }
276
#include "includes.h" __global__ void reduction(int* input, int* output) { __shared__ int tmp[TPB]; tmp[threadIdx.x] = input[threadIdx.x + blockIdx.x * blockDim.x]; __syncthreads(); if(threadIdx.x < blockDim.x / 2) tmp[threadIdx.x] += tmp[threadIdx.x + blockDim.x / 2]; __syncthreads(); if(threadIdx.x < blockDim.x ...
277
#include <stdio.h> #include <stdlib.h> #include <math.h> // Kernel that executes on the CUDA device __global__ void square_array(float *a, float *b, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx<N) { a[idx] = a[idx] * a[idx]; } } // main routine that executes on the host int main(void) { ...
278
//nvcc -ptx EM4.cu -ccbin "F:Visual Studio\VC\Tools\MSVC\14.12.25827\bin\Hostx64\x64" __device__ void EM1( double * x, double * y, double * z, double * vx, double * vy, double * vz, double * ...
279
#include <unistd.h> #include <stdio.h> #define THREADS 256 #define START 0 #define END 1000 __global__ void sum(int* result) { __shared__ int partials[THREADS]; int start = ((END - START) / blockDim.x) * threadIdx.x; int end = start + ((END - START) / blockDim.x) - 1; if (threadIdx.x == (THREADS - 1...
280
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<bits/stdc++.h> #include <numeric> #include<math.h> //#define 10 10 using namespace std; __global__ void cuda_add(int *da,int *db,int *dc) { int i = threadIdx.x + blockIdx.x * blockDim.x; //dc[i] = da[i]=db[i]=0; dc[i] = da[i]+db[i]; //prin...
281
#include <iostream> #include <stdio.h> #include <math.h> #include <vector> /** * Several variations of a simple 3D 7-point Laplacian. * * Notes: * - Since it is a very simple example which naturally fits the parallelization * model of CUDA, there are not many elaborate optimization. * - Using shared memory might...
282
#include <iostream> #include <cmath> /* Ryan McDonald CSUF Spring 2021 CPSC 479 - Dr. Bein */ __global__ void squareMatrix(int* matrix, int* result, int N) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; int sum = 0; if (row < N && col < N) { for (int i = 0;...
283
#include "cuda_runtime.h" #include <cuda.h> #include <cstdio> #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include "device_launch_parameters.h" using namespace std; const int MAX_STRING_LENGTH = 256; const int THREADS = 3; const string DATA_FILE = "/home/lukasz/Documents/GitHub/Lygret...
284
#include <iostream> #include <thrust/version.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/reduce.h> #include <thrust/fill.h> // examples // [1] https://github.com/thrust/thrust/wiki/Quick-Start-Guide void thrust_reduce_by_key(thrust::device_vector<int> &d_keys, ...
285
#include <iostream> #include <cstdlib> #include <cassert> #include <zlib.h> #include <png.h> #include <queue> #include <thread> #include <mutex> #include <condition_variable> #include <vector> using namespace std; #define MASK_N 2 #define MASK_X 5 #define MASK_Y 5 #define SCALE 8 #define NUM_THREAD 512 __constant__ i...
286
#include "includes.h" __global__ void ExactResampleKernel_1toN(float *input, float *output, int inputWidth, int inputHeight, int outputWidth, int outputHeight) { int id = blockDim.x * blockIdx.y * gridDim.x + blockDim.x * blockIdx.x + threadIdx.x; int size = outputWidth * outputHeight; if (id < size) { //output point ...
287
#include <stdio.h> #include <stdlib.h> // questions: // 1. if I had a bunch of vectors to add in succession, would there be any benefit in keeping the memory allocated // and doing all the additions before freeing memory? What would be the impact? // 2. given that thread creation has some overhead, would it make sen...
288
#include "includes.h" __global__ void addKernel(int *c, const int *a, const int *b, int size) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < size) { c[i] = a[i] + b[i]; } }
289
#include <iostream> using namespace std; void SimpleIntegerAdd(); void TestIntegerArrayAdd(); int main(int argc, char *argv[]) { // SimpleIntegerAdd(); TestIntegerArrayAdd(); }
290
/* #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <iostream> //vector int main(void) { // H has storage for 4 integers thrust::host_vector<int> H(4); // initialize individual elements H...
291
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <sys/time.h> using namespace std; // ############### COMMON ############### #define CHECK(call) \ { \ const cuda...
292
#include <cstdio> #include <cstdlib> #include <vector> __device__ __managed__ int sum; __global__ void thread(int *a) { a[threadIdx.x] = 0; } __global__ void reduction(int *bucket,int *key) { int i = threadIdx.x; atomicAdd(&bucket[key[i]], 1); } __global__ void sort(int num,int *key,int sum) { int thread ...
293
#include<bits/stdc++.h> #define N 16 #define BLOCK_DIM 16 using namespace std; __global__ void multiply(float A[], float B[], float C[]) { __shared__ float sub_A[BLOCK_DIM][BLOCK_DIM], sub_B[BLOCK_DIM][BLOCK_DIM]; int global_x = threadIdx.x + blockIdx.x * blockDim.x, global_y = threadIdx.y + blockIdx....
294
#include<stdio.h> #include<stdlib.h> #include<math.h> __global__ void add(double *a,double *b,double *c,int n) { int id=blockIdx.x*blockDim.x+threadIdx.x; if(id<n) { c[id] = a[id] + b[id]; } } int main() { int n=8; double *h_a,*h_b,*h_c,*d_a,*d_b,*d_c; size_t bytes = n*sizeof(double); h_a=...
295
//Based on the work of Andrew Krepps #include <stdio.h> #include <stdio.h> #define ARRAY_SIZE N #define ARRAY_SIZE_IN_BYTES (sizeof(unsigned int) * (ARRAY_SIZE)) ////////////////////////OPERATIONS////////////////////////////////////////////// //ADD=1 __global__ void add(int * array1,int * array2,int * array3) { ...
296
#include<stdio.h> #include<sys/time.h> // time of execution AOS will be more than SOA as AOS contains other data // which is not yet loaded. // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char* msg); const int numThreads = 1000000; int numThreadsPerBlock = 16; // Array of str...
297
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <string.h> #define TIMER_CREATE(t) \ cudaEvent_t t##_start, t##_end; \ cudaEventCreate(&t##_start); \ cudaEventCreate(&t##_end); #define TIMER_START(t) \ cudaEven...
298
#include "includes.h" extern "C" { } #define TB 256 #define EPS 0.1 #undef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) #undef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) __global__ void patchmatch2_conv_kernel( float *A, float *B, float *AP, float *BP, float *conv, int *prev_corrAB_upsampled, int patch, int ...
299
#include <stdio.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) { printf("blockId, threadId, dims: [%d, %d], [%d, %...
300
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdint.h> #include<stdio.h> __global__ void convolution_kernel(const uint8_t *d_source, uint8_t *d_target, const int width, const int height, const float *d_stancil, c...