serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
1,501
#include "includes.h" __global__ void cudaUpdateMostActive_kernel(unsigned int * exampleFiringRate, unsigned int * mostActiveId, unsigned int inputsDimX, unsigned int inputsDimY, unsigned int inputsDimZ) { const unsigned int inputSize = inputsDimZ * inputsDimX * inputsDimY; const unsigned int batchInputOffset = block...
1,502
/******************************************************************************** * * Copyright (C) 2009-2011 Bauhaus University Weimar * ********************************************************************************* * * module : splat_volume_samples.cu * project : gpucast * description: * ****************...
1,503
#include "includes.h" __global__ void AplusB(int *ret, int a, int b) { ret[threadIdx.x] = a + b + threadIdx.x; }
1,504
#include<iostream> #include<fstream> #include<math.h> #include<stdlib.h> #include<curand_kernel.h> #include<curand.h> #define MAX_CITIES 318 #define MAX_ANTS 318 #define Q 100 #define ALPHA 1.0 #define BETA 5.0 #define RHO 0.5 using namespace std; int n=0; int NC = 0; int t = 0; struct cities { int x,y; }; int...
1,505
#include "includes.h" __global__ void unsafe(int *shared_var, int *values_read, int N, int iters) { int i; int tid = blockIdx.x * blockDim.x + threadIdx.x; if (tid >= N) return; int old = *shared_var; *shared_var = old + 1; values_read[tid] = old; for (i = 0; i < iters; i++) { int old = *shared_var; *shared_var = ol...
1,506
#include<bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264; const double L = 100.; const double Diff = 1.; const int MAX_BLOCK_SIZE = 1048; /* | coordinate system: -|---------------y | x = i * d_x | y = i * d_x | x */ inline double left(double y) { return 0; } inline d...
1,507
#include <stdio.h> /* * ๅ…ˆใปใฉใ‚ใฃใŸๅผ•ๆ•ฐ `N` ใŒใชใ„ใ“ใจใซๆณจ็›ฎใ—ใฆใใ ใ•ใ„ใ€‚ */ __global__ void loop() { /* * ใ“ใฎใ‚ซใƒผใƒใƒซใฏใ€ๅ…ƒใฎ for ใƒซใƒผใƒ—ใ‚’ 1 ๅ›žใ ใ‘ๅๅพฉใ—ใพใ™ใ€‚ * ใ“ใฎใ‚ซใƒผใƒใƒซใซใ‚ˆใฃใฆไฝ•ๅ›ž็›ฎใฎใ€Œๅๅพฉใ€ใŒๅฎŸ่กŒใ•ใ‚Œใฆใ„ใ‚‹ใ‹ใฏใ€ * `threadIdx.x` ใ‚’ไฝฟ็”จใ—ใฆ็ขบ่ชใงใใพใ™ใ€‚ */ printf("This is iteration number %d\n", threadIdx.x); } int main() { /* * ใ“ใ‚Œใฏใ€Œใƒซใƒผใƒ—ใ€ใฎใ€Œๅๅพฉใ€ๅ›žๆ•ฐใ‚’่จญๅฎšใ™ใ‚‹ๅฎŸ่กŒใ‚ณใƒณใƒ†ใ‚ญใ‚นใƒˆใงใ™ใ€‚ *...
1,508
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #define BLOCK_SIZE 16 __global__ void gpu_matrix_multiply(float* a,float* b,float* c, int m, int n, int k) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; float sum = 0; int i; if( col < k &&...
1,509
extern "C" __global__ void matrixMultiplicationKernel(double* A, double* B, double* C, long N) { int ROW = blockIdx.y*blockDim.y+threadIdx.y; int COL = blockIdx.x*blockDim.x+threadIdx.x; double tmpSum = 0.0; if (ROW < N && COL < N) { // each thread computes one element of the block sub-matrix...
1,510
#include "includes.h" __global__ void CalculateSampleT( const float *target, const float *mask, float *subT, int *subM, const int wt, const int ht, const int ws, const int hs, const int sRate ){ const int ys = blockIdx.y * blockDim.y + threadIdx.y; const int xs = blockIdx.x * blockDim.x + threadIdx.x; const int curst =...
1,511
#include "includes.h" __global__ void reverse_colors_kernel(int num_rows, int max_color, int *row_colors) { int row_id = blockIdx.x * blockDim.x + threadIdx.x; for ( ; row_id < num_rows ; row_id += blockDim.x * gridDim.x ) { int color = row_colors[row_id]; if (color > 0) { //1 -> max_color //max_color -> 1 color = ma...
1,512
#include<math.h> #include<time.h> #include<stdexcept> #include<iostream> #include<cstdlib> //for abs(x) #include<stdio.h> using namespace std; __global__ void findMax(int* A,int* current_max,int* mutex,unsigned int n); int main() { const int NUMBER_OF_ELEMENTS = 1024*1024*20; int* hostA = (int*)malloc(NUMBER_O...
1,513
#include "includes.h" __global__ void gpu_seqrd_kernel(int *buffer, size_t reps, size_t elements) { int errors = 0; for(size_t j = 0; j < reps; j++) { size_t ofs = blockIdx.x * blockDim.x + threadIdx.x; size_t step = blockDim.x * gridDim.x; while(ofs < elements) { // manually unroll loop to get multiple loads in flight...
1,514
#include "includes.h" __global__ static void reduce(int *g_idata, int l1, int l2) { extern __shared__ unsigned int sdata[]; unsigned int tid = threadIdx.x; if (tid < l1) { sdata[tid] = g_idata[tid]; } else { sdata[tid] = 0; } __syncthreads(); // Parallel Reduction (l2 must be power of 2) for (unsigned int s = l2 / 2;...
1,515
// #CSCS CUDA Training // // #Example 2.1 - sum vectors, fix number of threads // // #Author Ugo Varetto // // #Goal: compute the scalar product of two 1D vectors using a number of threads lower than the // size of the output vector. // // #Rationale: shows how to implement a kernel with a computation/memory c...
1,516
#include <iostream> #include <fstream> #include <stdlib.h> #include <unistd.h> #include <vector> #include <complex> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include <math.h> #include <map> #include <stdexcept> #include <cuda.h> #include <cufft.h> //#include <helper_functions.h> //#include <hel...
1,517
#include "cuda.h" #include <stdio.h> #include <stdlib.h> __global__ void cudaADD(int* a, int* b) { a[0]+=b[0]; } int main(){ int a=5, b=6; int *c_a, *c_b; // Allocate memory for CUDA cudaMalloc(&c_b, sizeof(int)); cudaMalloc(&c_a, sizeof(int)); // Transfer data to GPU from CPU cudaMemcpy(c_a, &a, si...
1,518
#include <stdio.h> #include <stdlib.h> #include <time.h> #define BLOCK 30000 #define THREAD 1000 #define CHECK 1 void stopwatch(int); //๊ทธ๋ƒฅ ๊ธ€๋กœ๋ฒŒ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ __global__ void count( int* cnt) { (*cnt)++; } //Atomic ํ•จ์ˆ˜ ์‚ฌ์šฉ __global__ void atomic_count( int* cnt) { //Atomic ํ•จ์ˆ˜, ๋”ํ•˜๋Š” ๋Œ€์ƒ์„ ํฌ์ธํ„ฐ๋กœ ์ง€์ •ํ•ด์•ผํ•œ๋‹ค //ํ•œ๋ฒˆ์— ํ•˜๋‚˜์˜ ์“ฐ๋ ˆ๋“œ๋งŒ ์ž‘์—…ํ•œ๋‹ค atomi...
1,519
#include "includes.h" __global__ void naiveHistKernel(int* bins, int nbins, int* in, int nrows) { int tid = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; auto offset = blockIdx.y * nrows; auto binOffset = blockIdx.y * nbins; for (; tid < nrows; tid += stride) { int id = in[offset + tid]; i...
1,520
#include <stdlib.h> #include <stdio.h> #include <sys/time.h> /* change dimension size as needed */ const int dimension = 4096 ; const int blocksize = 64; const int K = 4; const int tilewidth = 2 ; struct timeval tv; __global__ void gpuSmMM( float *Ad , float *Bd , float *Cd , int dimention ) { //Taking sh...
1,521
#include<stdio.h> #include<assert.h> #include<cuda.h> #define N 1000000 #define HANDLE_ERROR( err )(handleCudaError( err, __FILE__, __LINE__ ) ) int handleCudaError(cudaError_t cut,const char* file, int line) { if(cut != cudaSuccess) { printf("%s : File: %s Line: %d \n",cudaGetErrorString(cut),file,line); ret...
1,522
#define FORRANGE(index, length) for (size_t index = threadIdx.x + blockIdx.x * blockDim.x; index < length; index += gridDim.x * blockDim.x) extern "C" __global__ void axpy_f(const size_t len, const float alpha, const float *x, float *y) { FORRANGE(i, len) { y[i] += alpha * x[i]; } }
1,523
// Mandelbrot.Framework.Gpu.JuliaGpu extern "C" __global__ void JuliaKernel( int* levels, int levelsLen0, unsigned char* colors, int colorsLen0, unsigned char* palette, int paletteLen0, int w, int h, double sx, double sy, double sw, double sh, int maxLevels, double* parameters, int parametersLen0); // Mandelbrot.F...
1,524
#include "includes.h" __global__ void reduce2(float *in, float *out, int n) { extern __shared__ float sdata[]; // load shared mem unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x*blockDim.x + threadIdx.x; sdata[tid] = (i < n) ? in[i] : 0; __syncthreads(); // do reduction in shared mem for (unsigned int s...
1,525
#include "includes.h" __global__ void init(int n, float *x, float *y) { int lane_id = threadIdx.x & 31; size_t warp_id = (threadIdx.x + blockIdx.x * blockDim.x) >> 5; size_t warps_per_grid = (blockDim.x * gridDim.x) >> 5; size_t warp_total = ((sizeof(float)*n) + STRIDE_64K-1) / STRIDE_64K; if(blockIdx.x==0 && thread...
1,526
__global__ void wave1Drusanov3(double * f_next,double * f_tmp, double * f_in, double nu, double omega, int N){ int tid=threadIdx.x+blockIdx.x*blockDim.x; if(tid<N){ int x_2m=tid-2; if(x_2m<0) x_2m+=N; int x_m = tid-1; if(x_m<0) x_m+=N; int x_p = tid+1; if(x_p>(N-1)) x_p-=N; in...
1,527
#include <stdio.h> __global__ void hello_cuda() { printf("Hello Cuda!\n"); } int main() { dim3 block(4); dim3 grid(8); hello_cuda<<<grid, block>>>();; cudaDeviceSynchronize(); cudaDeviceReset(); return 0; }
1,528
#include "includes.h" __global__ void histogram( int * hist_out, unsigned char * img_in, int img_w,int img_h, int nbr_bin){ int tx=threadIdx.x; int ty=threadIdx.y; int bx=blockIdx.x; int by=blockIdx.y; unsigned int col= tx + blockDim.x * bx; unsigned int row= ty + blockDim.y * by; int grid_width = gridDim.x * bloc...
1,529
// fermi // Avoid mangling of function names extern "C" { __global__ void matmulKernel (int n, int m, int p, float* c, const float* a, const float* b); } __global__ void matmulKernel (int n, int m, int p, float* c, const float* a, const float* b) { const int ttj = threadIdx.x; const int wtj = threadIdx....
1,530
#include "compare.cuh" __global__ void forward_kernel(float *y, const float *x, const float *k, const int B, const int M, const int C, const int H, const int W, const int K) { /* The goal here is to be correct AND fast. We have some nice #defs for you below to simplify indexing. Feel free to use them, or create you...
1,531
/***************************************************************************//** * \file LHS1.cu * \author Christopher Minar (minarc@oregonstate.edu) * \brief kernels to generate the left hand side for the intermediate velocity solve */ #include "LHS1.h" namespace kernels { __global__ void LHS1_mid_iter_X(int *ro...
1,532
/* Copyright 2012 by Erik Opavsky * * 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 ...
1,533
#include<stdio.h> #define N 32 void add(int *X, int *Y, int *Z) { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) { Z[i*N+j] = X[i*N+j] + Y[i*N+j]; } } __global__ void add_kernel(int *X, int *Y, int *Z){ int i = threadIdx.x; int j = threadIdx.y; Z[i*N+j] = X[i*N+j] + Y[i*N+j]; } int main() { cudaE...
1,534
// Cudafy_Test.RuneCalc extern "C" __global__ void calc_r(int n, int* build, int buildLen0, int buildLen1, int* stat, int statLen0, int* mult, int multLen0, int multLen1, int* flat, int flatLen0, int flatLen1, int* res, int resLen0, int resLen1); // Cudafy_Test.RuneCalc extern "C" __global__ void calc_r(int n,...
1,535
#include "includes.h" __global__ void add(float *array_a, float *array_b, float *array_c, int size) { int tid = blockIdx.x * blockDim.x + threadIdx.x; int step = blockDim.x * gridDim.x; for (int i = tid; i < size; i += step) { array_c[i] = array_a[i] + array_b[i]; } }
1,536
#include <sys/types.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <linux/fb.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <time.h> /* Conway's Game of Life running on nVidia GPUs. Each GPU thread updates the state of a single cell in the playing field, the...
1,537
// Host defines #define NUM_THREADS 1024 #define NUM_GRID 1 #define MAX_SIM_NUM 50000 #define THRESHOLD 2 // Includes #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <limits.h> using namespace std; // GPU Kernels declarations __global__ void CudaTest_kernel(i...
1,538
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> // DEVICE CODE: // Kernel: __global__ void hello_cuda(){ printf("Hello CUDA world!\n"); } // HOST CODE int main(){ int nx, ny; nx = 16; ny = 4; dim3 block(8, 2, 1); dim3 grid(nx/block.x, ny/block.y, 1); // launching kernel:...
1,539
// Some useful utilities // system includes #include <stdio.h> #include <assert.h> #include <cuda.h> // External function definitions void checkCUDAError(const char *msg) { cudaError_t err = cudaGetLastError(); if( cudaSuccess != err) { fprintf(stderr, "Cuda error: %s: %s.\n", msg, ...
1,540
/* Command to compile on Windows: nvcc .\lab5_2_3.cu -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64" Output should be: a: [22, 13, 16, 5] b: [5, 22, 17, 37] c: 853 */ #include <stdio.h> __global__ void dot_prod(int *c, int *a, int *b) { extern __s...
1,541
#include "simuParams.cuh" __host__ SimuParams::SimuParams(){} __host__ SimuParams::SimuParams(int _number_of_particles, int _particles_per_stream, real _TR, real _TE, real _timestep, int _n_mags_track, Vector3 m_initial, Vector3 _B0, int _res_x, int _res_y, real _FOVx, real _FOVy ):seed_offset(0){ numbe...
1,542
/** * TSM2 and ISM2 Testbed and Evaluation Platform * by Cody Rivera, 2019-2020 * * Usage - ./multiply [-d] [-i] matrixA matrixB matrixC * where -d signifies double precision, and -i signifies * ISM2 */ #include <cmath> #include <cstdio> #include <cstdlib> #include <fstream> #include <iostream> #include "cubla...
1,543
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda_runtime.h> __global__ void squareKernel(float* d_in, float *d_out) { const unsigned int lid = threadIdx.x; const unsigned int gid = blockIdx.x*blockDim.x + lid; d_out[gid] = d_in[gid]*d_in[gid]; } int main(int argc...
1,544
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> __global__ void Pass0_clean(int32_t *ptBufferDxOut, int32_t *ptBufferDyOut, u_int32_t *ptSobelOut, u_int32_t *ptLabelOut, u_int32_t *ptArea, ...
1,545
#include "add.cuh" __global__ void add(int a, int b, int *c) //kernel function๏ผŒrunning on gpu { *c = a + b; } int add(int a,int b) { int c; int *dev_c; cudaMalloc((void**)&dev_c, sizeof(int)); add<<<1,1>>>(a, b, dev_c); cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost); ...
1,546
#include <stdlib.h> #include <vector> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <algorithm> int main(int argc, char **argv) { thrust::host_vector<int> h_vec(100); std::vector<int> a_std(100); thrust::...
1,547
#include<iostream> #include<cuda.h> #include<cstdlib> #include<ctime> #define LIM 100 using namespace std; __global__ void cudaAdd(int *d_a, int *d_b, int *d_c) { int i = (blockIdx.x * blockDim.x) + threadIdx.x; if (i<LIM) { d_c[i] = d_a[i] + d_b[i]; } } int main() { int a[LIM],b[LIM],c[LIM]; int *d_a, *d_b...
1,548
#include "complex.h" __device__ double2 complexPlus(double2 A, double2 B) { return { A.x + B.x, A.y + B.y }; } __device__ double2 complexMinus(double2 A, double2 B) { return { A.x - B.x, A.y - B.y }; } __device__ double2 complexMultiply(double2 A, double2 B) { return { A.x * B.x - A.y * B.y, A.x * B.y + ...
1,549
// starter code taken from https://www.topcoder.com/community/competitive-programming/tutorials/assignment-problem-and-hungarian-algorithm/ // // edited by Joseph Greshik and Allee Zarrini #include<iostream> #include<stdio.h> #include<string> #include<fstream> #include<cstring> #define INF 100000000 //just infinity...
1,550
#include <stdio.h> #include <cuda.h> #include <cuda_runtime_api.h> #include <device_launch_parameters.h> #include <time.h> #define GRID_SIZE 8 #define BLOCK_SIZE 32 #define min(a, b) (a < b ? a : b) __global__ void mergeSort(int *d1, int *d2, int width, int n){ int tid = blockIdx.x * blockDim.x + threadIdx.x; in...
1,551
#include <iostream> #include <stdio.h> #include <vector> #define MAX_THREADS 256 #define SIZE 524288 #define __START__ cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); #define __STOP__(_V) cudaEventRecord(stop, 0); cudaEventSynchronize(stop); cudaEventElapsedTime(&time, start, stop); _V.pus...
1,552
/* * Author: Tejeswini * Purpose: 2D convolution of image on CPU and GPU */ #include <iostream> #include <stdio.h> #include "cuda.h" #include "cuda_runtime.h" #include "device_launch_parameters.h" #define _USE_MATH_DEFINES #include <math.h> #include <time.h> #include <string> #include <cstring> #define _CRT_SECURE...
1,553
#include "includes.h" __global__ void g_One_Bgrad(float* _delta, float* bgrad, int rows, int cols, int channels) { extern __shared__ float _sum[]; int channel = blockIdx.x; int col = blockIdx.y; int row = threadIdx.x; float delta = _delta[channel * rows * cols + row * cols + col]; _sum[row] = delta; __syncthrea...
1,554
#include "cuda.h" #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> __global__ void occupancy_test(int * results) { int gid = blockDim.x * blockIdx.x + threadIdx.x; int x1 = 1; int x2 = 2; int x3 = 3; int x4 = 4; int x5 = 5; int x6 = 6; int x7 = 7; int x8...
1,555
#include <stdio.h> #include <cuda_runtime_api.h> #include <time.h> /**************************************************************************** This program gives an example of a poor way to implement a password cracker in CUDA C. It is poor because it acheives this with just one thread, which is obviously not g...
1,556
#include "includes.h" __global__ void floyd1DKernel(int * M, const int nverts, const int k){ int ii = blockIdx.x * blockDim.x + threadIdx.x; // indice filas, coincide con ij int i = ii/nverts; int j = ii - i * nverts; if(i < nverts && j < nverts){ int kj = (k*nverts) + j; // printf("TID = %u \n\tI = %u => \tM[%u] =...
1,557
#include "includes.h" #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif __global__ void vec_add(float *A, float *B, float* C, int size) { int index = blockIdx.x*blockDim.x + threadIdx.x; if(index<size) C[index] = A[index] + B[index]; }
1,558
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <time.h> //************variables globales*************** int msk=3, dimx=1040, dimy=1388, tam_imag=1388*1040; // [i][j] = i*dimy+j //************** Kernel CUDA ********************* __global__ void Varianza (int *G_d, float *var_d){ int idx = threa...
1,559
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #define DataSize 1024 __global__ void Mirror(unsigned int *Da, unsigned int *Dc, int high,int width) { int tx = threadIdx.x; int bx = blockIdx.x; int bn = blockDim.x; int id = bx*bn+tx; Dc[id] = Da[bx * bn + bn - 1 - tx]; } __global...
1,560
#include <cub/cub.cuh> using namespace cub; template<int BLOCK_SIZE, int CPG> __global__ void cal_group_coo_format_nnz_kernel_cm(float *A, int nRows, int nCols, int *pNnzPerGroup) { int startIdx = blockIdx.x * CPG; int nnz = 0; int nColPerThread = (nCols + BLOCK_SIZE - 1) / BLOCK_SIZE; int colOffset =...
1,561
//first cuda program //Hitender Prakash #include <stdio.h> //define gpu kernel __global__ void square(double *d_out, double *d_in){ int pos=threadIdx.x; d_out[pos]=d_in[pos]*d_in[pos]; } int main(int argc, char **argv){ if(argc <2 ||argc >2){ printf("\nUsage: sqaure <size of array>"); exit(0); } int siz=a...
1,562
#include <stdio.h> #include <queue> #include <set> #include <list> #include <iterator> #include <algorithm> #include <time.h> #include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #define ARRAY_SIZE 30 #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code,...
1,563
#include<iostream> #include<cstdio> using namespace std; __global__ void sum(int *a,int *b,int n) { int block=256*blockIdx.x; int sum=0; for(int i=block;i<min(block+256,n);i++) { sum=sum+a[i]; } b[blockIdx.x]=sum; } int main() { cout<<"Enter the no of elements"<<endl; int n; cin>>n; int a[n]; for(int...
1,564
#include <stdio.h> // 1. Add kernel function here // 2. Get the number of threads in a block, block and thread indices and print them: // printf("Hello from GPU thread %d = %d * %d + %d\n", threadIndex, blockIndex, blockSize, threadInBlock); int main() { int numThreadsInBlock = 32; int numBlocks = 3; ...
1,565
#include "includes.h" __global__ void k4(int *Aux,int *S){ if(blockIdx.x==0) return; int tid=blockIdx.x*B+threadIdx.x; S[tid]+=Aux[blockIdx.x-1]; }
1,566
/** * Copyright 1993-2015 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...
1,567
__device__ double basis_eval(double x, double y, int i) { switch (i) { case 0: return 1.414213562373095E+00; case 1: return -1.999999999999999E+00+ 5.999999999999999E+00*x; case 2: return -3.464101615137754E+00+ 3.464101615137750E+00*x+ 6.928203230275512E+00*y; case 3: return 2...
1,568
#include "includes.h" __global__ void OPT_3_SIZES_SUM(int* lcmsizes, int n) { for(int i = 0; i < n; i++) lcmsizes[i+1] += lcmsizes[i]; }
1,569
#include "includes.h" __device__ double get_collective_dist(int *dist, int rows, int cols, int col) { double sum = 0; for (int i = 0; i < rows; i++) { if (dist[i * cols + col] == 0) { return 0; } sum += (1 / (double)dist[i * cols + col]); } return sum; } __global__ void collective_dist_kernel(int *dist, int rows, int c...
1,570
#define N 15 #define B 2 #define T 32 __global__ void dl(int* in) { int tid = threadIdx.x + blockIdx.x * blockDim.x; if(tid < N) { if(tid % 2 == 0) in[tid]++; __syncthreads(); // ouch int sum = in[tid]; if(tid > 0) sum += in[tid-1]; if(tid < N - 1) sum += in[tid+1]; ...
1,571
//////////////////////////////////////////////////////////// //Ho Thien Luan -> History Tracking! // 1. multi_pat_asm_naive_cpu.cu // 2. // // // //////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <time.h> #include <cuda...
1,572
#include "includes.h" __global__ void MatrixMulVarKernel(float* M, float* N, float* P, int widthAHeightB, int heightA, int widthB) { int Row = blockIdx.y*blockDim.y+threadIdx.y;// Calculate the row index of the P element and M int Col = blockIdx.x*blockDim.x+threadIdx.x;// Calculate the column index of P and N if ((Row...
1,573
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand_kernel.h> #define CUDA_CALL(x) do { if((x) != cudaSuccess) { \ printf("Error at %s:%d\n",__FILE__,__LINE__); \ return EXIT_FAILURE;}} while(0) __global__ void setup_kernel(curandState *state) { int id = threadIdx.x + blockIdx.x * blockDim....
1,574
//seqCuda.cu #include<iostream> using namespace std; #include <thrust/reduce.h> #include <thrust/sequence.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> int main() { const int N=10000; thrust::device_vector<int> a(N); thrust::sequence(a.begin(), a.end(), 0); long sumA= thrust::r...
1,575
// C = alpha * A * B + beta * C __global__ void MatMulKernelAB(const int M,const int K,float *A, const int K1, const int N,float *B, const int M1, const int N1,float *C, const float alpha,const float beta) { // Each thread computes at most (UNROLL_X * UNROLL_Y) elements of C // by accumulatin...
1,576
/** * Demonstrates the use of a synchronisation construct * What to ponder: * - Significance of counter values printed out with/without syncthreads * - Why does the values vary when syncthreads is used in a kernel launch * containing multiple blocks? */ #include <stdio.h> __device__ __managed__ int volatile i...
1,577
#include "includes.h" __global__ void SynchStreams() { }
1,578
#include<stdio.h> #define H 1024 #define W 1024 __global__ void Matrix_add(int *a, int *b, int *c) { int x=blockIdx.x*blockDim.x+threadIdx.x; int y=blockIdx.y*blockDim.y+threadIdx.y; int sum=0; for(int k=0; k<W; k++) { int aa=a[y*W+k]; int bb=b[k*W+x]; sum+=aa*bb; } c[y*W+x]=sum; } int main(voi...
1,579
#include <iostream> #include <bits/stdc++.h> #include <fstream> #include <sstream> #include <string> #include "math.h" #include "limits.h" #define MIN -99 #define M 104 #define N 1500 #define trainFileName "train_full.csv" #define testFileName "test_full.csv" #define features 55 #define K 10 #define trainData(row,col)...
1,580
#include<math.h> #include<stdlib.h> #include<stdio.h> #include<string.h> #include<cuda.h> #include<time.h> //CUDA error wrapping #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { if (code != cudaSuccess) { ...
1,581
#include "includes.h" __global__ void Kogge_Stone_scan_kernel(float *X, float *Y, int InputSize) { __shared__ float XY[SECTION_SIZE]; int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < InputSize) { XY[threadIdx.x] = X[i]; } // Perform iterative scan on XY for (unsigned int stride = 1; stride < blockDim.x; stride ...
1,582
#include "includes.h" __device__ inline float sigmoid(float x) { return 1.0f / (1.0f + __expf(-x)); } __global__ void kApplySigmoid(float* mat, float* target, unsigned int len) { const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int numThreads = blockDim.x * gridDim.x; for (unsigned int i =...
1,583
#include "includes.h" __global__ void kTile(const float* src, float* tgt, const uint srcWidth, const uint srcHeight, const uint tgtWidth, const uint tgtHeight) { const int idx = blockIdx.x * blockDim.x + threadIdx.x; const int numThreads = blockDim.x * gridDim.x; // const unsigned int numEls = tgtWidth * tgtHeight; ...
1,584
#include<cuda_runtime.h> #include<device_launch_parameters.h> #include<cassert> #include<iostream> #include<stdio.h> using namespace std; __global__ void vectorAdd(int *a, int* b, int* c, int n) { int tid = (blockIdx.x * blockDim.x) + threadIdx.x; if(tid<n) { c[tid] = a[tid] + b[tid]; } } void verify_result(i...
1,585
#include <stdint.h> #define WARP_SIZE 32 // ------------------------------------------------------------------- // helper functions // ------------------------------------------------------------------- // Get largest memory address that is aligned to a warp worth of floats // and smaller than x. __forceinline__ __d...
1,586
#include <cuda.h> #include<stdio.h> __global__ void dd(int *d_a, int *d_b, int *d_c, int vec_size){ int tid= threadIdx.x+blockIdx.x*blockDim.x; if (tid<vec_size) d_c[tid]= d_a[tid] + d_b[tid]; } int main(int argc, char ** argv){ cudaSetDevice(3); int i, vec_size; int *h_a, *h_b, *h_c; int *d_a...
1,587
// NOTE: the meanings of x/y here are switched. // Code assumes dimensions are x, y, channels, samples. __global__ void pool_switches (unsigned int* idx, const float* data, const int pooledWidth, const int pooledHeight, const int pooledVolume, const int width, const int height, const int poolWidth, const int...
1,588
// Implement BFS on CUDA. // The graph is not weighted but it is directed. The BFS algorithms is same just have to change the graph to unwieghted. // Error handler was copied from Dr. Rama's colab file shared to us on google classroom #include<stdio.h> #include<stdlib.h> #include<time.h> #define HANDLE_ERROR( err )...
1,589
/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may...
1,590
#include<stdio.h> #include<cuda.h> #include<cuda_runtime.h> void print_matrix(float *A,int m,int n) { for(int i =0;i<m;i++) { for(int j=0;j<n;j++) printf("%.1f ",A[i*n+j]); printf("\n"); } } __global__ void swapReflect(float *input, float *output, int M, int N) { int j = t...
1,591
// Compile & run with // `nvcc histogram.cu` // `./a.out` #include <cstdio> #include <curand_kernel.h> // uniform integer distrigbution in CUDA: // https://stackoverflow.com/questions/43622482 // Fewer than 32 bins will take the same amount of time // because of the warp size. However, it is not possible // to conf...
1,592
#include <stdio.h> int main(void) { // Return info about the 0th device cudaDeviceProp deviceProperties; cudaGetDeviceProperties(&deviceProperties, 0); printf("Name: %s\n", deviceProperties.name); printf("Total mem: %luMB\n", deviceProperties.totalGlobalMem/1024/102...
1,593
/* symbol.cu */ /****************************************************************************/ /* */ /* (C) 2010 Texas Advanced Computing Center. */ /* ...
1,594
#include <stdio.h> #include <fstream> //#include <iostream> #include <string.h> //#include <vector> #include <stdlib.h> //#include <unistd.h> //#include <time.h> #include <cuda.h> //#include <mpi.h> #define uchar unsigned char // 8-bit byte #define uint unsigned int // 32-bit word //define for sha256 #define DBL_INT...
1,595
#include <stdio.h> const int N = 2048; __global__ void add_complex(int *a , int *b , int *c) { int tid = blockIdx.x * blockDim.x + threadIdx.x; while (tid < N) { c[tid] = a[tid] + b[tid]; tid += blockDim.x * gridDim.x; } } int main (void) { int a[N], b[N], c[N]; for ...
1,596
/* * CUDA version by chengbin hu U#60715820 * Date 06/20/2015 * */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> //#include <cuda.h> #include <cuda_runtime.h> #define BOX_SIZE 23000 /* size of the data box on one dimension */ /* descriptors for single atom in the tree */...
1,597
#include "includes.h" __global__ void computeHistogram(unsigned int *buffer, int size, unsigned int *histo ) { __shared__ unsigned int temp[1024]; temp[threadIdx.x + 0] = 0; temp[threadIdx.x + 256] = 0; temp[threadIdx.x + 512] = 0; temp[threadIdx.x + 768] = 0; __syncthreads(); int i = threadIdx.x + blockIdx.x * bloc...
1,598
#include <iostream> #include <vector> #define BLOCK_SIZE 256 #define KERNEL_SIZE 9 #define HALF_KERNEL_SIZE 4 __global__ void convolution_1d_x_shared_memory( float *const input_image, const int width, const int height, float* result) { // Save input image in shared memory __shared__ float...
1,599
#include <iostream> #define n 64 #define blockSize 16 #define size_partial_sum blockSize * 2 __global__ void sum_reducer1(int *d_data) { __shared__ int partialSum[size_partial_sum]; partialSum[threadIdx.x] = d_data[threadIdx.x + blockIdx.x * blockDim.x * 2]; partialSum[threadIdx.x + blockDim.x] = d_data[b...
1,600
/* Faz a soma dos elementos de dois vetores Exemplifica o uso de diferentes streams com cudaMallocHost para alocar memoria no host nao paginavel e copia assincrona com cudaMemcpyAsync. Usa tambem o cudaStreamSynchronize para aguardar toda a stream terminar. O algoritmo divide "tam" elementos por "streams_nr" e encon...