serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
1,701
char *title = "Little's algorithm"; char *description = "Алгоритм Литтла - метод решения задачи коммивояжера"; /* Алгоритм Литтла применяют для поиска решения задачи коммивояжера в виде гамильтонова контура. Данный алгоритм используется для поиска оптимального гамильтонова контура в графе, имеющем N вершин, причем каж...
1,702
#include <iostream> #include <cuda.h> using namespace std; int *a, *b; // host data int *c, *c2; // results __global__ void vecAdd(int *A,int *B,int *C,int N) { int i = blockIdx.x * blockDim.x + threadIdx.x; C[i] = A[i] + B[i]; } void vecAdd_h(int *A1,int *B1, int *C1, int N) { for(int i=0;i<N;i++) ...
1,703
#include "includes.h" __global__ void PondHeadInit(double *ph, int size) { int tid = threadIdx.x + blockIdx.x * blockDim.x; while (tid < size) { ph[tid] = psi_min; tid += blockDim.x * gridDim.x; } }
1,704
#include "includes.h" __global__ void fsc_tomo_cmp_kernal(const float* data1, const float* data2, float* device_soln, const float data1threshold, const float data2threshold, const int nx, const int ny, const int nz, const int offset) { const uint x=threadIdx.x; const uint y=blockIdx.x; int idx = x + y*MAX_THREADS + o...
1,705
// 1 / (1 + e^(-x)) extern "C" __global__ void logistic(size_t n, double *result, double *x) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i<n) { result[i] = 1.0 / (1.0 + exp(-x[i])); } }
1,706
#include "includes.h" __global__ void profileSubphaseComputeRestriction_kernel() {}
1,707
#include<stdio.h> #include<iostream> using namespace std; int main() { int dCount; cudaGetDeviceCount(&dCount); for(int i=0; i<dCount+3; i++) { cudaDeviceProp prop; cudaError_t err = cudaGetDeviceProperties(&prop, i); if(err != cudaSuccess) cout<<"yes"<<endl; pr...
1,708
#include <cstdint> // Algorithm parameters. const double escape_radius = 2.5; const int max_iterations = 60; // Must be divisible by 3. const int blocks_size_x = 8; const int blocks_size_y = 10; const int threads_size_x = 32; const int threads_size_y = 32; typedef struct { uint8_t red; uint8_t green; uint...
1,709
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> void check(cudaError_t e) { if(e != cudaSuccess) { printf(cudaGetErrorString(e)); } } __global__ void addArrayGPU(int* a, int* b, int* c) { int i = threadIdx.x; c[i] = a[i] + b[i]; } int main() { const int ...
1,710
__global__ void init_kernel(int * domain, int pitch, int block_y_step) { /* 512 / 4 */ int blockXThreadSize = blockDim.x / block_y_step; int blockYThreadSize = blockDim.x / block_y_step / gridDim.y; int tx = threadIdx.x % blockDim.x; int ty = (blockIdx.y * blockDim.y) + thre...
1,711
#ifndef _GPU_CUDA_COMMON_CU__ #define _GPU_CUDA_COMMON_CU__ #include <stdio.h> namespace SiddhiGpu { __device__ bool cuda_strcmp(const char *s1, const char *s2) { // if(!s1 || !s2) return false; TODO: uncomment for ( ; *s1==*s2; ++s1, ++s2) { if (*s1=='\0') return true; } return false; } __device__ bool cuda_...
1,712
/* ============================================================================ Name : juliaset.cu Author : Wolfgang Version : Copyright : Your copyright notice Description : CUDA compute reciprocals ============================================================================ */ #include <ios...
1,713
// O(N) operations #include <stdio.h> #include <iostream> using namespace std; #define CHECK(call) \ { \ const cudaError_t error = call; \ if (error != cudaSuccess...
1,714
// // Created by heidies on 7/5/18. // #include <cuda_runtime.h> #include <iostream> using namespace std; int main(int argc, char **argv){ cout << "Starting... " << endl; int deviceCount = 0; cudaError_t error_id = cudaGetDeviceCount(&deviceCount); if (error_id != cudaSuccess){ cout << "cud...
1,715
#include "includes.h" __global__ void sortKernelSimple(int *arr, int arr_len, int odd) { int i = 2 * (blockIdx.x * blockDim.x + threadIdx.x) + odd; if (i < arr_len - 1) { //Even int a = arr[i]; int b = arr[i + 1]; if (a > b) { arr[i] = b; arr[i + 1] = a; } } }
1,716
#include <iostream> #include <cuda_runtime.h> // CUDA routines prefixed with cuda_ #include <stdio.h> #include <time.h> // time() for timing functions // cuda_runtime.h includes // stdlib.h -> rand(), RAND_MAX, malloc, calloc EXIT_FAILURE, EXIT_SUCCESS, exit() (among others) // Add two equally-sized vectors (1D) elem...
1,717
#include <stdio.h> /* * Scopo: somma due interi * * Tasks: * * Uso di un kernel * * allocazione delle memoria GPU * * Trasferimento di un intero dalla GPU al processore */ // Attenzione a questa parola chiave. Definisce un kernel, ovvero un processo che avviene // sulla GPU __global__ void dark(void) { // ...
1,718
//////////////////////////////////////////////////////////////////////////// // Calculate scalar products of VectorN vectors of ElementN elements on CPU. // Straight accumulation in double precision. //////////////////////////////////////////////////////////////////////////// #include <iostream> void Kernel_1_Max_CP...
1,719
#include <stdint.h> // Galois field multiplication // From Wikipedia __device__ uint8_t gmul( uint8_t a, uint8_t b ) { uint8_t p = 0; uint8_t counter; uint8_t hi_bit_set; for(counter = 0; counter < 8; counter++) { if(b & 1) p ^= a; hi_bit_set = (a & 0x80); a <<= 1; if(hi_bit_set) a ^= 0x1b; /* x^8 ...
1,720
// Author: Ayush Kumar // Roll No: 170195 // Compile: nvcc -g -G -arch=sm_61 -std=c++11 assignment5-p5.cu -o assignment5-p5 #include <cmath> #include <cstdlib> #include <cuda.h> #include <iostream> #include <sys/time.h> const uint64_t N = (256); #define BLOCK_SIZE_X 32 #define BLOCK_SIZE_Y 8 #define BLOCK_SIZE_Z 4 #d...
1,721
#include<stdio.h> #include<cuda_runtime.h> #include<device_launch_parameters.h> __global__ void add(int *A, int *B, int *C, int ha, int wa, int wb) { // Get the 1D Array index of the matrix int id = threadIdx.x; int sum; for (int i = 0; i < ha; ++i) { sum = 0; for (int j = 0; j < wa; ++...
1,722
#include "includes.h" __global__ void arrayOf2DConditions ( const int dim, const int nwl, const float *bn, const float *xx, float *cc ) { int i = threadIdx.x + blockDim.x * blockIdx.x; int j = threadIdx.y + blockDim.y * blockIdx.y; int t = i + j * dim; if ( i < dim && j < nwl ) { cc[t] = ( bn[0+i*2] < xx[t] ) * ( xx[t]...
1,723
#include <cuda.h> #include <cuda_runtime_api.h> #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <stdlib.h> //#define N 4 #define BLOCK_SIZE 4 #define GRID_SIZE 2 using namespace std; __device__ volatile int g_mutex; void cuda_error_check(cudaError_t err , const char *msg ) ...
1,724
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda.h> #include <sys/time.h> #define SIZE 102400 #define MOD 102399 #define STEP 128 /* ARRAY A INITIALIZER */ void init_a(int * a) { int i; for(i=0; i<SIZE; i++) { a[i] = 1; } } /* ARRAY B INITIALIZER */ void init_b(int * ...
1,725
#include<stdio.h> #include<cuda.h> #define N 1024 #define BLOCKSIZE 64 __device__ volatile unsigned k2counter; // try removing volatile: the code may hang. __global__ void K2init() { k2counter = 0; } __global__ void K2() { unsigned id = blockDim.x * blockIdx.x + threadIdx.x; printf("This is before: %d\n", id);...
1,726
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<iostream> #include<limits.h> #include<algorithm> #include<sys/time.h> using namespace std; #define INF INT_MAX-1 #define NS 1024 int m; int rowSize; int tilesize[3] = {2, 2, INT_MAX}; void print_matrix(float *d) { int i,j; for(i=0;i<32;i++) { ...
1,727
// example of using CUDA streams #include <stdio.h> #include <stdlib.h> #include <iostream> #include <chrono> using namespace std::chrono; __global__ void initWith(float num, float *a, int N) { int index = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; for(int i = index; i < N; i ...
1,728
#include<stdio.h> #include<time.h> #include<time.h> #include<stdlib.h> #include<math.h> __global__ void func1(int *c,int *a,int *b,int n) { int i = blockIdx.x*blockDim.x + threadIdx.x; if(i < n) { a[i] = 2 * i; b[i] = 3 * i; } } __global__ void func2(int *c,int *a,int *b,int n) { int i = blockIdx.x*blockDim.x + ...
1,729
#include "includes.h" __global__ void GenerateRandoms(int size, int iterations, unsigned int *randoms, unsigned int *seeds) { int idx = blockIdx.x * blockDim.x + threadIdx.x; unsigned int z = seeds[idx]; int offset = idx; int step = 32768; for (int i = 0; i < iterations; i++) { if (offset < size) { unsigned int b = ((...
1,730
//fonte: https://github.com/carloschilazo/CUDA_GA/blob/master/program.cu #include <iostream> #include <cstdlib> #include <stdio.h> #include <cuda.h> #include <time.h> using namespace std; /* Cannot use built-in functions, need to rewrite pow function so it can run on the device, kinda reinventing the wheel over he...
1,731
#include "includes.h" __global__ void empty() {}
1,732
#include <cuda_runtime.h> #include <thrust/device_ptr.h> #include <thrust/sort.h> extern void sort_uint_internal(void* dev_ptr, unsigned numElements, void* output_ptr) { if(output_ptr) { cudaMemcpy(output_ptr, dev_ptr, numElements * sizeof(unsigned), cudaMemcpyDeviceToDevice); } else { output_ptr = dev_ptr; } ...
1,733
#include "includes.h" __global__ void kSigmoid(const int nThreads, float const *input, float *output){ /* Computes the value of the sigmoid function f(x) = 1/(1 + e^-x). Inputs: input: array output: array, the results of the computation are to be stored here */ for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < ...
1,734
// Elapsed Real Time for input-4.txt: 1.381 seconds #include <stdio.h> #include <stdbool.h> #include <cuda_runtime.h> // Size of the square we're looking for. #define SQUARE_WIDTH 6 #define SQUARE_HEIGHT 6 // Maximum width of a row. Makes it easier to allocate the whole // grid contiguously. #define MAX_WIDTH 16384...
1,735
//Vector Addition using CUDA. //Winter 2020 //High Performance Computing. #include <string> //For stoi. #include <iostream> //For stdout. #include <cstdlib> //For random number generator. #include <chrono> ...
1,736
#include "includes.h" __global__ void kDot(const int nThreads, const float *m1, const float *m2, float *output, const int m1_rows , const int m1_columns, const int m2_columns ){ /* Computes the product of two matrices: m1 x m2. Inputs: m1: array, left matrix of size m1_rows x m1_columns m2: array, right matrix of size...
1,737
#include <cuda_runtime.h> #include <stdio.h> __global__ void doublevector(int* vec, int N) { int idx = (blockIdx.x * blockDim.x) + threadIdx.x; if (idx < N) { vec[idx] *= 2; } } __global__ void init(int* vec, int N) { int idx = (blockIdx.x * blockDim.x) + threadIdx.x; if (idx < N) { ...
1,738
#include "includes.h" __global__ void DrawObstacles(uchar4 *ptr, int* indices, int size) { int thread_id = threadIdx.x + blockIdx.x * blockDim.x; while (thread_id < size) { int index = indices[thread_id]; ptr[index].x = 0; ptr[index].y = 0; ptr[index].z = 0; ptr[index].w = 255; thread_id += blockDim.x * gridDim.x; }...
1,739
#include "includes.h" /* ================================================================== Programmers: Kevin Wagner Elijah Malaby John Casey Omptimizing SDH histograms for input larger then global memory ================================================================== */ #define BOX_SIZE 23000 /* size of the da...
1,740
#include<cuda_runtime.h> #include<stdio.h> int main(int argc, char **arg) { //f[^vf̍v` int nElem = 1024; //ObhƃubN̍\` dim3 block(1024); dim3 grid((nElem+block.x-1)/block.x); printf("grid.x %d block.x %d \n", grid.x, block.x); //ubNZbg block.x = 512; grid.x = (nElem+block.x-1)/block.x; printf("grid.x %d bloc...
1,741
#include<iostream> #include<cuda.h> #include<stdlib.h> #include<algorithm> #include<thrust/sort.h> #include<math.h> #include<stdio.h> using namespace std; struct tree{ int id; int leftid; int parent; float filter; int rightid; int pos; int startpos; int endpos; }Maptree[30]; __global__ ...
1,742
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <unistd.h> #include <sys/wait.h> #include <sys/time.h> /** 1.5[MB] div == 4, size = * 48000 2.0[MB] div == 8, size = * 32000 2.4[MB] div == 8, size = * 37000 **/ __global__ void __add(float* a,float* b,int size,int div){ ...
1,743
extern "C" __global__ void add (long n, double *a, double *b){ int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { a[i] += b[i]; } }
1,744
#include "includes.h" #define NUM 100 __global__ void add (int *a, int *b, int *c) { c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x]; }
1,745
#include "includes.h" __device__ float machine_eps_flt() { typedef union { int i32; float f32; } flt_32; flt_32 s; s.f32 = 1.; s.i32++; return (s.f32 - 1.); } __device__ double machine_eps_dbl() { typedef union { long long i64; double d64; } dbl_64; dbl_64 s; s.d64 = 1.; s.i64++; return (s.d64 - 1.); } __global__ v...
1,746
#include "includes.h" __global__ void devInverseReindexInt3Bool(int N, int3 *destArray, int3 *srcArray, unsigned int *reindex, int realSize, int nDims, int maxValue, bool ignoreValue) { for (unsigned int n = 0; n < nDims; n++) { int i = blockIdx.x*blockDim.x + threadIdx.x; while (i < N) { int ret = -1; int tmp = srcAr...
1,747
#include <stdio.h> #include <iostream> #include <fstream> #include <random> #define N 10000 #define MIN_POS 1688 using namespace std; typedef struct { float charge; int index; } cell; #define CUDA_CHECK(condition) \ /* Code block avoids redefinition of cudaError_t error */ \ do { \ cudaError_t error...
1,748
#include <stdio.h> #include <cuda.h> #include <curand.h> #include <curand_kernel.h> //this is the function that finds the min within the matrix __global__ void getminimum(unsigned *da, unsigned* minValue){ int i = threadIdx.x * blockDim.y + threadIdx.y; atomicMin(minValue, da[i]); } //fill matrix with random n...
1,749
#include <cstdio> #include <cstdlib> // error checking macro #define cudaCheckErrors(msg) \ do { \ cudaError_t __err = cudaGetLastError(); \ if (__err != cudaSuccess) { \ fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \ msg, cudaGetErrorString(__err), \ ...
1,750
#include <cuda.h> __device__ float phi(float eig1, float eig2, float gamma) { if (eig1 < 0.f) return __powf(eig1/eig2, gamma); return 0.f; } __device__ float omega(float eig1, float eig2, float gamma, float alpha) { eig2 = abs(eig2); if (eig1 <= 0.f) return __powf(1.f + eig1/eig2, gamma); if (eig1 < eig2...
1,751
#include <stdio.h> //#include <stdlib.h> #define DATA_SIZE 10 __global__ void cusum(int *data,int *size,float *sum){ int thi=threadIdx.x; if(thi<DATA_SIZE){ sum+=data[thi]; } } int main(int argc,char *argv[]){ int *list; int *dev_list; int i; int size=DATA_SIZE; int *dev...
1,752
#include "includes.h" __global__ void drawHeart(int CIRCLE_SEGMENTS, float *xx, float*yy) { float scale = 0.5f; int i = threadIdx.y*CIRCLE_SEGMENTS + threadIdx.x; float const theta = 2.0f * 3.1415926f * (float)i / (float)CIRCLE_SEGMENTS; xx[i] = scale * 16.0f * sinf(theta) * sinf(theta) * sinf(theta); yy[i] = -1 *...
1,753
extern "C" __global__ void kNMLQuadraticMinimize1_kernel( int numAtoms, int paddedNumAtoms, float4 *posqP, float4 *velm, long long *force, float *blockSlope ) { /* Compute the slope along the minimization direction. */ extern __shared__ float slopeBuffer[]; float slope = 0.0f; for( int atom = threadIdx.x + blockId...
1,754
#include <iostream> #include <string> #include <fstream> #include <stdio.h> using namespace std; typedef uchar4 ImageType; typedef double4 ClastersPos; typedef double DistanceType; __constant__ int QUANTITY; __constant__ ClastersPos POSITIONS[32]; void setZero(ClastersPos * pos, int clastersNum) { for (int i = 0...
1,755
//CUDA reduction algorithm. simple approach //Tom Dale //11-20-18 #include <iostream> #include <random> using namespace std; #define N 100000//number of input values #define R 100//reduction factor #define F (1+((N-1)/R))//how many values will be in the final output //basicRun will F number of threads go through R ...
1,756
#include<cuda.h> #include<stdio.h> void initializeArray(int*,int); void stampaArray(int*, int); void equalArray(int*, int*, int); int main(int argn, char * argv[]) { //numero totale di elementi dell'array int N; int *A_host; //array memorizzato sull'host int *A_device; //array memorizzato sul device int *copy; //array...
1,757
#include "matrix.cuh" matrix_t* matrix_constructor(unsigned int rows, unsigned int cols) { //assert(rows > 0 && cols > 0); matrix_t* m = (matrix_t*)malloc(sizeof(matrix_t) + sizeof(float) * rows * cols); assert(m != NULL); m->rows = rows; m->cols = cols; set_matrix(m, 0.0); return m; } float matrix_get(ma...
1,758
__global__ void primal(float *y1, float *y2, float *xbar, float sigma, int w, int h, int nc) { int x = threadIdx.x + blockDim.x * blockIdx.x; int y = threadIdx.y + blockDim.y * blockIdx.y; if (x < w && y < h) { int i; float x1, x2, val, norm; for (int z = 0; z < nc; z++) { i = x + w * y + w ...
1,759
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <assert.h> #define NTHREADS 120 #define CUDA_CALL(x) \ { \ const cudaError_t a = (x...
1,760
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define THREADS_PER_BLOCK 1 #define THREADS_PER_SM 1 #define BLOCKS_NUM 1 #define TOTAL_THREADS (THREADS_PER_BLOCK*BLOCKS_NUM) #define WARP_SIZE 32 #define REPEAT_TIMES 4096 // GPU error check #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }...
1,761
#include <cuda_runtime.h> #include <stdio.h> //#include <stdbool.h> extern "C" void gray_parallel(unsigned char* h_in, unsigned char* h_out, int elems, int rows, int cols); __global__ void kernel1(unsigned char* d_in, unsigned char* d_out, int rows, int cols){ int idx = threadIdx.x+blockIdx.x*blockDim.x; int idy =...
1,762
#include <stdio.h> #include<cuda_runtime.h> #include <time.h> #include <cuda.h> // CUDA runtime // Helper functions and utilities to work with CUDA #define N 256 //#define M 256 //__global__ĺ߱δ뽻CPUãGPUִ __global__ void matrix_mult(float *dev_a, float* dev_b, float* dev_c, int Width) { int Row = blockIdx.y*block...
1,763
#include<iostream> using namespace std; __global__ void multiply(int *ad,int *bd,int *cd,int n) { int row=blockIdx.y*blockDim.y+threadIdx.y; int col=blockIdx.x*blockDim.x+threadIdx.x; int sum=0; for(int i=0;i<n;i++) { sum=sum+ad[row*n+i]*bd[i*n+col]; } cd[row*n+col]=sum; } int main() { cout...
1,764
#include "includes.h" __global__ void divide_by_vector(float *matrix, float *vector, unsigned int row, unsigned int col) { int index = blockIdx.x * blockDim.x + threadIdx.x; if (index < row * col) matrix[index] /= vector[index / col]; }
1,765
#include <cstdio> #include <cstddef> #include <cfloat> #include <chrono> #ifndef ARRAY_SIZE #define ARRAY_SIZE 100 #endif #ifndef ARRAY_TYPE #define ARRAY_TYPE double #endif #ifndef BLOCK_NUM #define BLOCK_NUM 100 #endif #ifndef BLOCK_SIZE #define BLOCK_SIZE 512 #endif #ifndef WINDOW_SIZE #define WINDOW_SIZE 4 #en...
1,766
#include "includes.h" __global__ void PyrDown_y_g(u_int8_t *ptGrayIn,u_int8_t *ptGrayOut, int w, int h) { int ix = blockIdx.x*blockDim.x + threadIdx.x; int iy = blockIdx.y*blockDim.y + threadIdx.y; if(ix<w && iy<h)// && y>2) { float p_2 = ptGrayIn[ix*2+(iy*2-2)*w*2]/16.0f; float p_1 = ptGrayIn[ix*2+(iy*2-1)*w*...
1,767
// add two numbers #include <stdio.h> #include <cuda.h> #include <cuda_runtime.h> #include <curand_kernel.h> const int NBLOCK = 1; const int NTHREAD = 1; __global__ void add(int a,int b,int *c){ *c = a + b; } int main(void){ int a = 2; int b = 7; int c; int *c_dev; cudaMalloc( (void*...
1,768
#include "gemm.cuh" #include <stdio.h> //assumes that diagonal matrix has diagonal of one in reality (see ldl algorithm packed storage) __global__ void k_choi_diag_lower_gemm_f32(int n, float alpha, const float* D, int stride_row_d, int stride_col_d,const float* L, int stride_row_l, int stride_col_l, float beta, flo...
1,769
#include <cuda.h> #include <cuda_runtime.h> #include "ColorConverterKernels.cuh" #include "../errorCheck.cuh" __global__ void kernelCalcHist(unsigned char* data, unsigned int* hist, unsigned int size) { // Shared memory für lokales Histogramm im Aktuellen Block __shared__ unsigned int temp[256]; // Thread i im ...
1,770
#include <cstdio> #include <fstream> #include <iostream> #include <math.h> using namespace std; int nx = 41; int ny = 41; int grid_size = nx * ny; int SIZE = grid_size * sizeof(float); int nt = 700; int nit = 50; float c = 1.0; float dx = 2.0 / (nx - 1); float dy = 2.0 / (ny - 1); int rho = 1.0; float nu = 0.1; floa...
1,771
#include "includes.h" __global__ void dot(int *a, int *b, int *temp, int *c) { int outputIndex = blockIdx.x * blockDim.x + threadIdx.x; int i = outputIndex; int result = 0; /* multiplication step: compute partial sum */ while(i < N) { result += a[i] * b[i]; i += blockDim.x * gridDim.x; } temp[outputIndex] = result; ...
1,772
#include "includes.h" __global__ static void mprts_update_offsets(int nr_total_blocks, uint* d_off, uint* d_spine_sums) { int bid = threadIdx.x + THREADS_PER_BLOCK * blockIdx.x; if (bid <= nr_total_blocks) { d_off[bid] = d_spine_sums[bid * CUDA_BND_STRIDE + 0]; } }
1,773
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <iostream> #include <chrono> #include <thrust/functional.h> #include <thrust/iterator/constant_iterator.h> int main() { std::vector<double> stocks_ms, stocks_aapl; while (std::cin){ double mstf, aapl; std::cin >> mstf ...
1,774
#include "NeuralNetwork.cuh" /** * Creates a neural network with the specified number of layers * and neurons * Parameter layers: the number of layers in the neural network * Parameter neurons: an array with the number of neurons for each layer * Returns: a NeuralNet with the specified layers/neurons */ N...
1,775
/* ***** vecadd.cu ***** CUDA program to add two vectors. Compile: nvcc -o vecadd vecadd.cu Usage: vecadd [N], where N is vector length Author: John M. Weiss, Ph.D. CSC433/533 Computer Graphics - Fall 2016. Modifications: */ #include <chrono> #include <ctime> #include <cmath> #include <iostream> us...
1,776
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <arpa/inet.h> #include <math.h> #include "cs_dbg.h" #include "cs_cuda.h" #include "cs_helper.h" #include "cs_perm_generic.h" // #define CUDA_DBG // #define CUDA_DBG1 ...
1,777
#include "includes.h" __global__ void assignInitialClusters_64(int width, int height, int nPixels, int clusterCount, int* cluster, int filterCount, float* responses, int* intResponses) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; int pixel = y * width + x; if ((x < wid...
1,778
#include <stdlib.h> #include <stdio.h> #define ARR_SIZE 10 __global__ void add(int *a, int *b, int *c) { int i = blockIdx.x; if (i < ARR_SIZE) c[i] = a[i] + b[i]; } int main() { int i; int h_A[ARR_SIZE], h_B[ARR_SIZE], h_C[ARR_SIZE]; int *d_A, *d_B, *d_C; // Popula os vetores a serem somados for (i = ...
1,779
#define N 1200 #define THREADS 1024 #include <stdio.h> #include <math.h> __global__ void vecAdd(int *a, int *b, int *c); int main(){ int *a, *b, *c; int *dev_a, *dev_b, *dev_c; int size; size = N*sizeof(int); cudaMalloc((void**) &dev_a, size); cudaMalloc((void**) &dev_b, size); cudaMallo...
1,780
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <cuda.h> #include <cuda_runtime.h> #include <curand_kernel.h> __global__ void n_avg(int *a, int *b, int i, int n) { for (int j = i; j < i + n; j++) { atomicAdd(&b[i], a[j]); } b[i] /= n; } int main() { int m = 10000; int n = 32...
1,781
/** Sample for Mobile CUDA Simple Adding Vectors Application. Authoer @ Taichirou Suzuki **/ #include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <unistd.h> #include <sys/wait.h> #include <sys/time.h> /** Simple Kernel. **/ __global__ void ___add(float* a,float* b,unsigned long size)...
1,782
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<stdio.h> #include<stdlib.h> #include<string.h> __global__ void countWord(char *a , char *b , unsigned int* d_count , int size , int wordSize) { int id = threadIdx.x+1; int cur = 0; int start = 0; int end = size; int j = 0; ...
1,783
#include <stdio.h> #include <stdlib.h> #include <curand.h> #define GRID_SIZE 2 #define BLOCK_SIZE 3 struct point3D { float x; float y; float z; }; /** * GPU側のグローバル関数から呼び出される関数の定義は、deviceを指定する。 * これで、後は普通の関数定義と同じように、好きな関数を定義できる。 */ __device__ float negate(float val) { return -val; } /** * GPU側の関数の引数に、構造体を使用...
1,784
#include <stdio.h> #include <time.h> #include <cuda_runtime.h> #include <cassert> #include <cstdlib> #include <functional> #include <iostream> #include <algorithm> #include <vector> using std::cout; using std::generate; using std::vector; #define SIZE 10000 #define N 10 #define CUDA_CALL(x) do { if((x)!=cudaSuccess)...
1,785
#include <cuda_runtime.h> #include <stdio.h> #include <sys/time.h> #define LEN 1<<22 double seconds(){ struct timeval tp; struct timezone tzp; int i = gettimeofday(&tp,&tzp); return ((double)tp.tv_sec+(double)tp.tv_usec*1.e-6); } struct InnerArray{ float x[LEN]; float y[LEN]; }; void...
1,786
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <cuda.h> #define maxThreads 512 /* This code was developed and tested on cuda3 */ __global__ void getmaxcu(unsigned int num[], unsigned int size){ unsigned int tid = threadIdx.x; unsigned int gloid = blockIdx.x*blockDim.x+threadIdx.x; __sha...
1,787
/* sergeim19 April 27, 2015 Burgers equation - GPU CUDA version */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #include <cufft.h> #include <time.h> #include <sys/time.h> #define NADVANCE (4000) #define nu (5.0e-2) int timeval_subtract (double *result, struct timeval *x, struct t...
1,788
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> extern "C" __device__ void profileCount(long index){ }
1,789
// inspired by https://devblogs.nvidia.com/efficient-matrix-transpose-cuda-cc/ // TILE_DIM=32, BLOCK_ROWS=8 // No bank-conflict transpose // Same as transposeCoalesced except the first tile dimension is padded // to avoid shared memory bank conflicts. // can be used to transpose non-square 2D arrays __global__ void tra...
1,790
__global__ void update(int nx, int ny, float *f, float *g) { int idx = blockIdx.x*blockDim.x + threadIdx.x; int i, j; i = idx/ny; j = idx%ny; if (i > 0 && i < nx-1 && j > 0 && j < ny-1) { f[idx] = 0.25*(g[idx-ny] + g[idx+ny] + g[idx-1] + g[idx+1] - 4*g[idx]) + 2*g[idx] - f[idx]; } } ...
1,791
#include <iostream> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #include <ctime> #include <sys/time.h> #include <sstream> #include <string> #include <fstream> using namespace std; __global__ void reduce0(int *g_idata, int *g_odata, int size){ extern __shared__ int s...
1,792
//#pragma comment (lib, "cublas.lib") //#include "stdio.h" //#include <cuda.h> //using namespace std; //#include <ctime> //#include "cuda_runtime.h" //#include "curand_kernel.h" //#include "device_launch_parameters.h" //#include <stdio.h> //#include <stdlib.h> // //#include <string> //#include <iomanip> //#include <tim...
1,793
#include <cuda.h> #include <bits/stdc++.h> #define BLOCK_SIZE 32 #define TILE_WIDTH BLOCK_SIZE //int BLOCK_SIZE, TILE_WIDTH; using namespace std; //Declarations : //matrix initialization void init(int *A, int n, int d); //matrix comparation bool compare(int *A, int *B, int n); //print matrix void printmat(int *A, ...
1,794
/* Multiplica um vetor por uma constante. Exemplo para o uso de memória constante em CUDA */ #include <stdio.h> #include <stdlib.h> #include <cuda.h> #define TAM 100 #define VLR_ESCALAR 10 #define TPB 256 __device__ __constant__ int escalar_d; __global__ void mult(int *vetA_glb){ int idx = blockDim.x * blockI...
1,795
#include <iostream> #include <stdio.h> using namespace std; __global__ void add(float *dX, float *dY, int N) { // contains the index of the current thread in the block int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; int arraySize = N; int valuesPerThread; ...
1,796
#include <stdio.h> #define N 512 /*************************************************************** * TERMINOLOGÍA * * Un block puede ser dividido en distintos threads paralelos * * Usamos threadId.x en vez de blockIdx.x * *************************...
1,797
#include "includes.h" // 1 / (1 + e^(-x)) extern "C" __global__ void logistic(size_t n, double *result, double *x) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i<n) { result[i] = 1.0 / (1.0 + exp(-x[i])); } }
1,798
#include "includes.h" __global__ void VectorAdd(float *VecA, float *VecB, float *VecC, int size) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < size) VecC[i] = VecA[i] + VecB[i]; }
1,799
#include <cuda_runtime.h> extern "C" void sumMatrixOnGPU2D1(float *MatA, float *MatB, float *MatC, int nx, int ny, int dimx); // grid 1D block 1D // grid 2D block 2D // grid 2D block 1D __global__ void sumMatrixOnGPUMix(float *MatA, float *MatB, float *MatC, int nx, int ny) { unsigned int ix = threadIdx.x + blockI...
1,800
/* * @Author: heze * @Date: 2021-06-01 00:38:55 * @LastEditTime: 2021-06-05 00:47:39 * @Description: 在gpu_shareMem.cu基础上查对数表 * @FilePath: /src/gpu_shareMem_log.cu */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define blockSize 10 #define printArray 0 /** * @brief 对数表 */ __device__ float logTable...