serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
1,901
#include "includes.h" __global__ void square(float * d_out, float * d_in) { int idx = threadIdx.x; float f = d_in[idx]; d_out[idx] = f*f; }
1,902
#include <stdio.h> int main(int argc, char **argv) { printf("Hello World from CPU!\n"); return 0; }
1,903
#include <iostream> #include <fstream> #include <cmath> #include <cuda.h> const int n = 1025; const double h = 1.0 / (double)(n); const double K2 = 100.0; const double cft1 = 1.0 / (4.0 + h * h * K2); const double cft3 = cft1 * h * h; const double PI = 3.1415926535897932385; const int MaxIter = 30000; using namespace...
1,904
#include "includes.h" __global__ void kernelF(const float *d_x, float *d_y) { const float &x0 = d_x[0]; const float &x1 = d_x[1]; // f = (1-x0)^2 + 100 (x1-x0^2)^2 const float a = (1.0 - x0); const float b = (x1 - x0 * x0) ; *d_y = (a*a) + 100.0f * (b*b); }
1,905
/* Code adapted from book "CUDA by Example: An Introduction to General-Purpose GPU Programming" This code computes a visualization of the Julia set. Two-dimenansional "bitman" data which can be plotted is computed by the function kernel. The data can be viewed with gnuplot. The Julia set iteration is: z= z**2 + C...
1,906
#include <stdio.h> /* * Show DIMs & IDs for grid, block and thread */ __global__ void checkIndex(void) { if ((threadIdx.x + threadIdx.y) && ((threadIdx.x + threadIdx.y) % 5 == 0)) { printf("threadIdx:(%d, %d, %d) blockIdx:(%d, %d, %d) " "blockDim:(%d, %d, %d) gridDim:(%d, %d, %d)\n", threadIdx.x, threadId...
1,907
#include "includes.h" __global__ void square(float * d_out, float * d_in) { int idx = threadIdx.x ; float f = d_in[idx]; d_out[idx] = f * f; }
1,908
#include <iostream> #include <time.h> #include <random> #include "kernels.cuh" int main() { unsigned int n = 32; // variables instantiations int *h_x; int *d_x; int *h_root; int *d_root; int *h_child; int *d_child; // initiate memory allocation h_x = (int*)malloc(n*sizeof(int)); h_root = (int*)malloc(si...
1,909
extern "C" __device__ void loop_cuda(float *in, float *out, size_t n) { size_t i = blockDim.x * blockIdx.x + threadIdx.x; if (i < n) { out[i] = sqrt(in[i]); } }
1,910
#include <iostream> #include <math.h> __global__ void add(unsigned long long int n, float *x, float *y) { int index = threadIdx.x; int stride = blockDim.x; for(unsigned long long int i = index; i<n; i+= stride) y[i] = x[i]+ y[i]; } int main(void) { unsigned long long int N= 1<<29; float *x , *y; cuda...
1,911
#include <iostream> __global__ void kernel(void) {} // __global__ indicates that the function is to be run on device (GPU) int main(void) { kernel<<<1,1>>>(); // <<<1,1>>> are the arguments passed to the host, the arguments to device will be as usual inside (). printf("Hello, World!\n"); return 0; }
1,912
// RUN: %clang --cuda-host-only -nocudainc -target i386-unknown-linux-gnu -x cuda -E -dM -o - /dev/null | FileCheck --check-prefix HOST %s // RUN: %clang --cuda-device-only -nocudainc -target i386-unknown-linux-gnu -x cuda -E -dM -o - /dev/null | FileCheck --check-prefix DEVICE-NOFAST %s // RUN: %clang -fcuda-approx-tr...
1,913
#include <cstdint> #include <cmath> #include <fstream> #include <iostream> #include <vector> const int BLOCK_SIZE = 1024; class PointSourcePollution { public: PointSourcePollution() = default; ~PointSourcePollution() = default; void end(const double* data, uint64_t cylinder_size); }; void PointSourcePo...
1,914
#include "conv2d.hh" #include "graph.hh" #include "../runtime/node.hh" #include "../memory/alloc.hh" #include "conv2d-input-grad.hh" #include "conv2d-kernel-grad.hh" #include "ops-builder.hh" #include <cassert> #include <stdexcept> #include <cmath> namespace ops { Conv2D::Conv2D(Op* input, Op* kernel, const int s...
1,915
#if GOOGLE_CUDA #define EIGEN_USE_GPU #include <cassert> __device__ inline void swapf(float & a, float & b) { float tmp = a; a = b; b = tmp; } __device__ inline void swap(int & a, int & b) { int tmp = a; a = b ; b = tmp; } __global__ void KnnKernel(int b,const int n,const int d,const float ...
1,916
#pragma once #include <curand_kernel.h> #include <stdio.h> #define _tol 10E-6 typedef float real; //Change this between double or (float) single precision //typedef float3 real3; //Change this between double or (float) single precision struct real3 { real x, y, z; real& operator [] (size_t index) { return *(&...
1,917
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <vector> #include <iostream> #include <chrono> using namespace std; // adds elements of array in place like this for a 11 element array: // [1][1][1][1][1][1][1][1][1][1][1][0][0][0][0][0] // ^+=^ ^+=^ ^+=^ ^+=^ ^+=...
1,918
#include <stdio.h> __global__ void outputFromGPU() { printf("Hello World!!! from GPU.\n"); } int main(void) { printf(":: Ex0 ::\n"); outputFromGPU<<<1,1>>>(); printf("Hello World!!! from CPU.\n"); return 0; }
1,919
#include "includes.h" __global__ void testKernel4r(float *data1, float *data2) { float t = 0.0f; float c = 0.0f; //printf("r = %f\n", data2[NX*blockIdx.x + threadIdx.x]); if(blockIdx.x > 0) { t += (data2[NX*(blockIdx.x-1)+threadIdx.x] - data2[NX*blockIdx.x+threadIdx.x]); c += 1.0f; } if(blockIdx.x < NX-1) { t += (dat...
1,920
__global__ void plus_one_kernel(int num_comp, int *y, int *x){ int i = threadIdx.x + blockDim.x * blockIdx.x; if (i < num_comp){ y[i] = x[i] + 1; } }
1,921
#include "math.h" #include "cuda.h" #include <iostream> const int ARRAY_SIZE = 1000; using namespace std; __global__ void increment(double *aArray, double val, unsigned int sz) { unsigned int indx = blockIdx.x * blockDim.x + threadIdx.x; if (indx < sz) aArray[indx] += val; } int main(int argc, char **argv) {...
1,922
/****************************************************************************** * PROGRAM: copyStruture * PURPOSE: This program is a test which test the ability to transfer multilevel * C++ structured data from host to device, modify them and transfer back. * * * NAME: Vuong Pham-Duy. * College student. * Facult...
1,923
#include <iostream> #include <cuda.h> /* Publish topic GPU code: set an topic array to a value */ __global__ void pub_topic(float *topic,float param) { int i=threadIdx.x; /* find my index */ topic[i]=i+param; } /* Subscribe topic CPU code: get antopic value */ void...
1,924
#include "InitializeComponents.cuh" /** * Sets up a neural network with a specified amount of input and output * neurons with the same number of hidden nodes per layer and the same * activations for each neuron * Parameter layers: the amount of layers in the neural net * Parameter inputNeurons: the number...
1,925
//pass //--blockDim=64 --gridDim=1 --no-inline #include "cuda.h" __global__ void foo(float* A) { A[threadIdx.x == 0 ? 1 : 2*threadIdx.x] = 2.4f; }
1,926
#include "includes.h" __global__ void negative_prob_multiply_csr_matrix_vector_kernel(unsigned int* cum_row_indexes, unsigned int* column_indexes, float* matrix_data, float* in_vector, float* out_vector, unsigned int outerdim) { unsigned int row = blockDim.x * blockIdx.x + threadIdx.x; if (row < outerdim) { float pro...
1,927
#include "includes.h" __global__ void arraySet_kernel(unsigned int* d_vals, unsigned int value, size_t num_vals) { // tIdx = threadIdx.x; unsigned int gIdx = blockIdx.x * blockDim.x + threadIdx.x; if (gIdx < num_vals) d_vals[gIdx] = value; }
1,928
/* Vinh Le CSCI 440 - Parallel Computing Homework 2.1 - count ones in matrix Colorado School of Mines 2018 */ #include <stdio.h> __global__ void countones(int *in, int *out) { __shared__ int temp; unsigned int tid = threadIdx.x; if (in[tid]==1){ atomicAdd(&temp,1); } __syncthreads(); *out = temp; } i...
1,929
#include <iostream> using namespace std; __global__ void MatrixMulKernel(int m, int n, int k, float *A, float *B, float *C) { int Row = blockIdx.y * blockDim.y + threadIdx.y; int Col = blockIdx.x * blockDim.x + threadIdx.x; if ((Row < m) && (Col < k)) { float Cvalue = 0.0; for (int i =...
1,930
//pass //--blockDim=2 --gridDim=2 --no-inline #include <cuda.h> typedef struct __align__(64) { unsigned int tid, bid; } pair; __global__ void align_test (pair* A) { int tid = threadIdx.x; int bid = blockIdx.x; int idx = blockDim.x * bid + tid; A[idx].tid = tid; A[idx].bid = bid; }
1,931
#include "includes.h" /* Modified from https://github.com/zhxfl/CUDA-CNN */ __global__ void matrixTransKernel(float *A, int rows, int cols) { int j = blockIdx.x * blockDim.x + threadIdx.x; int i = blockIdx.y * blockDim.y + threadIdx.y; if (j >= cols || i >= rows) return; float tmp = A[i * cols + j]; A[i * cols + j]...
1,932
#include "FluidGPU.cuh" #include <cmath> #include <cuda_runtime.h> #include <iostream> #include <thrust/sort.h> #include <device_launch_parameters.h> #include <device_functions.h> #include <cuda_runtime_api.h> #include <cuda.h> float kernel(float r) { if (r >= 0 && r <= cutoff) { return 1. / 3.14159 / (powf(cutoff,...
1,933
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #define BLOCKSIZE 32 #define NUM char __global__ void MatMul(int n, NUM *a, NUM *b, int *c){ int tidx = blockDim.x * blockIdx.x + threadIdx.x; int tidy = blockDim.y * blockIdx.y + threadIdx.y; int sum = 0; for(int i = 0; i < n; i++){ sum += a[tidy * n ...
1,934
#include <cuda.h> #include <stdlib.h> #include <stdio.h> #include <time.h> /* To index element (i,j) of a 2D array stored as 1D */ #define index(i, j, N) ((i)*(N)) + (j) /*****************************************************************/ // Function declarations: Feel free to add any functions you want. void se...
1,935
#include "includes.h" __global__ void calculateIntermediates(int n, double *xs, int *cluster_index, int *intermediates0, double *intermediates1, double *intermediates2, int k, int d){ int blocksize = n / 450 + 1; int start = blockIdx.x * blocksize; int end1 = start + blocksize; int end; if (end1>n) end = n; else end ...
1,936
#include "model.cuh" #include <vector> int main(int argc, char* argv[]) { try { Model nn (losses::MSE); nn += new Dense(10,300); nn += new Dense(300, 5); Matrix m(10); std::cout << nn.feed(m); std::vector<Matrix> train_data; std::vector<Matrix> ans; // generate some training data for(int i = 0; i...
1,937
// Modified from // https://github.com/sshaoshuai/Pointnet2.PyTorch/tree/master/pointnet2/src/group_points_gpu.cu #include <stdio.h> #include <stdlib.h> #define THREADS_PER_BLOCK 256 #define DIVUP(m, n) ((m) / (n) + ((m) % (n) > 0)) __global__ void group_points_grad_kernel(int b, int c, int n, int npoints, ...
1,938
#include "includes.h" // risky #define dfloat double #define p_eps 1e-6 #define p_Nsamples 1 // ratio of importance in sampling primary ray versus random rays #define p_primaryWeight 2.f #define p_intersectDelta 0.1f #define p_shadowDelta 0.15f #define p_projectDelta 1e-2 #define p_maxLevel 5 #define p_maxNrays (...
1,939
#include "includes.h" __device__ unsigned int getGid3d3d(){ int blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z) + (threadIdx.y * blockDim.x) + (threadIdx.z * (blockDim.x * blockDim.y)) + threadIdx.x; return threadId; } _...
1,940
#include "includes.h" __global__ void load(int size, const long *in) { const int ix = threadIdx.x + blockIdx.x * blockDim.x; if (ix < size) { } }
1,941
#include<cuda_runtime.h> #include<device_launch_parameters.h> #include<stdio.h> #include<stdlib.h> #include<string.h> __global__ void add(int* d_a,int* d_b,int* d_r,int *d_m) { int n = threadIdx.x; int size = gridDim.x; for(int i = 0;i<(2);i++) { d_r[i*(*d_m)+n] = d_a[i*(*d_m)+n] + d_b[i*(*d_m)+n]; } } int m...
1,942
#include "includes.h" namespace ann { // CUDA2 } __global__ void kernel_calc_gjL_2( int layer_id, int *l, int *s_ext, int *sw_ext, float *z_ext_arr, float *a_ext_arr, float *t_arr, float *gjl_ext, float *w_ext_arr ){ int idx = threadIdx.y + blockDim.y*blockIdx.y; int h = blockDim.x; int pidx = threadIdx...
1,943
// Inner product of 2 vectors #include<iostream> #include<vector> __global__ void vecProd(float *a, float *b, float *c, int N){ int i = blockDim.x*blockIdx.x + threadIdx.x; if (i < N){ c[i] = a[i]*b[i]; } } int main(){ std::vector<float> v1; std::vector<float> v2; std::vector<float> v3; for(auto i = 0; i < 10; i+...
1,944
#include <stdio.h> #include <stdlib.h> #include <time.h> //kernel __global__ void Matmul(float *A,float *B,float *C,int wA,int wC,int hC){ int i = blockDim.x*blockIdx.x+threadIdx.x; int j = blockDim.y*blockIdx.y+threadIdx.y; int k; float tmp = 0.0f; for(k=0;k<wA;k++){ tmp += A[k+j*wC] * B[i+k*hC]; } ...
1,945
#include <stdio.h> #include <iostream> #include <map> #include <string> #include <fstream> #include <vector> using namespace std; #define ll long long const int GRID_SIZE = 1; // Use naive method __device__ bool isPrime(ll n) { if(n<2) return false; for(ll i=2;i*i<=n;i++) if(n%i==0)...
1,946
#include <iostream> #include <bits/stdc++.h> using namespace std; class Stack { private: int Size; int* arr; public: Stack(); ~Stack(); void Append(int x); void Pop(); void Destroy(); void Peek(); void Show(); }; Stack::Stack() : Size(1) { arr = new int[INT_MAX]; } Stack::~Stack(...
1,947
#include "includes.h" /* * Compile: nvcc -o saxby saxby.cu * Run: ./saxby */ __global__ void daxbyAdd(const float *A, const float *B, float *C, float x,int numElements){ int i = blockDim.x * blockIdx.x + threadIdx.x; if(i < numElements){ C[i] = A[i]* x + B[i]; } }
1,948
// Passing array of a Class and assigning elements at odd/even elements to another array. // @alpha74 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #include "stdio.h" using namespace std; class Coord { int x; int y; public: Coord() { x = 0; y = 0; } void set(...
1,949
// sudoku solver sequential execution , using algorithm x , exact cover #include<bits/stdc++.h> #include<cuda.h> #include <algorithm> #include <chrono> #include<iostream> #include <fstream> #include<stdio.h> #include<stdlib.h> #define f first #define s second using namespace std; //using namespace std::chrono; vec...
1,950
#include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/functional.h> int main(int argc, char *argv[]) { thrust::device_vector<int> data(8); data[0] = 6; data[1] = 3; data[2] = 7; data[3] = 5; data[4] = 9; data[5] = 0; data[6] = 8; data[7] = 1; thrust::sort(data.begin(), data.end());...
1,951
#include "includes.h" __global__ void Solve_redblack2_Kernel(float* output, const float* input, int width, int height, int nChannels, int c, const float* weightx, const float* weighty, float lambda, float omega, bool redflag) { int bx = blockIdx.x; int by = blockIdx.y; int tx = threadIdx.x; int ty = threadIdx.y; int x...
1,952
#include<stdio.h> #include<cuda.h> /* Producing twiddle factors */ #define NUM_OF_X_THREADS 10 #define NUM_OF_Y_THREADS 10 __global__ void inputKernel(float *x, int N) { int ix = blockIdx.x * blockDim.x + threadIdx.x; int iy = blockIdx.y * blockDim.y + threadIdx.y; int idx = iy * NUM_OF_X_THREADS + ix...
1,953
#include <math.h> #include <stdio.h> #define TDIM 32 #define RDIM 8 //number of rows in a block __global__ void fast_transpose( double* a, double* b, int N) { //buffer __shared__ double buffer[TDIM][TDIM+1]; int blockIdx_y = blockIdx.x; int blockIdx_x = (blockIdx.x+blockIdx.y)%gridDim.x; int y = ...
1,954
#include <stdio.h> #include <stdlib.h> #include <fstream> /** * Computes the log of reaction rate. * @param a: Pointer to coefficient matrix. * @param temp: Pointer to temperature array. * @param lam: Matrix to write the results to. * @param nsets: Number of sets / number of rows in coefficient matrix. * @param ncells...
1,955
#include "includes.h" __global__ void matrixPolyderNewLayout(const float *coefImg, float *coefImgDer, const int w, const int h, const int m, size_t yOffset){ size_t x = threadIdx.x + blockDim.x * blockIdx.x; size_t y = threadIdx.y + blockDim.y * blockIdx.y; if(x >= w || y >= h) return; size_t xOffsetDer = m-1; size_t ...
1,956
#include <stdio.h> // For the CUDA runtime routines (prefixed with "cuda_") #include <cuda_runtime.h> #include <cuda.h> // Device global variables __device__ double c_x_min; __device__ double c_x_max; __device__ double c_y_min; __device__ double c_y_max; __device__ double pixel_width; __device__ double pixel_height;...
1,957
#include<stdio.h> __global__ void vecAdd(int *c_d,int *a_d,int *b_d) { int idx=threadIdx.x; c_d[idx]=a_d[idx]+b_d[idx]; } int main() { const int N=12; int a_h[N],b_h[N],c_h[N]; for(int i=0;i<12;i++) { a_h[i]=i; b_h[i]=i*2; } //initialize gpu pointer int *a_d,*b_d...
1,958
#include <stdlib.h> #include <cuda.h> #include <stdio.h> #include <malloc.h> __host__ void fill_vector(float *V, int len){ float aux = 5.0; for (int i = 0; i < len; i++) { V[i] = ((float)rand() / (float)(RAND_MAX)) * aux ; } } __host__ void print(float *V, int len){ for (int i = 0; i < len; i++) { p...
1,959
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> __global__ void kernel(void){ printf("hello world from block %d, thread %d\n", blockIdx.x, threadIdx.x); } int main(void){ kernel <<<10, 10>>> (); cudaDeviceSynchronize(); return 0; }
1,960
#include "includes.h" const int Nthreads = 1024, maxFR = 100000, NrankMax = 3, nmaxiter = 500, NchanMax = 32; ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////...
1,961
// tdfc-cuda backend autocompiled body file // tdfc version 1.160 // Fri May 27 17:47:08 2011 #include <stdio.h> __global__ void tdfc_vadd(double cc_a,double* cc_x,double* cc_y,double* cc_z,int N ) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx<N) { { cc_z[idx] = (((cc_a*cc_x...
1,962
#include <cuda_runtime.h> #include <stdio.h> #define CHECK(call)\ {\ const cudaError_t error = call;\ if (error != cudaSuccess)\ {\ printf("Error: %s:%d, ", __FILE__, __LINE__);\ printf("code:%d, reason: %s", error, cudaGetErrorString(error));\ exit(-10 * error);\ }\ }\ void i...
1,963
extern "C" { __global__ void img_reverse(uchar3* d_idata, uchar3* d_odata, int width, int height){ int xIndex = threadIdx.x + blockIdx.x * blockDim.x; int yIndex = threadIdx.y + blockIdx.y * blockDim.y; int idx = yIndex * width + xIndex; if (xIndex < width && yIndex < height){ uchar3 rgb...
1,964
//TEST CASE PASS IN GPU_VERIFY. IT IS NOT VERIFY ARRAY BOUNDS VIOLATION #include <stdio.h> #include <cuda.h> #include <assert.h> #define N 2//64 __global__ void foo(int* p) { int* q; q = p + 1; p[threadIdx.x] = q[threadIdx.x]; }
1,965
#include "includes.h" __global__ void rfi_gpu_kernel(unsigned short *d_input, int nchans, int nsamp) { int c = blockIdx.x * blockDim.x + threadIdx.x; int count =0; float stdev = 1000000.0f; float mean = 0.0f; float sum = 0.0f; float sum_squares = 0.0f; float cutoff = (4.0f * stdev); for(int out=0; out<4; out++) { ...
1,966
#include <stdio.h> #include <assert.h> #include <sys/time.h> #include <math.h> #define MAXIT 360 #define N 1024 #define M 1024 int *lkeepgoing; float *iplate; float *oplate; float *tmp; /* Return the current time in seconds, using a double precision number. */ double When() { struct timeval tp; gettimeof...
1,967
#include <cstdio> // Matrices are stored in row-major order: // M(row, col) = *(M.elements + row * M.width + col) typedef struct { int width; int height; float* elements; bool cpu; } Matrix; Matrix make_cpu(int w, int h){ Matrix m; m.width = w; m.height = h; m.elements = static_cast<f...
1,968
#include <stdio.h> #include <stdlib.h> #include <string.h> __global__ void cuda_xor(char * encrypt, char * key, int numElements, size_t len_key){ int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < numElements){ encrypt[i] = encrypt[i] ^ key[i % len_key]; } } void xor_encrypt(char h_m[], c...
1,969
#include <stdio.h> #include <cuda.h> int main() { int dev_count; cudaDeviceProp dev_prop; cudaGetDeviceCount(&dev_count); printf("the number of cuda device is %d\n",dev_count); cudaGetDeviceProperties(&dev_prop,0); printf("the number of max threads per block is:%d\n",dev_prop.maxThreadsPerBlock); printf("the num...
1,970
#include <stdio.h> #include <iostream> void init(int *a, int N) { int i; for (i = 0; i < N; ++i) { a[i] = i; } } __global__ void doubleElements(int *a, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int stride = gridDim.x * blockDim.x; for (int i = idx; i < N + stride; i += stride) { ...
1,971
#include "includes.h" __global__ void forwardPass1(float* in, float* syn1, float* layer1) { int l = blockDim.x*blockIdx.x + threadIdx.x; int j = blockDim.y*blockIdx.y + threadIdx.y; int Y = 128; atomicAdd(&layer1[l] , in[j] * syn1[j*Y + l]); layer1[l] = 1.0/(1.0 + exp(layer1[l])); }
1,972
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cuda.h> #include <stdlib.h> //#define BLOCK_SIZE 32 #define SIZE 1024*1024 __host__ void SaveMatrixToFile(char* fileName, int* matrix, int width, int height) { FILE* file = fopen(fileName, "wt"); for (int y = 0; y < height...
1,973
#include "includes.h" __device__ __forceinline__ float imag(const float2& val) { return val.y; } __global__ void ForwardWarpKernel_PSF2x2(const float *u, const float *v, const float *src, const int w, const int h, const int flow_stride, const int image_stride, const float time_scale, float *normalization_factor, float ...
1,974
/******************************************************************************* * serveral useful gpu functions will be defined in this file to facilitate * the set calculus toolbox scheme, i.e., to calculate gradients,normal vectors, * curvatures, Heaviside function and Dirac_Delta function *********************...
1,975
#include <stdio.h> #include <iostream> #include <string> #include <stdlib.h> #include <math.h> #include <cuda.h> #include <cmath> #include <fstream> #include <sstream> #define DIM 32 const float PI = 3.14159265358979f; using namespace std; /*************************************************/ class Complex { public: ...
1,976
#include "includes.h" __device__ void check_existance_of_candidate_rows( short *deleted_rows, int *row_group, const int search_depth, int *token, int *selected_row_id, const int total_dl_matrix_row_num) { for (int i = threadIdx.x; i < total_dl_matrix_row_num; i = i + blockDim.x) { // std::cout<<deleted_rows[i]<<' '<<ro...
1,977
#include <stdio.h> __device__ const char *STR = "HELLO WORLD!"; //__constant__ const char *STR = "HELLO WORLD!"; const char STR_LENGTH = 12; __global__ void hello() { printf("%c\n", STR[threadIdx.x % STR_LENGTH]); } int main(void) { int num_threads = STR_LENGTH; int num_blocks = 2; dim3 dimBlock (16,16); dim3 d...
1,978
#include <stdio.h> #include <stdlib.h> #include <time.h> //CUDA RunTime API #include <cuda_runtime.h> //1M #define DATA_SIZE 1048576 #define THREAD_NUM 256 #define BLOCK_NUM 32 #define NUM_THREADS 256 __global__ static void matMultCUDA(const float* a, size_t lda, const float* b, size_t ldb, float* c, size_t ldc, ...
1,979
__global__ void init_kernel(int * domain, int domain_x) { int tx = blockIdx.x * blockDim.x + threadIdx.x; int ty = blockIdx.y * blockDim.y + threadIdx.y; // Dummy initialization domain[ty * domain_x + tx] = (1664525ul * (blockIdx.x + threadIdx.y + threadIdx.x) + 1013904223ul) % 3; } // Reads a cell at (x+dx...
1,980
#include <cstdlib> #include <cmath> #include <iostream> #include <tuple> __global__ void Run(unsigned int *d_force, unsigned int *d_distance, unsigned int *d_output, unsigned int n) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < n) *d_output = d_force[id] * d_distance[id]; } int main(int argc, ch...
1,981
#include<stdio.h> //GPU CODE! __global__ void add(int *a, int *b, int *c){ *c = *a + *b; } //CPU CODE int main(void){ int a, b, c; //host variables int *d_a, *d_b, *d_c; //GPU copies of host variables a = 9; b = 32; int size = sizeof(int); //Allocate space from GPU for host copies cudaMalloc((void **)...
1,982
#include <stdio.h> #include <iostream> #include <cuda.h> #include <cuda_runtime.h> #define N 1024 // 向量中元素的个数。 // 每一个block中线程数量,这样将内核配置参数定义为常量,便于程序的移植和修改。 #define threadsPerBlock 512 /**向量点乘,向量内积运算 * 向量内积运算,就是将多个对应元素的乘法结果累加起来。 * * CUDA 编程中重要概念:归约运算。 * 这种原始输入是两个数组,而输出为一个单一的数值的运算,CUDA 编程称之为归约运算。 */ // Define ke...
1,983
#include <stdio.h> #include <cstdlib> #include "type.cuh" #include "case.cuh" #include "cuda_runtime.h" #include "device_launch_parameters.h" void ObjFuncStat(FILE *fp, IPTR pj, Population *p); void RawStat(FILE *fp, IPTR pj, Population *p); __host__ void PhenoPrint(FILE *fp, IPTR pj, Population *p); void GooguSta...
1,984
#include <cuda_runtime.h> #include <stdio.h> #include <time.h> #include <stdlib.h> #include <sys/time.h> #define N 8388608 #define BLOCK_DIM 256 //Kernel __global__ void reduction(int * in, int * out){ int globalid = blockIdx.x*blockDim.x + threadIdx.x; __shared__ int s_array[BLOCK_DIM]; s_array[threadIdx.x] = i...
1,985
#include <iostream> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/random/linear_congruential_engine.h> #include <thrust/random/uniform_real_distribution.h> // nvcc -arch=sm_70 -std=c++14 exemplo2.cu -o exemplo2 && ./exemplo2 struct random_ex{ thrust::minstd_rand rng; thrus...
1,986
#include <stdio.h> #include <stdlib.h> __device__ int d_value; // Device code: GPU function __global__ void test_Kernel() { int threadID = threadIdx.x; d_value = 1; printf("threadID %-3d d_value%3d\n", threadID, d_value); } // Host code: CPU function int main() { int h_value = 0; // kernelName<<<#block_per...
1,987
// // Created by root on 2020/12/3. // #include "thrust/device_vector.h" #include "thrust/host_vector.h" #include "thrust/iterator/counting_iterator.h" #include "thrust/transform.h" #include "math.h" #include "stdio.h" #define N 64 struct DistanceFrom { float mRef; int mN; DistanceFrom(float ref, int n) ...
1,988
extern "C" #define TILE_LENGTH 128 __global__ void l2(float *v1, float *v2, int n, float *result) { __shared__ float ds_R[TILE_LENGTH]; //int tx = blockIdx.y * blockDim.y + threadIdx.y; int tx = blockIdx.x * blockDim.x + threadIdx.x; float ret = 0.0f; for (int t = 0; t < (n - 1) / TILE_LENGTH + 1; t++) {...
1,989
/* * EzLeftUpdater.cpp * * Created on: 23 янв. 2016 г. * Author: aleksandr */ #include "EzLeftUpdater.h" #include "SmartIndex.h" /* * indx должен пренадлежать участку от [0, sizeY-1] */ __device__ void EzLeftUpdater::operator() (const int indx) { int n = indx; Ez(0, n) = coeff[0]*(Ez(2, n) + EzLeft(0, ...
1,990
#include "includes.h" __global__ void cuda_Shrink_CalU_Vector(float *Y, float *U, float *X, float lambda, float *L1Weight, int nRows, int nCols, int nFilts) { unsigned int Tidx = threadIdx.x + blockIdx.x * blockDim.x; unsigned int Tidy = threadIdx.y + blockIdx.y * blockDim.y, index; float WLambda; float absxV1, X_temp...
1,991
#include "includes.h" __device__ float hard_mish_yashas_grad(float x) { if (x > 0) return 1; if (x > -2) return x + 1; return 0; } __device__ float hard_mish_yashas(float x) { if (x > 0) return x; if (x > -2) return x * x / 2 + x; return 0; } __device__ float mish_yashas(float x) { float e = __expf(x); if (x <= -18.0f)...
1,992
#include <stdio.h> #include <cuda_profiler_api.h> #include <cuda_runtime_api.h> #include <stdlib.h> #include <time.h> #include<sys/time.h> #include<unistd.h> #define cudaCheck(e) do { \ if (cudaSuccess != (e)) { \ fprintf(stderr, "Cuda runtime error in line %d of file %s \ : %s \n", __LINE__, __FILE__, ...
1,993
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #define N 64 #define MAX_ERR 1e-6 __global__ void vector_add(float *out, float *a, float *b, int power) { //int stride = 1; int tid = blockIdx.x * blockDim.x + threadIdx.x; // 0 ...
1,994
#include <stdlib.h> #include <stdio.h> #define L 100 __global__ void kernelcount_nonz(int size, double *A, int *nonz, int *rowptr) { int tid = threadIdx.x, count = 0; for(int i = 0; i < size; i++) { if(A[tid*size + i] != 0.0) { count ++; } } nonz[tid] = count; __syncthreads(); count = 0; for(int i =...
1,995
/* The data set that we are using has 4 attributes but we are using only 2 attributes. Those 2 attributes are 1)Study Time 2) Exam Performance. These 2 attributes will be used to calculate the student's "KnowledgeLevel" KnowledgeLevel can be High or Low in our program but in the data set "KnowledgeLevel" has High, Low ...
1,996
#include "includes.h" __global__ void one_channel_mul_kernel(const float *data_l, const float *data_r, float *result, int channel_total, int total) { int idx = 2 * (blockIdx.x * blockDim.x + threadIdx.x); int one_ch_idx = idx % (2 * channel_total); if (idx / 2 < total) { result[idx] = data_l[idx] * data_r[one_ch_i...
1,997
#include <stdio.h> #include <time.h> #define N 10 float max(float *timer, int n){ int i = 0; float maxTimer=0.0; for( ; i < n ; i ++){ if(timer[i] > maxTimer)maxTimer = timer[i]; } return maxTimer; } void flush(float *a, int n){ int i = 0; for( ; i < n ; i++){ a[i] = 0.0; } } float sum(float *a, int n){ ...
1,998
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <assert.h> /** Max size 1024 */ __global__ void kreduce(unsigned int *vec, int size){ int tid = threadIdx.x; for(int offset=(size/2);offset >= 1;offset /= 2){ if(tid < offset){ vec[tid] += vec[tid+offset]; } __syncthreads(...
1,999
#include <stdio.h> __global__ void helloCUDA(float f) { if (threadIdx.x == 0) printf("Hello thread %d, f=%f\n", threadIdx.x, f) ; } int main() { helloCUDA<<<1, 5>>>(1.2345f); cudaDeviceSynchronize(); return 0; }
2,000
#include <stdlib.h> #include <sys/time.h> #include <stdio.h> #include <cuda.h> #include <math.h> //#define N 1000000 #define SQRT_TWO_PI 2.506628274631000 #define BLOCK_D1 1024 #define BLOCK_D2 1 #define BLOCK_D3 1 // Note: Needs compute capability >= 2.0 for calculation with doubles, so compile with: // nvcc kernelE...