serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
20,401
/* 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...
20,402
/* void cureTest() { float sqrt }*/
20,403
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <sys/time.h> #define BLOCK_SIZE 8 #define GRID_SIZE 8 //struct timespec start, finish; //double elapsed; __global__ void ising_kernel(int *G,int *newG,double *w,int n){ int x,y; __shared__ double shared_w[25]; __shared__...
20,404
#include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #include <math.h> #include <locale.h> #include <cuda.h> #define BLOCK_SIZE 250 #define GRID_SIZE 4 #define THREAD_SIZE 1000 #define CUDA_FLOAT float __global__ void pi_kern(double *res) { int n = threadIdx.x + blockIdx.x * BLOCK_SIZE; CU...
20,405
/** * 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...
20,406
#include <stdio.h> #include <stdlib.h> #define CONFIGURATION_COUNT 250000 struct Tick { long timestamp; double open; double high; double low; double close; double sma13; double ema50; double ema100; double ema200; double rsi; double stochK; double stochD; double prc...
20,407
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <math.h> #include <time.h> typedef struct bmpFileHeaderStruct { /* 2 bytes de identificación */ uint32_t size; /* Tamaño del archivo */ uint16_t resv1; /* Reservado */ uint16_t resv2; /* Reservado */ ui...
20,408
#include <stdlib.h> #include <string.h> #include <time.h> #include <math.h> #include <stdio.h> #include <cuda_runtime.h> #include <sys/time.h> double cpuSecond() { struct timeval tp; gettimeofday(&tp, NULL); return ((double) tp.tv_sec + (double) tp.tv_usec * 1.e-6); } #define CHECK(call) ...
20,409
#include <stdio.h> __global__ void reduce0(int *g_idata, int *g_odata) { extern __shared__ int sdata[]; // each thread loads one element from global to shared mem unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x*blockDim.x + threadIdx.x; sdata[tid] = g_idata[i]; __syncth...
20,410
// This example demonstrates a parallel sum reduction // using two kernel launches #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> #include <vector> #include <numeric> #include <iostream> #include <time.h> double secuential(const double a[] , int dim,bool verbose...
20,411
#include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <time.h> const int N = 1024; // 正方行列のサイズを指定(N×N) const int BLOCK = 16; // ブロックのサイズを指定 double cpuSecond(); __global__ void matrixMul(int *dMatA, int *dMatB, int *dMatC) { int col = blockIdx.x * blockDim.x + threadIdx.x; int row = blockIdx.y * blo...
20,412
#include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define ceil(a,b) ((a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1) void check_error (const char* message) { cudaError_t error = cudaGetLastError (); if (error != cudaSuccess) { printf ("CUDA error :...
20,413
#include<iostream> #include<fstream> #include<string> #include<cstdlib> #include<cstring> #include<vector> #include<iterator> #include<ctime> #include<limits> using namespace std; struct info_edge { int vertex1,vertex2; int weight; }; void extract_data(vector<info_edge> &adjacency,char* str) { int i,n=1,m=0; int ver...
20,414
#include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define ceil(a,b) ((a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1) void check_error (const char* message) { cudaError_t error = cudaGetLastError (); if (error != cudaSuccess) { printf ("CUDA error :...
20,415
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #define thread_num 16 /*inline void CUDA_ERROR_CHECK(const cudaError_t &err){ if(err != cudaSuccess){ fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(err)); exit(EXIT_FAILURE); } }*/ __device__ int mandel(float x, float y, int maxIterations){ floa...
20,416
#include<cuda.h> #include<stdio.h> #include<cuda_runtime.h> #include <cuda_profiler_api.h> #define NSTREAM 8 void matricMul(int *A, int *B, int *C, int size) { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { int outidx = col * size + row; for (int idx = 0; idx < size; idx++) { ...
20,417
#include "includes.h" __global__ void CutSubImageKernel_SingleParams(float *input, float *output, float subImageX, float subImageY, float subImageDiameter, bool safeBounds, int inputWidth, int inputHeight, int outputWidth, int outputHeight) { int id = blockDim.x * blockIdx.y * gridDim.x + blockDim.x * blockIdx.x + thre...
20,418
#include "includes.h" __device__ void devVecAdd(size_t pointDim, double* dest, double* src) { for(size_t i = 0; i < pointDim; ++i) { dest[i] += src[i]; } } __global__ void kernElementWiseSum(const size_t numPoints, const size_t pointDim, double* dest, double* src) { // Called to standardize arrays to be a power of two ...
20,419
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> // this is the program that is to be run on the device for a // large number of threads, in our example 100 // each thread takes care of one entry in the number array, // so in order for the thread to know which number to manipulate, // a scheme has to be...
20,420
#include "includes.h" /* Location qualifiers __global__ Defines a kernel. Runs on the GPU, called from the CPU. Executed with <<<dim3>>> arguments. __device__ Runs on the GPU, called from the GPU. Can be used for variables too. __host__ Runs on the CPU, called from the CPU. Qualifiers can be mixed Eg __host__...
20,421
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <cuda.h> #include <curand.h> #include <curand_kernel.h> #include <cuda_runtime.h> #define ROW 5000 #define COL 5000 __global__ void matrixAddition(float *a, float *b, float *c, int N){ int index = threadIdx.x + blockIdx.x * blockDim.x; if( index <...
20,422
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include<time.h> #define BLOCK_SIZE 32 __global__ void gpu_matrix_mult(long *a, long *b, long *c, int m, int n, int k) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; int sum = 0; if (row < m) { ...
20,423
#include<stdio.h> #include<cuda.h> #include<math.h> #include<float.h> #define CUDA_CALL(x) do { cudaError_t err=(x); \ if(err!=cudaSuccess) { \ printf("Error %s at %s: %d",cudaGetErrorString(err),__FILE__,__LINE__);\ return EXIT_FAILURE;}} while(0) #define W 64 // Input DIM #define D 3 // Input and Kernel Dep...
20,424
#include <iostream> #include <thrust/sort.h> using namespace std; bool searchFunction(int *array, int *array2, int k, int m){ int first = array2[k]; int second = array[k]; for (int i=0; i<m; i++){ if (array[i]>first){ return false; } else if (array[i]==first){ if (array2[i]==second){ return tr...
20,425
/* * model.c * * */ #include <math.h> #include <cuda.h> struct model_data_ { double mygamma; double *theta; int N_samples; int N_sensors; } model_data; extern "C" __global__ void GPU_model(double *g, double *d,double *theta,double mygamma,int N_samples,int N_sensors) { int ix= bloc...
20,426
// // http://forums.nvidia.com/index.php?showtopic=34309 // #include <stdio.h> // called from host, run on device __global__ void add_arrays_gpu(float *in1,float *in2,float *out) { int idx=threadIdx.x; // flat model out[idx]=in1[idx]+in2[idx]; } int main() { cudaDeviceProp c; cudaGetDeviceProperties(&c, 0)...
20,427
#include <stdio.h> __global__ void math_sqrt(float *a, float *b) { *b = sqrt(*a); } int main() { float a, b; float *d_a, *d_b; a = 4; cudaMalloc((void **) &d_a, sizeof(float)); cudaMalloc((void **) &d_b, sizeof(float)); cudaMemcpy(d_a, &a, sizeof(float), cudaMemcpyHostToDevice); ...
20,428
#include "includes.h" long N = 6400000000; int doPrint = 0; /////////////////////////////////////////////////////////////////////////////////////////////////////////// // HELPER CODE TO INITIALIZE, PRINT AND TIME struct timeval start, end; __global__ void gpu_sqrt(float* a, long N) { long element = blockIdx.x*blockDi...
20,429
#include <cuda_runtime.h> __global__ void fdiv_rn_global(float x, float y, float *r) { *r = __fdiv_rn(x, y); } float cuda_fdiv_rn(float x, float y) { float *gpu_result, result; cudaMalloc((void **)&gpu_result, sizeof(float)); fdiv_rn_global<<<1, 1>>>(x, y, gpu_result); cudaMemcpy(&result, gpu_res...
20,430
#include <stdio.h> #include <math.h> #include <sys/time.h> #include <stdlib.h> #define N 1024 #define HEADER_SIZE (54) #define LENGTH (3*N*N) #define screenh N #define screenw N typedef unsigned char byte_t; void BMPwrite(byte_t* bmp) { int i; FILE *file; file = fopen("cuda.bmp", "w+"); for(i = 0; i < LENGT...
20,431
#include "includes.h" __global__ void calculate_A_ch_3(float* rho, float* dz, float* s_a, int npix, int nchannels, int nimages, float* A_ch) { int i = blockIdx.x*blockDim.x + threadIdx.x; int j = blockIdx.y*blockDim.y + threadIdx.y; int c = blockIdx.z*blockDim.z + threadIdx.z; if (i < npix && j < nimages) { A_ch[c*npix...
20,432
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,float var_2,float var_3,float var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float ...
20,433
#include <thrust/device_vector.h> #include <iostream> #include <cuda.h> #include <cuda_runtime.h> #include <sys/time.h> __global__ void increment(int *data_ptr) { (*data_ptr)++; } __global__ void at_increment(int *data_ptr) { atomicAdd(data_ptr, 1); } int main(void) { thrust::device_vector<int> data_ptr(1); ...
20,434
#include <string> #include <iostream> #include <cstdlib> #include <fstream> #include <cmath> #include <iomanip> #include <cstring> #include <chrono> #define mu 0 #define pi 3.141 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ )) // useful MACRO to check for errors using namespace std; static vo...
20,435
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> // adds array elements in a loop like normal void addArrays(int* a, int* b, int* c, int count) { for (int i = 0; i < count; i++) { c[i] = a[i] + b[i]; } } // simulates adding each element in a separate thread indexed b...
20,436
#define FENCE_KERNEL(ID,ASM_STR)\ extern "C" __global__ void fences_kernel_ ## ID(\ volatile float *OUT, volatile float *IN)\ {\ int id = blockDim.x * blockIdx.x + threadIdx.x;\ OUT[id] = IN[id+1] + 1.0f;\ asm(ASM_STR);\ OUT[id+1] = IN[id] + 2.0f;\ } // same as .acq_rel (since that's default) FENCE_KERNEL(...
20,437
/* * Copyright (c) 2016, Ville Timonen * 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 copyright notice, this * list of co...
20,438
#include "includes.h" __global__ void cudaDinv_kernel(unsigned int size, const double *x, double *y) { 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) { y[i] = 1.0 / x[i]; } }
20,439
#include "includes.h" __global__ void normalizeGradient(float* gradient, int* activeMask, int activePatches, int patches) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i >= activePatches) return; int patch = activeMask[i]; float norm = gradient[6 * patches + patch]; if (norm > 0) norm = 1.0f / sqrtf(norm); fo...
20,440
#include <iostream> #include <stdio.h> #include <cuda_runtime.h> #define MIN(a, b) (a<b?a:b) #define BLOCK_SIZE 32 struct Matrix { int height; int width; int *el; int stride; __host__ __device__ Matrix(int height, int width, int stride ): height(height), width(width),stride(stride){} __host__ __device__ M...
20,441
#include<stdio.h> __global__ void kernel(int i){ printf("hello world %d \n", i); }; int main(){ int const n_stream = 5; cudaStream_t *ls_stream; ls_stream = (cudaStream_t*) new cudaStream_t[n_stream]; for (int i=0; i<n_stream; i++){ cudaStreamCreate(&ls_stream[i]); } for(int i...
20,442
#include <stdio.h> // kernel __global__ void add_vectors(int *c, int *a, int *b, int n){ // printf("Add vectors function\n"); // printf("n value: %i \n", n); int index = threadIdx.x; int stride = blockDim.x; // int index = blockIdx.x * blockDim.x + threadIdx.x; // int stride = blockDi...
20,443
#include <cuda.h> #define BLOCK_SIZE_X 16 #define BLOCK_SIZE_Y 16 #define PI 3.14159265358979323846 #define WINDOW 6 #define NUM_ITER 64 __global__ void conv2(float *A, float *B,uint8_t *C, int height, int width, int window){ int row = threadIdx.x + blockIdx.x*blockDim.x; int col = threadIdx.y + blo...
20,444
#include <iostream> #include <chrono> int main(int argc, char *argv[]) { int n = atoi(argv[1]); //TODO: atoi is an unsafe function int nbiter = atoi(argv[2]); float *array = new float[n]; for(int i = 0; i < n; ++i) array[i] = 1.; float *d_array; cudaMallocHost((void **)&d_array, n *...
20,445
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #define TAM 10 #define TAMBLOCK 2 __global__ void reducirVector(float *dest, float *origin, int *BLOCKS){ if(blockIdx.x==0){ float counter=0.0f; for(int i=0;i<*BLOCKS;++i){ for(int j=0;j<TAMBLOCK;++j){ counter+=orig...
20,446
#include <iostream> #include <cstdlib> #include <cstdio> #include <cassert> using namespace std; __global__ void euler1 (float2 *pos, float2* vel, float2 *acc, float dt, float box) { int i=threadIdx.x+blockDim.x*blockIdx.x; //Moves a particle using Euler pos[i].x += vel[i].x * dt; pos[i].y += vel[i].y * dt; ...
20,447
#include "includes.h" #define FIBER 32 #define MATRIX_SIZE 2048 #define DATA_SIZE MATRIX_SIZE * MATRIX_SIZE * sizeof(int) #define MAX_MATRIX_SIZE (MATRIX_SIZE * MATRIX_SIZE) using namespace std; __global__ void kernel_shared(int *A, int *C, int *B, int *result) { __shared__ int shared_memory[FIBER][FIBER]; int i...
20,448
extern "C" __global__ void sigmoid(float* a, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { a[i] = 1.0f / (expf(-a[i]) + 1.0f); } }
20,449
__device__ float multiplyByTwo(float number){ return number * 2.0f; } __device__ float divideByTwo(float number){ return number * 0.5f; }
20,450
#include "includes.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]; }
20,451
// Copyright (c) 2019-2020, 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 o...
20,452
#include <iostream> #include <cuda.h> #include <chrono> using namespace std; __global__ void transpose(double *in_d, double * out_d, int row, int col) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; out_d[y+col*x] = in_d[x+row*y]; } int main(int argc,char **ar...
20,453
#include "includes.h" __global__ void writeOffsetUnroll4(float *A, float *B, float *C, const int n, int offset) { unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; unsigned int k = i + offset; if (k + 3 * blockDim.x < n) { C[k] = A[i] + B[i]; C[k + blockDim.x] = A[i + blockDim.x] + B...
20,454
/* rkrish11 Rahul Krishna */ #include "cuda.h" #include <curand.h> #include <curand_kernel.h> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define SEED 35791246 __global__ void init_stuff(curandState *state, int count) { // This sets a random number seed for all th...
20,455
#include "includes.h" __global__ void kCopyToTransDestFast(float* srcStart, float* destStart, unsigned int srcCopyWidth, unsigned int srcCopyHeight, unsigned int srcJumpSize, unsigned int destJumpSize) { // const unsigned int idxY = blockIdx.y * blockDim.y + threadIdx.y; // const unsigned int idxX = blockIdx.x * ...
20,456
#include "add.cuh" /** * CUDA kernel */ __global__ void kernel(int* a, int* b, int* c) { int i = threadIdx.x; c[i] = a[i] + b[i]; } /** * Function adds two numbers and stores the result in c */ void addTwoNum(int* a, int* b, int* c) { int* d_a, * d_b, * d_c; cudaMalloc((void**)&d_a, sizeof(int)); cudaMalloc(...
20,457
/* This program is written to find the nearest neighbour of each point in 3 deminsional space by implementing the brute force algorithm. The brute force approach can easily be converted into a embarassingly parallel algorithm for the GPU where there is no interaction between the threads. Benchmarking is done to compare...
20,458
#include "motionPlanningSolution.cuh" typedef struct MotionPlanningSolution { std::vector<int> path; // list of path indexes float cost; float cp; float time; } MotionPlanningSolution;
20,459
#include <math.h> __device__ double dist(double x1, double y1, double x2, double y2){ return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); } __global__ void testKernel(double *xs, double *ys, double *b){ b[blockIdx.x] = dist(xs[blockIdx.x], 1.0, ys[blockIdx.x], 1.0); } /* r^3 */ __device__ double rbf(doub...
20,460
#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<stdbool.h> #include<cuda.h> #include<cuda_runtime.h> #include<curand.h> #include<curand_kernel.h> #include<math.h> //Declare all needed extern variables and functions // Result from last compute of world. extern unsigned char *g_resultData; // Current ...
20,461
//#include "BLACKCAT_GPU_MATHEMATICS.cuh" // // //__global__ //void GPU_MATHEMATICS::dot(float* store, unsigned s_LD, const float* m1, unsigned m1_r, unsigned m1_c, unsigned m1_LD, // const float* m2, unsigned m2_r, unsigned m2_c, unsigned m2_LD) //{ //// cublasHandle_t h; //// cublasCreate(&h)...
20,462
/* 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 ...
20,463
#include <stdio.h> // pitch: the number of cols // size : the number of rows __global__ void matmul_kernel( const float* const mat1, const float* const mat2, float* const mat3, const size_t pitch1, const size_t pitch2, const size_t pitch3, const size_t size1, const size_t size2, const size_t size3 ...
20,464
#include<cuda.h> #include<stdio.h> #include<math.h> #include<stdlib.h> using namespace std; //For nodes in adjacency list typedef struct node { int val; struct node* next; }node; //Stores visit array's old and new values typedef struct node1 { int oldval,newval; }node1; //Compare function to sort based on decre...
20,465
#include "includes.h" __global__ void atomic_reduction_kernel(float *data_out, float *data_in, int size) { int idx_x = blockIdx.x * blockDim.x + threadIdx.x; atomicAdd(&data_out[0], data_in[idx_x]); }
20,466
#include <stdio.h> __global__ void add( int *a, int *b, int *c) { *c = *a + *b; } __global__ void array_add (int *a, int *b, int *c, int sz) { int idx = threadIdx.x + blockIdx.x * blockDim.x; if ( idx < sz) c[idx] = a[idx] + b[idx]; } int main(void) { int a, b, c; int *dev_a, *dev_b, *dev_c; int size = size...
20,467
/** * @device matview_transopse * Create on:Apr 17 2018 * @author: haili * the size of tensor is m×n×k×l */ __global__ void d_batch_transpose(float* A,float* T,const int m, const int n,const int batch){ int tid=blockDim.x*blockIdx.x+threadIdx.x; int t_n=blockDim.x*gridDim.x; while(tid<m*n*batch){ A[(tid/(m*...
20,468
#include <algorithm> #include <cfloat> #include <chrono> #include <fstream> #include <iostream> #include <random> #include <sstream> #include <stdexcept> #include <vector> #include <stdio.h> #include <stdlib.h> #include <string> double std_time_used; struct Data { Data(int size) : size(size), bytes(size * sizeof(flo...
20,469
extern "C" __global__ void sconv_bprop_C1_N64 ( float* param_test, float* param_I, const float* param_F, const float* param_E, 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 pa...
20,470
#include "includes.h" __global__ void fill_lower_left_gpu(int *iRow, int *jCol, unsigned int *rind_L, unsigned int *cind_L, const int nnz_L) { int i = threadIdx.x; if (i < nnz_L) { iRow[i] = rind_L[i]; jCol[i] = cind_L[i]; } }
20,471
#include "includes.h" __global__ void BFS_kernel_multi_block( volatile unsigned int *frontier, volatile unsigned int *frontier2, unsigned int frontier_len, volatile unsigned int *cost, volatile int *visited, unsigned int *edgeArray, unsigned int *edgeArrayAux, unsigned int numVertices, unsigned int numEdges, volatile u...
20,472
#include "includes.h" __device__ float computeDeterminant (float e00, float e01, float e02, float e10, float e11, float e12, float e20, float e21, float e22) { return e00*e11*e22-e00*e12*e21+e10*e21*e02-e10*e01*e22+e20*e01*e12-e20*e11*e02; } __global__ void hessianKernel ( float *d_output, const float *d_gxx, const flo...
20,473
#include "direct_gpu_computation.cuh" #include <cmath> // block width for computation - arbitrary parameter - can be changed #define BW 512 /** * Computes the backpropagation results of the Softmax loss for each result in a batch. * Uses the softmax values obtained from forward propagation to compute the difference. *...
20,474
#include "includes.h" __device__ void exchange(float &a, float &b){ float temp = a; a = b; b = temp; } __global__ void flip_2D(float* coords, size_t dim_y, size_t dim_x, int do_y, int do_x){ size_t index = blockIdx.x * blockDim.x + threadIdx.x; size_t total = dim_x * dim_y; size_t id_x = index % dim_x; size_t id_y = in...
20,475
#include <iostream> #include <cuda_runtime.h> #include <fstream> #include <sstream> #include <iomanip> #include <ctime> #define TILE_WIDTH 20 #define WIDTH 10000 #define MATSIZE 256 #define SIZE (WIDTH * WIDTH * sizeof(float)) float A[WIDTH][WIDTH], B[WIDTH][WIDTH], C[WIDTH][WIDTH]; float *dev_A, *dev_B, *dev_C; __g...
20,476
__global__ void f1( float4* __restrict__ ptr ) { float4 v = ptr[threadIdx.x]; v.x += 1; v.y += 1; v.z += 1; v.w += 1; ptr[threadIdx.x] = v; } __global__ void f2( float* __restrict__ ptr1, float* __restrict__ ptr2, float* __restrict__ ptr3, float* __restrict__ ptr4 ) { ptr1[threadIdx.x] += 1; ptr2[threa...
20,477
#include <cmath> #include <cuda_runtime.h> #include <curand_kernel.h> #include "metropolis_cuda.cuh" /* Raandomly shuffle the path */ __device__ void shuffle(int *path, curandState localState, int path_length) { for (int i = 1; i < (path_length - 1); i++) { int j = int(curand_uniform(&localState...
20,478
// source : https://gist.github.com/dpiponi/1502434 #include <stdio.h> // // Nearly minimal CUDA example. // Compile with: // // nvcc -o minimal minimal.cu // #define N 1000 // // A function marked __global__ // runs on the GPU but can be called from // the CPU. // // This function multiplies the elements of an arra...
20,479
#ifndef __CUDA_KERNELHEADER__ #define __CUDA_KERNELHEADER__ /********************************************/ /* Added codes for OpenACC2CUDA translation */ /********************************************/ #ifdef __cplusplus #define restrict __restrict__ #endif #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define MIN(a,b) (...
20,480
#include <fstream> #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <thrust/binary_search.h> #include <thrust/pair.h> #define IGNORE_FIR...
20,481
#include "includes.h" __global__ void diffuseProject_k(float2 *vx, float2 *vy, int dx, int dy, float dt, float visc, int lb) { int gtidx = blockIdx.x * blockDim.x + threadIdx.x; int gtidy = blockIdx.y * (lb * blockDim.y) + threadIdx.y * lb; int p; float2 xterm, yterm; // gtidx is the domain location in x for this thr...
20,482
#include <cuda.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <math.h> // to build on Titan V: // nvcc -arch=sm_70 --ptxas-options=-v -o vanilladeriv vanilladeriv.cu; #ifdef USE_DOUBLE #define dfloat double #else #define dfloat float #endif #ifndef POLYNOMIAL_ORDER #define POLYNOMIAL_ORDER ...
20,483
#include <math.h> #include <iostream> #include <time.h> #include <sys/time.h> #include <stdio.h> // modifiable typedef float ft; const int chunks = 64; const size_t ds = 1024*1024*chunks; const int count = 22; const int num_gpus = 4; // not modifiable const float sqrt_2PIf = 2.5066282747946493232942230134974f; const ...
20,484
//xfail:BUGLE_ERROR //--blockDim=1024 --gridDim=1 --no-inline //error: Unsupported function pointer typedef double(*funcType)(double); __device__ double bar(double x) { return sin(x); } __global__ void foo(double x, int i) { funcType f; if (i == 0) f = bar; else f = cos; f(x); }
20,485
#include "includes.h" __global__ void bankConflictsRead(float *outFloat, int iStride, unsigned long long *ullTime) { /* Static size of shared memory */ __shared__ float s_memoryA[2024]; /* Variable in register */ float r_var; /* Start measure clock cycles */ unsigned long long startTime = clock64(); /* Access data from...
20,486
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda.h> #include <sys/time.h> #define SIZE 102400 #define MOD 102399 #define STEP 1 /* 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 * b)...
20,487
#include <cuda_runtime.h> extern "C" { __global__ void dilation(int * src, int * dst, int p, int window_size, int n_window, int image_shape) { extern __shared__ int smem[]; int tx = threadIdx.x; int ty = threadIdx.y; int bx = blockIdx.x; if (tx == 0) { ...
20,488
#include <cstdio> #include <cstdlib> #define cudaCheckError() { \ cudaError_t e=cudaGetLastError(); \ if(e!=cudaSuccess) { ...
20,489
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <stdbool.h> #include <unistd.h> #include <pthread.h> #include <cuda.h> #define NUM_THREADs 5 #define BLOCK_SIZE 16 #define PI 3.141592654 #define MEGEXTRA 1000000 typedef struct Matrix { int width; int height; double* eleme...
20,490
#include "includes.h" __global__ void Float(float * x, int* y, size_t idxf, size_t idxi, size_t N) { for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < N; i += blockDim.x * gridDim.x) x[(idxf)*N + i] = float(y[(idxi-1)*N + i]); return; }
20,491
#include <bits/stdc++.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> using namespace std; int main(){ int N = 1<<25, mod = 1E6; srand(0); vector<int> testing(N); //thrust::host_vector<int> nums(N); clock_t start...
20,492
/* FLUIDS v.3 - SPH Fluid Simulator for CPU and GPU Copyright (C) 2012. Rama Hoetzlein, http://fluids3.com Fluids-ZLib license (* see part 1 below) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use o...
20,493
#include<iostream> #include<stdio.h> __global__ void kern(void){ int x = threadIdx.x + blockIdx.x*blockDim.x; int y = threadIdx.y + blockIdx.y*blockDim.y; // printf("Dim %d %d \n", blockDim.x, blockDim.y); printf("%d %d %d\n", x,y, (x + 8*y)); // __syncthreads(); printf("Id%d %d %d\n", blockIdx.x, blockIdx.y, (x ...
20,494
#include "includes.h" __global__ void totalSequential(float *input, float *output, int len) { //@@ Compute reduction for a segment of the input vector int tid = threadIdx.x, i = blockIdx.x * blockDim.x; if(tid == 0) { int sum = 0; for(unsigned int j = 0; j <blockDim.x; j++) { sum += input[i + j]; } output[blockIdx.x] ...
20,495
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<time.h> #define N 10000000 //job size = 1K, 10K, 100K, 1M and 10M #define M 128 //Threads per block =128 #define R 16 //radius = 2,4,8,16 // CUDA API error checking macro static void handleError( cudaError_t err, const c...
20,496
#include <float.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #define BLOCK_SIZE 16 typedef struct { int width; int height; float* elements; } Matrix; // Matrix multiplication kernel called by MatMul() __global__ void MatMulKernel(Matrix A, Matrix B, Matrix C) { ...
20,497
#include "cuda_runtime.h" #include <math.h> void SimpleSummator(double* a, double* b, double* c, int length){ for (int i = 0; i < length; i++){ c[i] = sinf(a[i]) + sinf(b[i]); } } __global__ void CUDASummator(double* a, double* b, double* c){ int i = threadIdx.x + blockIdx.x * blockDim.x; c[i] = sinf(a[i]) + s...
20,498
#include <sys/time.h> #include <cuda.h> #include <stdio.h> #define HANDLE_ERROR( err ) ( HandleError( err, __FILE__, __LINE__ ) ) static void HandleError( cudaError_t err, const char *file, int line ) { if (err != cudaSuccess) { printf( "Error: %s in %s at line %d\n", cudaGetErrorString( err ), ...
20,499
#include <stdio.h> int main() { int devCount; cudaGetDeviceCount(&devCount); printf("device count: %d\n", devCount); for (int i = 0; i < devCount; ++i) { cudaDeviceProp devProp; cudaGetDeviceProperties(&devProp, i); printf("ver: %d.%d\n", devProp.major, devProp.minor); p...
20,500
#include <iostream> #include <cmath> #include <algorithm> #include <fstream> #define N 1000 #define nrange 20 #define bkgd 3 #define CL 0.9 __global__ void kernel(double*, int*, double*); __device__ double poissonP(double, double); __device__ double factorial(double n); __global__ void kernel(double...