serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
23,801
/*========================================================================== MD5 KERNEL * Copyright (c) 2008, NetSysLab at the University of British Columbia * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provi...
23,802
#include <iostream> #include <memory> #include <cassert> using namespace std; #include <cuda.h> __global__ void getValue(float4 *outdata, float *indata) { // outdata[0] = indata[0]; float4 my4 = make_float4(indata[0], indata[3], indata[1], indata[2]); outdata[0] = my4; } int main(int argc, char *argv[]...
23,803
void TestCpuFunctions() { }
23,804
__global__ void Sample1Kernel(float *d_A, float *d_B, float *d_C) { // Step 1. 自身のCUDAスレッドIDを計算する int thread_id = blockDim.x * blockIdx.x + threadIdx.x; // Step 2. CUDAスレッドIDを用いてグローバルメモリからデータを読み込み,計算する d_C[thread_id] = d_A[thread_id] + d_B[thread_id]; }
23,805
#define EIGEN_USE_GPU #include <cuda.h> #include <stdio.h> __global__ void UntruncCovKernel( const double* incr, const int nb_incr, const int paths_length, const int paths_length_, const int nb_diagonals, double* pdes_sol) { unsigned int p = blockIdx.x; unsigned int idx = threadIdx.x; for (int ...
23,806
#include <stdio.h> __global__ void helloFromGPU(void){ printf("hello world from gpu!\n"); } int main(void){ // hello from cpu printf("hello from cpu!\n"); // 1 thread block and 10 threads helloFromGPU <<<1,10>>>(); cudaDeviceReset(); return 0; }
23,807
/************************************************************************************************************* * FILE: lakegpu_mpi.cu * * AUTHORS: attiffan Aurora T. Tiffany-Davis * ssbehera Subhendu S. Behera * wpmoore2 Wade P. Moore * * DESCRIPTION:...
23,808
//#include"cuda_helper.cuh" // //#include"npp.h" //#include"nppcore.h" //#include"nppdefs.h" //#include"nppi.h" //#include"npps.h" //#include"nppversion.h" //#define NPP_CALL(x){const NppStatus a=(x);if (a!=NPP_SUCCESS){printf("\nNPP Error(err_num=%d) \n", a);cudaDeviceReset();ASSERT(0);}} // //#define NUM_STREAMS 4 /...
23,809
__global__ void saxpy_kernel(int n, float a, float *x, float *y) { int i = blockDim.x * blockIdx.x + threadIdx.x; if ( i < n ) y[i] += a * x[i]; } extern "C" void saxpy(int n ,float a, float *x, float *y) { dim3 griddim, blockdim; blockdim = dim3(128,1,1); griddim = dim3(n/blockdim.x,1,1); saxpy_kern...
23,810
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #define BLOCK_SIZE 1024 // You can change this //#define NUM_OF_ELEMS 1e6 // You can change this __global__ void total(float * input, float * output, int len) { int tid_x = blockIdx.x * blockDim.x + threadIdx.x ; int tid_y...
23,811
/* Monte Carlo simulation of the Ising model using CUDA */ /* Author: Jorge Fernandez de Cossio Diaz */ /* March, 2019 */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <cassert> #include <cuda.h> #include <curand_kernel.h> //#include <curand.h> #define RANDSEED 5 // random seed /* Linear dimens...
23,812
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <unistd.h> #define THREADS 1024 __global__ void kernel(struct cudaPitchedPtr pitchedPointer){ int id; float *d; id = blockDim.x*blockIdx.x + threadIdx.x; d = (float*)pitchedPointer.ptr; d[id] += 1.0f; } int main(){ int i,ite ...
23,813
#include <stdio.h> #include <cuda.h> #define N 500 #define BLOCKSIZE 64 #define ELEPERTHREAD 20 __device__ const unsigned delta = ELEPERTHREAD / 5; __global__ void k1(unsigned *nelements) { unsigned id = blockIdx.x * blockDim.x + threadIdx.x; __shared__ unsigned sum; __shared__ unsigned avg; __shared__ unsigne...
23,814
#include "median_tree_node.cuh"
23,815
#include "includes.h" __global__ void Histogram_kernel(int size, int bins, int cpu_bins, unsigned int *data, unsigned int *histo) { extern __shared__ unsigned int l_mem[]; unsigned int* l_histo = l_mem; // Block and thread index const int bx = blockIdx.x; const int tx = threadIdx.x; const int bD = blockDim.x; const i...
23,816
#include "includes.h" __global__ void render_final(float *points3d_polar, float * selection, float * depth_render, int * img, int * render, int oh, int ow) { int x = blockIdx.x * TILE_DIM + threadIdx.x; int y = blockIdx.y * TILE_DIM + threadIdx.y; int w = gridDim.x * TILE_DIM; int h = w /2; int maxsize = oh * ow; for...
23,817
/************************************************************************ Source Code : vectorModel.cu Program : GPU as SIMD Processor using Vector Programming model Objective : To demonstrate that better bandwidth can be achieved if e...
23,818
#include "includes.h" /* * PARA CORRERLO: * $ export LD_LIBRARY_PATH=/usr/local/cuda/lib * $ export PATH=$PATH:/usr/local/cuda/bin * $ nvcc -o matrixTrans matrixTrans.cu -O2 -lc -lm * $ ./matrixTrans n */ /* * UNSIGNED INT --> Tipo de dato para enteros, números sin punto decimal. * Los enteros...
23,819
#include "includes.h" __global__ void gpu_find_vac( const int num_atoms, const int correlation_step, const int num_correlation_steps, const float* g_vx, const float* g_vy, const float* g_vz, const float* g_vx_all, const float* g_vy_all, const float* g_vz_all, float* g_vac_x, float* g_vac_y, float* g_vac_z) { const int ...
23,820
#include <stdio.h> #include <iostream> #include <cuda.h> #include <time.h> using namespace std; //prodotto puntuale tra 2 matrici, usando il padding di memoria (pitch) //input size matrici (m,n) , dimensioni blocchi (righe di thread, colonne di thread) __host__ void inizializzaCPU(int *a,int m,int n){ srand((unsig...
23,821
#include <stdio.h> #define n 1024 #define NUMTHREADS 256 __global__ void histogram_kernel(unsigned int *data, unsigned int *bin) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { atomicAdd(&(bin[data[i]]), 1); } } int main(int argc, char *argv[]) { int i; int size = n * sizeof(in...
23,822
#include <iostream> #include <chrono> #include <vector> #include<curand_kernel.h> using namespace std; #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true){ if (code != cudaSuccess) { fprintf(stderr,"GPUassert: %...
23,823
__device__ int N; __global__ void set_N(int n) { N = n; } __global__ void dev_add(int *a, int *b, int *c) { int id = blockIdx.x; if (id < N) c[id] = a[id] + b[id]; } void add(int a[], int b[], int c[], int n) { int *dev_a, *dev_b, *dev_c; set_N<<<1, 1>>>(n); cudaMalloc(&dev_a, n * sizeof(int)); cudaMalloc(&...
23,824
/* threads and blocks. * for blocks = 2, threads = 4: * a = [0,1,2,3 | 0,1,2,3] * index = threadIdx.x + blockIdx.x * threads * = [0,1,2,3 | 4,5,6,7] */ #include <stdio.h> /* this kernel uses threads and blocks. the width of a block * (number of threads per block) can be accessed with the * built in variable ...
23,825
#include <stdio.h> #include <math.h> #include <time.h> #include <unistd.h> #include <cuda_runtime_api.h> #include <errno.h> #include <unistd.h> /****************************************************************************** * The variable names and the function names of this program is same as provided by the univers...
23,826
#include<stdio.h> #include<math.h> #define SIZE 1024 __global__ void max(int * A, int * C) { int i=blockIdx.x*blockDim.x+threadIdx.x; A[2*i] < A[2*i+1]?C[i]=A[2*i]:C[i]=A[2*i+1]; } int main() { int A[SIZE]; int *devA,*devC; for(int j=0;j<SIZE;j++) { A[j]=...
23,827
// Cudafy1.Program extern "C" __global__ void thekernel(); // Cudafy1.Program extern "C" __global__ void thekernel() { }
23,828
#include "myqueue.cuh" #include <iostream> using namespace std; template<class T> MyQueue<T>::MyQueue() : frontPtr(NULL), backPtr(NULL), count(0) { } template<class T> __device__ __host__ bool MyQueue<T>::isEmpty() { return(count == 0); } template<class T> __device__ __host__ void MyQueue<T>::push(T data) { Node *...
23,829
/* Block size X: 32 */ __global__ void fct_ale_b1_vertical(const int maxLevels, const int * __restrict__ nLevels, const double * __restrict__ fct_adf_v, double * __restrict__ fct_plus, double * __restrict__ fct_minus) { const int node = (blockIdx.x * maxLevels); for ( int level = threadIdx.x; level < nLevels[blockIdx....
23,830
#include <stdio.h> __global__ void VecAdd(double* A, double* B, double* C, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) C[i] = A[i] + B[i]; } #define N 10000 int main() { double a[N]; double b[N]; double c[N]; int i; for (i = 0; i < N; ++i) { a[i] = 3.0*(double)i - 11.4; ...
23,831
#include <iostream> #include <math.h> #define THREADS_PER_BLOCK 1024 __global__ void add(int n, float *x, float *y) { int i = THREADS_PER_BLOCK * blockIdx.x + threadIdx.x; if (i < n){ y[i] += x[i]; } } int main(void) { int N = 1 << 20; // N = 2^20 = 1024*1024= 1.048.576 int N_bloc...
23,832
#include "includes.h" __global__ void sumaVectores (float * d_a, float *d_b, float * d_c) { int index = blockIdx.x*blockDim.x+threadIdx.x; if (index < N ) d_c[index] = d_a[index] +d_b[index]; }
23,833
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #define MAXPOINTS 1000000 #define MAXSTEPS 1000000 #define MINPOINTS 20 #define PI 3.14159265 void check_param(void); void printfinal(void); int nsteps, tpoints; float values[MAXPOINTS+2]; void check_param(void) { char tchar[20]; while ((...
23,834
#include <math.h> #include <iostream> #include <cuda_runtime.h> #include <stdlib.h> #include <cstdio> using namespace std; #define SIZE 1024 * 1024 const int N = 1024; float h_A[SIZE]; float h_B[SIZE]; float h_C[SIZE]; __global__ void matrixMultiplicationKernel(float* A, float* B, float* C, int N) { int row = ...
23,835
#include <iostream> #include <unistd.h> #include <stdlib.h> #include "cuda.h" using namespace std; __global__ void infinitekernel(float *dptr, int *dwait) { while(*dwait) *dptr += 1; *dptr = 999; } int main(void) { cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaStream_t stream...
23,836
#include "includes.h" __global__ void MatMulInt(int *a, int b, int *c,int ROW, int COLUMNS){ int ix = blockIdx.x * blockDim.x + threadIdx.x; int iy = blockIdx.y * blockDim.y + threadIdx.y; int idx = iy * COLUMNS + ix; if (ix < ROW && iy < COLUMNS) { c[idx] = a[idx] * b ; } }
23,837
__global__ void kernel_forwardDVF(float *mx, float *my, float *mz, cudaTextureObject_t alpha_x, cudaTextureObject_t alpha_y, cudaTextureObject_t alpha_z, cudaTextureObject_t beta_x, cudaTextureObject_t beta_y, cudaTextureObject_t beta_z, float volume, float flow, int nx, int ny, int nz) { int ix = 16 * blockIdx.x +...
23,838
#include <stdio.h> __global__ void test(char* a, int* b) { a[threadIdx.x] += b[threadIdx.x]; } int main() { int dec[7] = {1, 1, 1, 1, 1, 1, 0}; char str[7] = "Hello "; printf("%s", str); int* cuda_mem_int; char* cuda_mem_str; cudaMalloc((void**)&cuda_mem_str, sizeof(str)); cudaMalloc((void**)&cuda_mem...
23,839
// solveBCs.cu // //This file contains the function used solve for the boundary conditions of a pendulum //Included Files #include <iostream> //Function Prototypes // Functions found in Functs.cu void matmult61(double A[6][6], double B[6], double C[6]); //solve_BCs: // Function used to solve for the acceleration an...
23,840
#include <stdio.h> #include <cuda.h> #include <stdlib.h> #include <unistd.h> __global__ void add(int *a, int *b, int *c){ c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x]; } #define N 512*512*1024 int random_ints(int *p, int n){ int i; for(i=0;i<n;i++) *p++ = rand(); return 0; } int main(){ int *a, *b, *c; int...
23,841
__global__ void calc_dd_coeff( const double dx, const double dy, const double dz, const double * __restrict__ eta, const double * __restrict__ xi, double * __restrict__ dd_i, double * __restrict__ dd_j, double * __restrict__ dd_k ) { size_t a = blockIdx.x * blockDim.x + threadId...
23,842
/* Program to compute Pi using Monte Carlo methods */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <curand_kernel.h> #define SEED 35791246 __global__ void getcount(int *count_dev) { int idx = blockIdx.x * blockDim.x + threadIdx.x; double x, y, z; //init random number seed by taking clock...
23,843
#include <cuda.h> #include <stdio.h> #include <time.h> #include <iostream> #include <fstream> #include <string> #include <vector> __global__ void printMatrix(float **d_matrix, int size) { int i = (blockIdx.x * blockDim.x) + threadIdx.x; int j = (blockIdx.y * blockDim.y) + threadIdx.y; if (i < size && i >= ...
23,844
#include <stdio.h> #include <cuda_runtime.h> #include <cuda.h> #include <stdlib.h> #define N 5 __global__ void add(int *a, int *b, int *c) { *c += a[threadIdx.x] * b[threadIdx.x]; } void print_five(int* array){ for(int i=0; i<5; ++i){ printf("%d ", array[i]); } printf("\n"); } void random_ints(int *a, int n){...
23,845
#include "includes.h" __global__ void initialize_cells(CellT* dev_cells, CellT* dev_next_cells, int size_x, int size_y) { for (int i = threadIdx.x + blockDim.x * blockIdx.x; i < size_x*size_y; i += blockDim.x * gridDim.x) { dev_cells[i] = 0; dev_next_cells[i] = 0; } }
23,846
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #define THREADS_PER_BLOCK 512 float *CPU_big_dot(float *A, float *B, int N); float *GPU_big_dot(float *A, float *B, int N); __global__ void multiply(float *a, float *b, float *results, int *N); /* Helper functions */ float *random(int N)...
23,847
// Codigo serial para resolver la ecuacion de difusion en 2D // #include <iostream> #include <fstream> #include <cmath> #include <stdio.h> #include <sys/time.h> double get_time() { struct timeval tim; gettimeofday(&tim, NULL); return (double) tim.tv_sec+(tim.tv_usec/1000000.0); } void update (float *u, float *...
23,848
#include <stdio.h> // Kernel definition //adds two vectors A and B of size N and stores the result into vector C: __global__ void VecAdd(float* A, float* B, float *C) { int i = threadIdx.x; C[i] = A[i] + B[i] ; } int main() { // here only 1024 is the maximum number i can use for carrying out the // ...
23,849
# include <stdio.h> # include <math.h> # include <sys/time.h> # define N 1000000 # define RADIUS 100 # define THREADS 32 __global__ void QuarterAreaOfCircle ( float *area , float *start, float *end){ //int i = blockDim.x*blockIdx.x+threadIdx.x; int i = 0; float threadStartX; float x, dx; float segme...
23,850
#include "includes.h" __global__ void matrixTriUpper(float *a, int m, int n) { //setting matricies to their upper bound for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { if(i>j) a[i*n + j] = 0; a[i*n + j] = a[i*n + j]; } } }
23,851
#include "includes.h" __global__ void matrixMul(int *a, int *b, int *c, int n, int tile_size){ __shared__ int A[SHMEM_SIZE]; __shared__ int B[SHMEM_SIZE]; int tx = threadIdx.x; int ty = threadIdx.y; int bx = blockIdx.x; int by = blockIdx.y; int row = by * tile_size + ty; int col = bx * tile_size + tx; int temp_sum =...
23,852
/** * Name : Veerakumar Natarajan * Student Id: 200208042 * * 2d convolution program */ #include <stdio.h> #include <fstream> #include <sstream> #include <stdlib.h> // For the CUDA runtime routines (prefixed with "cuda_") #include <cuda_runtime.h> /** * CUDA Kernel Device code * * Computes the 2d convolution...
23,853
__global__ void gpu_KIDepthToVertices(const float *depthIn, float4 * vertOut, int *segMap, const int width, const int height, const float2 pp, ...
23,854
/* NiuTrans.Tensor - an open-source tensor library * Copyright (C) 2017, Natural Language Processing Lab, Northeastern University. * All rights reserved. * * 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 o...
23,855
#include<stdio.h> #define BLOCK_DIM 25 #define N 25 __global__ void matadd(int *a, int *b, int *c) { int col=blockIdx.x*blockDim.x+threadIdx.x; int row=blockIdx.y*blockDim.y+threadIdx.y; int index = col + row*N; if(col<N && row<N){ c[index]=a[index]+b[index]; } } int main(void) { int a[N][N],b[N][N],c[N][N]; ...
23,856
#include "includes.h" __global__ void reprojectPoint(double *d_N, int nRxns, int istart, double *d_umat, double *points, int pointsPerFile, int pointCount, int index){ int newindex = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; for(int i=newindex;i<nRxns-istart;i+=stride){ d_umat[nRxns*i...
23,857
extern "C" __device__ __forceinline__ float sigmoid_f(float x) { return 1.0 / (1 + exp(-x)); } extern "C" __device__ __forceinline__ float training_q_fwd(const float log_alpha, const float beta, const float gamma, const float zeta) { return sigmoid_f(log_alpha - beta * (-gamma / zeta)); } extern "C" __device_...
23,858
#include "includes.h" // Kind of lame, but just put static file-level variables here for now. // Pointer to device results array. float * dev_result = 0; // Pointer to device data array. float * dev_data = 0; // Size of data/result sets (i.e. number of entries in array). unsigned int testArraySize = 0; // GPU func...
23,859
#include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #include <math.h> extern "C" __global__ void mandelbrot_ker(float* lattice, float* mandelbrot_graph, int max_iters, float upper_bound_squared, int lattice_size) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if (tid < lattice_size * lattice_s...
23,860
/* * Copyright 2014 NVIDIA 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 law ...
23,861
#define TPB2D 8 __global__ void ldc_D3Q15_LBGK_ts(float * fOut, const float * fIn, const int * snl, const int * lnl, const float u_bc, const float omega,const float * ex, const float * ey, const float * ez, const float * w, const int Nx, const int Ny, const int Nz){ int X=threa...
23,862
using Point = double3; struct Ref { Point* pos; Point* dir; double* distance; }; struct View { int size; Point* pos; Point* dir; double* distance; __device__ Ref operator[](int i) const { return {pos + i, dir + i, distance + i}; } }; __device__ inline void move_impl(const Ref& ref) { const d...
23,863
// // main.c // qr // // Created by Zia Ul-Huda on 21/11/2016. // Copyright © 2016 TU Darmstadt. All rights reserved. // #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <time.h> #include <sys/time.h> #define CUDA_ERROR_CHECK #define CudaSafeCall( err ) __cudaSafeCall( err, _...
23,864
#pragma once #include <cuda_runtime.h> #include <cuda.h> #include <iostream> #include <vector> #include <string> #include <stdexcept> template<typename T> void check(T err, const char* const func, const char* const file, const int line) { if (err != cudaSuccess) { throw std::runtime_error( ...
23,865
#include<thrust/host_vector.h> #include<thrust/device_vector.h> #include<thrust/generate.h> #include<thrust/sort.h> #include<thrust/copy.h> #include<cstdlib> int main() { thrust::host_vector<int> H(22); thrust::generate(H.begin(), H.end(), rand); thrust::device_vector<int> D = H; thrust::sort(D.begin()...
23,866
/* Solution of the Laplace equation for heat conduction in a square plate */ #include <iostream> // global variables const int NX = 1024; // mesh size (number of node points along X) const int NY = 1024; // mesh size (number of node points along Y) const int MAX_ITER=1000; // number of Jacobi iteration...
23,867
//xfail:BUGLE_ERROR //--gridDim=1 --blockDim=2 --no-inline //This kernel is racy. However, variable-length memcpys are not supported. //Expect error at Bugle stage. #define memcpy(dst, src, len) __builtin_memcpy(dst, src, len) typedef struct { short x; short y; char z; } s_t; //< sizeof(s_t) == 6 __global__ v...
23,868
#include "includes.h" __global__ void next_move_hub_kernel(int* hub, int nhub, int *rat_count, int *healthy_rat_count, int *exposed_rat_count, int *infectious_rat_count, double *node_weight, double *sum_weight_result,int *neighbor, int *neighbor_start, int width, int height, double batch_fraction){ int x = blockIdx.x ...
23,869
#include <stdio.h> #include <math.h> #include <iostream> static void HandleError( 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 ); } } #define HANDLE_ERROR( err ) (HandleErro...
23,870
// tdfc-cuda backend autocompiled body file // tdfc version 1.160 // Thu May 26 16:38:16 2011 #include <stdio.h> __global__ void tdfc_rot(float cc_c,float cc_s,float* cc_x,float* cc_y,float* cc_x_out,float* cc_y_out,int N ) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx<N) { { ...
23,871
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <assert.h> void synchronizeAndCheckReturnStatus() { cudaThreadSynchronize(); cudaError_t status = cudaGetLastError(); if (status != cudaSuccess) { printf("return status: %s\n", cudaGetErrorString(status)); exit(0); } } int main()...
23,872
/* hello CUDA kernels * Arguments: * char *a - an array of characters * Purpose: * Each CUDA thread calculates an index value and increments * its portion of the array by the value of its index. */ /* hello_block * This kernel works when called with * multiple thread blocks, each using * a single threa...
23,873
// CUDA sample // simple grid-stride #include <stdio.h> #include <cstdlib> void init(int *a, int N) { int i; for (i = 0; i < N; ++i) { a[i] = i; } } __global__ void doubleElementsStride(int *a, int N) { /* * Use a grid-stride loop so each thread does work * on more than one element in the array...
23,874
#include <stdio.h> void GetDeviceProperties(struct cudaDeviceProp *prop) { cudaError_t e; int device; device = 0; e = cudaGetDeviceProperties (prop, device); if (e != cudaSuccess) { fprintf(stderr, "GetDeviceProperties failed\n"); exit(2); } } int main() { cudaDeviceProp p;...
23,875
#include <iostream> static __global__ void kernel(const float *A, const float *b) { } int main(int argc, char** argv) { float *d_a, *d_b; if(cudaMalloc(&d_a, sizeof(float)) != cudaSuccess) { std::cout << "cudaMalloc d_a failed" << std::endl; return 1; } if(cudaMalloc(&d_b, sizeof(float)) != c...
23,876
#include <thrust/device_vector.h> #include <thrust/reduce.h> #include <thrust/random.h> #include <thrust/sort.h> #include <thrust/unique.h> #include <thrust/equal.h> using namespace thrust::placeholders; /*************************************/ /* CONVERT LINEAR INDEX TO ROW INDEX */ /*********************************...
23,877
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #define Mask_Width 101 #define TILE_WIDTH 1000 __constant__ int M[Mask_Width]; __global__ void Convolution1D_kernel(int *N, int *P, int n) { int i = blockIdx.x*blockDim.x + threadIdx.x; int j; int PValue = 0; int N_...
23,878
#include <cuda_runtime.h> #include <stdio.h> __global__ void HelloFromGPU(void) { printf("hello from GPU\n"); return; } void HelloFromCPU(void) { printf("hello from CPU\n"); return; } int main (void) { HelloFromCPU(); HelloFromGPU<<<2, 5>>>(); HelloFromCPU(); return 0; }
23,879
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <curand_kernel.h> #include <cstdio> #include <cassert> #define check_cuda_call(ans) { _check((ans), __FILE__, __LINE__); } inline void _check(cudaError_t code, char *file, int line) { if (code != cudaSuccess) { fprintf(stderr,"CUDA Error:...
23,880
#include<iostream> #include<cuda.h> using namespace std; #define N 10 __global__ void add(int *a,int *b,int *c){ int tid=threadIdx.x; if(tid<N) c[tid]=a[tid]+b[tid]; } int main(){ int a[N],b[N],c[N]; int *dev_a,*dev_b,*dev_c; cudaMalloc(&dev_a,N*sizeof(int)); cudaMalloc(&dev_b,N*sizeof(i...
23,881
#include <stdio.h> #include <stdlib.h> int main() { unsigned int N = 450000000; unsigned int bytes = N*sizeof(double); // Host Initialization double *h_a; h_a = (double*)malloc(bytes); for (unsigned int i=0; i<N; i++) h_a[i] = 2.0f; // Device Initialization double *d_a; cudaMalloc(&d_a, bytes); // Event...
23,882
/* Ray-Triangle Intersection Test Routines */ /* Different optimizations of my and Ben Trumbore's */ /* code from journals of graphics tools (JGT) */ /* http://www.acm.org/jgt/ */ /* by Tomas Moller, May 2000 */ #include <math.h> #include <iostream> #inclu...
23,883
////12163291 ˰򼳰 HW1 //#pragma warning(disable: 4819) // // //#include<stdio.h> //#include<iostream> //#include <cuda_runtime.h> //#include <cuda.h> //#include <time.h> //for //#include <math.h> // //using namespace std; // //#define DATASIZE 1048576 //2048 131072 262144 1048576 ȵƴµ ÷ο ִ //#define BLOCK_SIZE 2048...
23,884
#include <stdio.h> #include <vector> // CUDA device kernel ...
23,885
#include <stdio.h> #include <iostream> #include <unistd.h> #include <sys/time.h> // Shorthand for formatting and printing usage options to stderr #define fpe(msg) fprintf(stderr, "\t%s\n", msg); // Shorthand for handling CUDA errors. #define HANDLE_ERROR(err) ( HandleError( err, __FILE__, __LINE__ ) ) using namespa...
23,886
#include "includes.h" __global__ void max_pool3d_backward(int B, int N, int M, int C, const int* maxIndex, const float* gradOutput, float* gradInput) { for(int i=blockIdx.x;i<B;i+=gridDim.x) { for(int j=threadIdx.x;j<M*C;j+=blockDim.x) { int c = j%C; int n = maxIndex[i*M*C+j]; atomicAdd(&gradInput[i*N*C+n*C+c],gradOutp...
23,887
#include <stdio.h> #include <cuda.h> #define TILE_DIM 16 __global__ void multMats(float * A, float * B, float * C, int m, int n, int k) { //Create 2 tiles for matrix A and B at the shared memory __shared__ float ATile[TILE_DIM][TILE_DIM]; __shared__ float BTile[TILE_DIM][TILE_DIM]; int row = blockIdx....
23,888
//pass //--gridDim=1 --blockDim=2 --no-inline //This kernel is race-free. // //It uses uses memcpy and copies fewer bytes than the struct size so we have to //handle the arrays in and out at the byte-level. #define memcpy(dst, src, len) __builtin_memcpy(dst, src, len) typedef struct { short x; short y; char z;...
23,889
#include <stdio.h> #include <stdlib.h> #include <cuda.h> unsigned char *pdata; // pointer to data content void getInfo(int *width, int *height, int *dataOffset, int *pixLen) { FILE *f; if (NULL == (f = fopen("lena_color.bmp", "rb"))) { printf("Fail to open the file1"); exit(EXIT_FAILURE); ...
23,890
#include <stdio.h> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <iostream> #include <cuda.h> #include <cuda_runtime.h> __global__ void left_shift_kernel(int *a, const int N){ int idx = threadIdx.x; if (idx < N - 1){ int temp = a[idx + 1]; __syncthreads()...
23,891
#include "includes.h" __global__ void init_cs(int *d_cl, int *d_cs, int c_size, int chunk) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i >= c_size) { return; } if (i == 0) { d_cs[i] = 0; } else { d_cs[i] = d_cl[i - 1] * chunk; } }
23,892
// numInterior: (NfIn) // intrplWgts: (NfIn*maxK, 3) // input: (NfIn*maxK, C) // filter: (3, C, r) // output: (NfIn, C*r) __global__ void facet2facet_conv3d_forward(int NfIn, int C, int r, const int* numInterior, const float* intrplWgts, const float* input, ...
23,893
#include "includes.h" __global__ void calcSigmoidForwardGPU(float *in, float *out, int elements) { int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; if( id < elements ){ float v = in[id]; v = 1.0f / (1.0f + exp( -v )); // sigmoid out[id] = v; } /* original for ( int i = 0; i < in_total_size; ++i...
23,894
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/copy.h> #include <thrust/functional.h> #include <thrust/iterator/zip_iterator.h> #include <thrust/sequence.h> #include <iostream> #include <cstdlib> #include <ctime> #include <chrono> using namespace std; using sys_clock = std::chrono...
23,895
#include <iomanip> #include <iostream> using namespace std; // CUDA Kernel //Performs matrix multiplication A * B = Out //Note that aWidth must equal bHeight for the multiplication to succeed //Thus we have summarily done away with the latter to remove temptation //This kernel assumes that A is row major and B is col...
23,896
#include<iostream> #include<cuda.h> using namespace std; //这种__shared__其实没什么,就是一个block内的线程能够维护一个全局变量 #define imin(a,b) (a<b?a:b) const int N=33*1024; const int threadsPerBlock=256; const int blocksPerGrid=imin(32,(N+threadsPerBlock-1)/threadsPerBlock); __global__ void dot(float *a,float *b,float *c){ __shared__ flo...
23,897
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> // __device__ - GPU // __global__ - GPU // __host__ - CPU __global__ void add( int a, int b, int *c) { *c = a + b; } int main() { int c; int *dev_c; cudaMalloc( (void**)&dev_c, sizeof(int)); add<<<1,1>>> (1, 2, dev_c);...
23,898
#include <iostream> #include <math.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" // Kernel function to add the elements of two arrays __global__ void add(int n, float* x, float* y) { int index = threadIdx.x; int stride = blockDim.x; for (int i = index; i < n; i += stride) y[i] =...
23,899
/* helloCUDA.cu */ /****************************************************************************/ /* */ /* (C) 2010 Texas Advanced Computing Center. All rights reserved. */ /* ...
23,900
/* CPU code, still some bugs. */ //#include <cuda_runtime.h> //#include <vector> //#include <string> //#include <set> // //#include "load_obj.h" //#include "collision.cuh" //#include "check.cuh" //#include "./common/book.h" //#include "cpu.cuh" // //#define COL_MAX_LEN 1000000 // //void printElapsedTime(cudaEvent_...