serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
3,801
#include <cstdio> #include <cstdlib> #include <iostream> #include <cassert> constexpr size_t BLOCK_SIZE = 1024; // Размер блока. constexpr size_t SIZE = 2048; // Отдельный компаратор сравнивает пару ключей // и производит обмен соответствующих элементов и // ключей для обеспечения заданного порядка. __device__ void C...
3,802
#include <stdio.h> #include <stdlib.h> #include <fstream> #include <iostream> #include <string> #include <vector> #include "cuda.h" using namespace std; #define BILLION 1E9; __global__ void vecAddKernel(float *A, float *B, float *C, int n){ int i = threadIdx.x+blockDim.x*blockIdx.x; if(i<n) C[i] = A[i]+B[i]; } vo...
3,803
__global__ void test_if() { int a[5]; int x = 4; int y = 5; if (x < 5) { a[x] = 42; a[x + 1] = 42; y = 0; ++x; } a[y] = 42; a[x] = 42; if (x < 5) // unreachable { int z = -1; int local_var = 0; a[z] = 42; // Okay, because unreachable } else { a[x] = 42; } int local_var; a[local_var] = 4...
3,804
/* Example showing the use of CUFFT for fast 1D-convolution using FFT. -KERNEL part separated from original source*/ #include <vector_types.h> // Complex data type typedef float2 Complex; static __device__ inline Complex ComplexScale(Complex, float); static __device__ __host__ inline Complex ComplexMul(Complex, Comp...
3,805
#include <stdio.h> #include <stdlib.h> typedef struct { int size; char *_string; } string_t; __global__ void string_append(string_t*, string_t*, string_t*); int main(void) { int size; string_t *str1_host = (string_t *)malloc(sizeof(string_t)); char _string1[] = "Hello, "; size = sizeof(_string1); str1...
3,806
#include <fstream> #include <iterator> #include <vector> #include <iostream> #include <cstdlib> #include <string> #include <sstream> #include <iomanip> #include <math.h> #include <stdio.h> void getSourceFile(std::vector<double>& eNomVec, std::vector<double>& rangeVec, std::vector<double>& sigmaXVec,std::vector<dou...
3,807
#include "includes.h" __global__ void mkRender(float *fb, int max_x, int max_y) { //MK: Pixel 위치 계산을 위해 ThreadId, BlockId를 사용함 int i = threadIdx.x + blockIdx.x * blockDim.x; int j = threadIdx.y + blockIdx.y * blockDim.y; //MK: 계산된 Pixel 위치가 FB사이즈 보다 크면 연산을 수행하지 않음 if((i >= max_x) || (j >= max_y)){ return; } //MK: FB ...
3,808
#include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void sumaMatrices(int *a, int *b, int *c, int N) { int col = blockIdx.x * blockDim.x + threadIdx.x; int fil = blockIdx.y * blockDim.y + threadIdx.y; int indice = fil * N + col; if(fil<N&&col<N) { c[indice]=a[indice]+b[indice]; } } int main (v...
3,809
#include<iostream> #include<fstream> #include<string> #include<cstdlib> #include<cstring> #include<vector> #include<iterator> #include<ctime> #include<limits> #include<list> #include<algorithm> using namespace std; struct info_edge { int vertex1,vertex2; int edge; }; //This function to extract data from file vo...
3,810
// ================================================================= // // File: intro1.cu // Author: Pedro Perez // Description: This file shows some of the basic CUDA directives. // // Copyright (c) 2020 by Tecnologico de Monterrey. // All Rights Reserved. May be reproduced for any non-commercial // purpose. // // ==...
3,811
#include "includes.h" __global__ void AddAndRefreshConnectionKernel( int node1, int node2, int *activityFlag, int *connection, int *age, int maxCells ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blockDim.x*blockIdx.x //blocks preceeding current block + threadIdx.x; if...
3,812
// Babak Poursartip // 09/14/2020 // Udemy Cuda // unique index calculation #include <cstdio> // =========================================== __global__ void unique_idx_calc_threadIdx(int *input) { int tid = threadIdx.x; printf(" my threadIdx: %d,value: %d \n", tid, input[tid]); } // ============================...
3,813
#include "includes.h" __device__ float sigmoid_derivate(float x){ return __fmul_rn(x, __fsub_rn(1.0f, x)); } __device__ float sigmoid(float x){ return __frcp_rn(__fadd_rn(1, exp(-x))); } __global__ void sigmoidBackward(float* R, float* V, int x, int y){ int index = blockDim.x * blockIdx.x + threadIdx.x; if(index < x*y)...
3,814
/* 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,int var_2,int 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) { comp += var_4 * +1....
3,815
#include <cuda.h> #include <cuda_runtime.h> #include <cufft.h> #include "device_launch_parameters.h" #include <complex> #include <device_functions.h> #include <cuComplex.h> #include <chrono> #include <iostream> #pragma comment(lib,"cufft.lib") using namespace std; __global__ void Complex_mult(cufftComplex * c, const ...
3,816
#include "includes.h" __global__ void __findBoundaries(long long *keys, int *jc, int n, int njc, int shift) { __shared__ int dbuff[1024]; int i, j, iv, lasti; int imin = ((int)(32 * ((((long long)n) * blockIdx.x) / (gridDim.x * 32)))); int imax = min(n, ((int)(32 * ((((long long)n) * (blockIdx.x + 1)) / (gridDim.x * 3...
3,817
/* Simple code to check whether there a working CUDA runtime + driver + GPU device * combination present in the system. * * The expected result of this program is the CUDA runtime and driver API version * printed on the command line and a confirmation that a test kernel has been * successfully executed on the CUDA...
3,818
#include "includes.h" __global__ void blend(float *cmap, float* oldd, float* newd, float weight,int * params) { int ax = blockIdx.x*blockDim.x + threadIdx.x; int ay = blockIdx.y*blockDim.y + threadIdx.y; int ch = params[0]; int ah = params[1]; int aw = params[2]; int slice_a = ah * aw; int pitch_a = aw; // HMM@ HACK...
3,819
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "../../saxpy/saxpy.c" #include <stdio.h> #include <stdlib.h> #include <sys/time.h> //#define DEBUG 0 #define CHECK_ERR(x) \ if (x != cudaSuccess) { \ fprintf(stderr,"%s in %s ...
3,820
#include <iostream> #include <cmath> /* Compile: nvcc test01.cu -o test01 Run: ./test01 Benchmark: nvprof ./test01 */ __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] = x[i] + y[i]; } int main(void){ int N = 1<...
3,821
#include<stdio.h> #include<cuda_runtime.h> #include<device_launch_parameters.h> __global__ void add(int *a,int *b, int *al) { int id=blockIdx.x*blockDim.x+threadIdx.x; b[id] = (*al)*a[id] + b[id]; } int main() { int a[10],b[10],n,al; printf("Enter n: "); scanf("%d",&n); printf("Enter alpha: "); scanf("%...
3,822
/* * hw03p01.cu * * Created on: Oct 02, 2015 * Author: Kazi * Usage: * Basic CUDA program that does some math on a gpu and copies * the data back over to the host. Make sure to compile with the * right parameters for the device as this code does not check * devices to determine capability or anythi...
3,823
#include "kernel.cuh" #include "cuda_runtime.h" #include "device_launch_parameters.h" #define err(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: %s %s %d\n", cudaGet...
3,824
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> using namespace std; float timeMemory(bool pinned, bool toDevice) { const int count = 1 << 20; const int iterations = 1 << 6; const int size = count * sizeof(int); cudaEvent_t start, end; int *h, *d; float elapsed; cudaEr...
3,825
#include "includes.h" __global__ void query_ball_point2_gpu(int b, int n, int m, int nsample, const float *xyz1, const float *xyz2, const float *radii, int *idx, int *pts_cnt) { int batch_index = blockIdx.x; xyz1 += n*3*batch_index; xyz2 += m*3*batch_index; radii += m*batch_index; idx += m*nsample*batch_index; // m cl...
3,826
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #include <sys/time.h> #include <png.h> #include <math.h> #define FILTER_RADIUS 3 // M #define FILTER_AREA ( (2 * FILTER_RADIUS + 1) * (2 * FILTER_RADIUS + 1) ) // (N ^ 2) #define INV_F...
3,827
#include "includes.h" __global__ void Compute_psi_phi_Kernel(float* psi, float* phi, const float* gAbsIx, const float* gAbsIy, const float* gIx, const float* gIy, int nPixels, float norm_for_contrast_num, float norm_for_contrast_denom, float eps) { int bx = blockIdx.x; int tx = threadIdx.x; int x = bx*blockDim.x + tx;...
3,828
#include<stdio.h> #include<cuda.h> #include<cuda_runtime.h> #define BLOCK_NUM 32 //块数量 #define THREAD_NUM 256 // 每个块中的线程数 #define LOOP_N BLOCK_NUM * THREAD_NUM * 1000000 __global__ void leib_pi(double* g_sum) { const int tid = threadIdx.x; const int bid = blockIdx.x; double tmp = 0; int flag = -1; ...
3,829
/** * covariance.cu: This file is part of the PolyBench/GPU 1.0 test suite. * * * Contact: Scott Grauer-Gray <sgrauerg@gmail.com> * Louis-Noel Pouchet <pouchet@cse.ohio-state.edu> * Web address: http://www.cse.ohio-state.edu/~pouchet/software/polybench/GPU */ #include <stdio.h> #include <stdlib.h> #include <mat...
3,830
// Corresponding header file: /include/filter_ops.h #include <cuda_runtime.h> #include <string> #include <math.h> /* * Contains kernels and functions for adding photo filters to the imput image. * apply_filter() function is called to apply the filter with image on GPU and * filter name as parameters. A pointer to t...
3,831
/* Furthest point sampling GPU implementation * Original author: Haoqiang Fan * Modified by Charles R. Qi * All Rights Reserved. 2017. */ __global__ void cumsumKernel(int b, int n, const float* __restrict__ inp, float* __restrict__ out) { const int BlockSize = 2048; const int p...
3,832
__global__ void matrix(float *A, int numElements, int n) { int i = blockDim.x * blockIdx.x + threadIdx.x; int j = blockDim.y * blockIdx.y + threadIdx.y; float a; if (i < n && j< n && i!= (n-1) && i%2==0) { a = A[j*n + i]; A[j*n + i] = A[j*n + i + 1]; A[j*n + i +1] = a; ...
3,833
#include <stdio.h> #define N (2048*2048) #define THREADS_PER_BLOCK 512 void random_ints(int* a, int n) { int i; for (i = 0; i < n; ++i) { a[i] = rand() %5000; } } // indexing an array with one element per thread // M threads per block, a unique index for each thread is given by threadIdx.x + blockIdx....
3,834
/* \file TestDivergentRecursion.cu \author Gregory Diamos <gregory.diamos@gatech.edu> \date Tuesday November 9, 2010 \brief A CUDA assembly test for short-circuiting control flow. */ const unsigned int threads = 512; const unsigned int iterations = 100; __device__ bool out[threads]; __device__ unsigned int di...
3,835
#include "includes.h" __global__ void FindMinSample(float* DistanceBuffer, short2* IndexBuffer, int spread, int mapSizeX, int mapSizeY) { int kOffset = CUDASTDOFFSET; float distance1 = DistanceBuffer[kOffset]; float distance2 = DistanceBuffer[kOffset + spread]; short2 index1 = IndexBuffer[kOffset]; short2 index2 = Inde...
3,836
#include <stdio.h> #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #define N 100 __global__ void kernel(int *a, int *b, int *c) { int globalID = threadIdx.x + blockIdx.x * blockDim.x; printf("globalID = %d\n", globalID); if (globalID < N) c[globalID] = a[globalID] + b[globalID];...
3,837
#include <stdio.h> __global__ void add(int *a, int *b, int *c) { *c = (*a) + (*b); } __global__ void multiply(int *a, int *b, int *c) { *c = (*a) * (*b); } __global__ void subtract(int *a, int *b, int *c) { *c = (*a) - (*b); } __global__ void divide(int *a, int *b, int *c) { *c = (*a) / (*b); } int mai...
3,838
/* ============================================================================ Name : readcalmch.cu Author : Ting-Wen Yu Version : Copyright : Your copyright notice Description : CUDA compute reciprocals ============================================================================ */ #include...
3,839
/** File name: bfs_cpu_stl.cu Author: Yuede Ji Last update: 10:27 10-02-2015 Description: Using stl queue to implement the easiest version of bfs. **/ #include <stdio.h> #include <queue> #include <stdlib.h> #include <string.h> using namespace std; #define N 1025 char filein[] = "/home/yuede/dataset/kron_10_4.d...
3,840
#include "includes.h" #define BLOCK_SIZE 16 #define HEADER_SIZE 122 #define BLOCK_SIZE_SH 18 typedef unsigned char BYTE; /** * Structure that represents a BMP image. */ typedef struct { int width; int height; float *data; } BMPImage; typedef struct timeval tval; BYTE g_info[HEADER_SIZE]; // Reference header ...
3,841
#include <iostream> using std::cout; using std::endl; // kernel declaration __global__ void multiply(float *d_out,float *d_a,float *d_b) { int idx = threadIdx.x + blockIdx.x * blockDim.x; float f = d_a[idx]; float g = d_b[idx]; d_out[idx] = f*g; } // driver code int main() { const int ARRAY_SIZE...
3,842
#include "includes.h" __global__ void cuda_graph_avgpool_bprop(float* gradInput, const float *gradOutput, const float* clusters, const int nClusters, const int poolsize, const int dim, const int nClustersPerThread) { extern __shared__ float shared_mem[]; float* gradOutput_data = (float*)shared_mem; const int tidx = t...
3,843
#include <cuda.h> #include <stdio.h> #include <string.h> __global__ void CountSort(int*, int*, int, int); __host__ void counting_sort(int* arr, int size, int max_val) { int block_num = 1000; int thread_num_per_block = 1000; uint64_t histo_size = sizeof(int)*max_val; printf("size: %d\n", size); printf("max_val: %...
3,844
#include <cuda.h> #include <stdio.h> #define SIZE 10 int main(int argc,char *argv[]){ if(argc<3){ printf("Usage: ./test.cu <ptx_file> <cuda_device>\n"); exit(0); } // Error code CUresult error; int i; // Host variables float *h_A, *h_B, *h_C; h_A = (float *)malloc(sizeof(float)*SIZE); h...
3,845
// Write a CUDA program to compute the sum of an array of elements. Input:Number of elements in the array. Output: Array sum // Error handler was copied from Dr. Rama's colab file shared to us on google classroom #include<stdio.h> #include<stdlib.h> #include<time.h> #define HANDLE_ERROR( err ) ( HandleError( err, _...
3,846
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <cuda_runtime.h> #include <sys/time.h> #include <cuda.h> /* Problem size */ #define NI 4096 #define NJ 4096 void Convolution(double* A, double* B) { int i, j; double c11, c12, c13, c21, c22, c23, c31, c32, c33; c11 = +0.2; c21 = +0.5; c31 = -...
3,847
// Copyright (c) Megvii Inc. All rights reserved. #include <math.h> #include <stdio.h> #include <stdlib.h> #define THREADS_PER_BLOCK 256 #define DIVUP(m, n) ((m) / (n) + ((m) % (n) > 0)) __global__ void voxel_pooling_forward_kernel(int batch_size, int num_points, int num_channels, int num_voxel_x, ...
3,848
#include <cuda_runtime.h> #include <stdio.h> void initialInt(int *ip, int size){ for(int i = 0; i<size; i++){ ip[i] = i; } } void printMatrix(int *C, const int nx, const int ny){ int *ic = C; printf("\n Matrix: (%d, %d) \n", nx, ny); for (int iy = 0; iy < ny; iy++){ for(int ix = 0; ix < nx; ix++){ ...
3,849
#include <stdio.h> #include <sys/time.h> #define A 0.1234 #define TPB 256 #define INITIAL_N 10000 #define FINAL_N 100000000 #define EPSILON 1e-5 // #define ARRAY_SIZE 10000 int ARRAY_SIZE = INITIAL_N; // Get the current time double cpuSecond() { struct timeval tp; gettimeofday(&tp,NULL); return ((double)tp.tv_...
3,850
#include "includes.h" __global__ void vectorAddKernel(float* A, float* B, float* Result) { // insert operation here int i = threadIdx.x + blockDim.x * blockIdx.x; Result[i] = A[i] + B[i]; }
3,851
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <string.h> #include <limits.h> #include <stdbool.h> #define MAX_EDGE 100000000 #define MAX_NODE 1000000 __device__ volatile int Cx[MAX_NODE]; __global__ void A_star(int* off,int* edge,int* W,int* Hx,int* P,int* PQ,int* PQS,int* L,int* nextFlag,int...
3,852
__global__ void vecAdd(float *l, float *r, float *result, size_t N) { size_t i = threadIdx.x; LABEL: if (l[i] > i) { result[i] = exp(l[i]); } else { LABEL1: result[i] = acosf(l[i]); } if (i < 5) { ++i; l[i] = r[i] / 2.0; r[i] = r[i] / 2.0; if (l[i] - r[i] > 2.0) { goto LABEL1; ...
3,853
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define VECTOR_SIZE 655360 #define TILE_DIM 1024 #define COMP_ITERATIONS 1024000 __global__ void simpleKernel(float *A, float *C1, int size, int compute_iters, int tile_dim) { int xIndex = blockIdx.x * tile_dim + threadIdx.x; float ra, rb, rc, rd; ...
3,854
/** * @file strongestNeighborScan.cu * @date Spring 2020, revised Spring 2021 * @author Hugo De Moraes */ #include <stdio.h> #include <stdlib.h> /** * Scans input in parallel picks two elements with a stride s, checks if these two elements are in the same segment; * if so, it compares the two elements, store th...
3,855
// includes, system #include <stdio.h> #include <assert.h> #include <iostream> #include <cuda_runtime.h> // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char* msg); // implement the kernel using global memory __global__ void reverseArray(int *d_out, int *d_in, int n){ int i =...
3,856
#include <iostream> #include <cuda.h> __global__ void glob() { return; } int main() { float time; cudaEvent_t start; cudaEvent_t stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); glob<<<13, 128>>>(); cudaEventRecord(stop, 0); cudaEventSynchro...
3,857
#define DP_BLOCKSIZE 512 __global__ void kReflectH(float * imgs, float * targets, const int imgSize, const int numCases, int numColors, int imgsPerThread, bool checkCaseBounds) { const int pxIdx = blockIdx.y * 4 + threadIdx.y; const int imgPixels = imgSize * imgSize; if (pxIdx <...
3,858
#include "includes.h" __global__ void MatMulKernel(float *Md, float *Nd, float *Pd, int width) { // Thread row and column within matrix int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; // Each thread computes one element of P // by accumulating results into Pvalue float...
3,859
#include <iostream> #include <cmath> #include <algorithm> using namespace std; __global__ void RowOperation1(float* matrix_cu,int* rank_cu,float* inverse_cu, int* dim) { int i = threadIdx.y + blockDim.y * blockIdx.y; int j = threadIdx.x + blockDim.x * blockIdx.x; float pivot_cu = matrix_cu[i + dim[0] * rank_cu[0]]; ...
3,860
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> #include <string.h> int main() { cudaDeviceProp prop; int dev; int stat; int count; int i; cudaGetDeviceCount(&count); // count is updated with No. of GPU-s. for (i = 0; i < count; i++) { cudaGetD...
3,861
#include "WaveEquationKernels.cuh" __global__ void WaveEquation_kernel(float3* slice1, float3* slice2, float3* slice3, unsigned int gridSize, float deltaTime) { unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < (gridSize * gridSize)) { unsigned int x = i / gridSize; unsigned...
3,862
#include "includes.h" __global__ void downSampleKernel(unsigned char * d_in, unsigned char * d_out, size_t skip) { size_t i = threadIdx.x; // Assuming 3 channels BGR and averaging int px = d_in[i * skip * 3] + d_in[i * skip * 3 + 1] + d_in[i * skip * 3 + 2]; d_out[i] = px / 3; }
3,863
#include "includes.h" __global__ void findPartIndicesKernel(int size, int *array, int *partIndices) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < size) { int value = array[idx]; int nextValue = (idx != size - 1) ? array[idx + 1] : -1; if (value != nextValue) { partIndices[value + 1] = idx + 1; } } }
3,864
#include "includes.h" __global__ void _bcnn_backward_depthwise_sep_conv_data_kernel(int nthreads, float *dst_grad, float *weight_data, int batch_size, const int channels, int dst_h, int dst_w, const int src_h, const int src_w, int kernel_sz, int stride, int pad, float *src_grad) { int i, n, c, h, w, kw, kh, h_out_s, w...
3,865
//============================================================================ // Name : parallelization1.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #...
3,866
#include "includes.h" __global__ void ApplyMat5(float* input, float* output, float* matrix){ int id = threadIdx.x + blockDim.x * blockIdx.x; for (int i = 0; i < 296; ++i){ float total = 0.0f; total += input[id * 300 + i] * matrix[0]; total += input[id * 300 + i + 1] * matrix[1]; total += input[id * 300 + i + 2] * matr...
3,867
#include <iostream> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/reduce.h> int main(int argc, char *argv[]) { int n = atoi(argv[1]); thrust::host_vector<int> h_vec(n, 1); thrust::device_vector<int> d_vec(n); thrust::copy(h_vec.begin(), h_vec.end(), d_vec.begin()); cuda...
3,868
#include "includes.h" // CUDA kernel to add elements __global__ void add(int N, float *x) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i<N) x[i] = x[i] *2; }
3,869
#include <thrust/device_vector.h> #include <thrust/transform.h> #include <thrust/sequence.h> #include <thrust/copy.h> #include <thrust/fill.h> #include <thrust/replace.h> #include <thrust/functional.h> #include <iostream> using namespace std; #define N 10 int main() { thrust::device_vector<int> X(N); thrust::device...
3,870
#include <iostream> #include <math.h> #include <ctime> #include <cmath> #include <stdlib.h> #include <fstream> #include <sstream> double density(double Xold, double Xnew, double sigma, double r, double delta, double delta_t); double* three_dim_index(double* matrix, int i, int j, int k, double m, int b); double kah...
3,871
/* * Rectangular matrix multiplication * A[M][K] * B[k][N] = C[M][N] * */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/timeb.h> #include <string.h> /* read timer in second */ double read_timer() { struct timeb tm; ftime(&tm); return (double) tm.time + (double) tm.millitm / 100...
3,872
#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); } void printMatrix(float *C, const int nx, const int ny) { float *ic = C; //бережем оригинальный массив от изменения f...
3,873
#include "cuda_runtime.h" #include "cuda.h" #include "device_launch_parameters.h" #include "stdio.h" using namespace std; __global__ void mykernel() { printf("Hello World!"); } int main(){ mykernel <<< 1,1>>> (); return 0; }
3,874
/* File: matmult-cuda-float.cu * * Purpose: * * Input: * * Output: * * Compile: nvcc -o matmult-cuda-float.o matmult-cuda-float.cu * * Run: ./matmult-cuda-float.o * * Algorithm: * * Note: * * */ #include <stdio.h> #include <cuda_runtime.h> __global__ void VecAdd(float* A, float* B, float* C, i...
3,875
#include "includes.h" __global__ void hsv2rgb(float *inputH, float *inputS, float *inputV, uchar3 *output, int width, int height) { int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; int tid = y*width + x; if (x<width){ if (y<height){ float H = inputH[tid]; float S = inp...
3,876
#include <iostream> #include <math.h> #include <sys/time.h> #include "cudaDmy.cuh" #include <cuda.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cuda_runtime_api.h> #include <fstream> #include <map> #include <set> #include <string> #include <vector> #include <iterator> #include <algorithm...
3,877
extern "C" { __global__ void vectorAdd(const float *a, const float *b, float *c, int num) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < num) { c[i] = a[i] + b[i]; } } __global__ void initImage(unsigned char *data, int cols, int rows) { int x = threadId...
3,878
#include <algorithm> #include <cassert> #include <cstdlib> #include <iostream> #include <vector> /* 1-D convolution kernel Arguments : array = padded array mask = convolution array result = result array n = number of elements in array m = number of elements in the mask */ __global__ void convolu...
3,879
// 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...
3,880
#include <stdio.h> #include <cuda_runtime.h> #include <float.h> __device__ void swap(float *a, float *b) { float tmp = *a; *a = *b; *b = tmp; } extern __shared__ float BlockShMem[]; __global__ void CUDAJacobi(float *Aptr, float *Zptr, const unsigned int *Mptr, const int Nmat) { const int N = sqrtf(Mptr[blockIdx.x...
3,881
// David Ramirez A01206423 #include <stdio.h> #include <stdlib.h> #include "cuda_runtime.h" #define N 10 #define M 10 #define WIDTH 2 // Device mat mult __global__ void MatrixMul(float *darray_1, float *darray_2 , float *dres_arr, int n){ // cols and rows definition int col = threadIdx.x + blockIdx.x * blockDim.x...
3,882
#include <cmath> using namespace std; // ][ -> *n+ __device__ void ludcmp(float* a, int* indx, float &d) { const float TINY=1.0e-20; int i,imax,j,k; float big,dum,sum,temp; const int n = 5; float vv[n]; d=1.0; for (i=0;i<n;i++) { big=0.0; for (j=0;j<n;j++) if ((temp=fabs(a[i*n+j])) > big) big=temp; // ...
3,883
/* Ising model: Halmitonian H = /sum_ij J(sigma_i)(sigma_j) */ /* * TODO: * 1. Calculate the energy in the program * 2. Calculate the heat capacity in the program * 3. Add more inputs to adjust the length of lattice * 4. A matlab code to plot data. * data format example: * position.x ...
3,884
__device__ __constant__ int constNumber[4] = {1,2,3,4};
3,885
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> #define DATA_SIZE 1048576 int data[DATA_SIZE]; static void GenerateNumbers(int *number, int size) { for(int i = 0; i < size; i++) { number[i] = rand() % 10; } return; } static void print_device_prop(const cudaDeviceProp &prop) { ...
3,886
#include <stdio.h> #include <stdlib.h> #define N 512 void random_ints(int* a, int size){ for(int i =0; i<size; i++) a[i]=rand()%1000; } __global__ void addVecs(int *c, int *a, int *b){ int index = threadIdx.x + blockIdx.x * blockDim.x; c[index] = a[index]+b[index]; } int main(void){ int *a, *b, *c; ...
3,887
/** * This file defines vector operations to simplify code elsewhere. */ // Versions of make_x() that take a single value and set all components to that. inline __device__ int2 make_int2(int a) { return make_int2(a, a); } inline __device__ int3 make_int3(int a) { return make_int3(a, a, a); } inline __devi...
3,888
/***************************************** Project 3 James Albu, Rebecca Johnson, Jacob Manfre GPU Radix Sort Algorithm *******************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #define MAX 2147483647; //largest 32bit signed integer //#define M...
3,889
#include "includes.h" __global__ void gaussKde1D ( const int dim, const int nd, const int nb, const int Indx, const float *hh, const float *a, const float *b, float *pdf ) { int i = threadIdx.x + blockDim.x * blockIdx.x; int j = threadIdx.y + blockDim.y * blockIdx.y; int ij = i + j * nb; float h; if ( i < nb && j < nd ...
3,890
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define STAR -1 struct timeval start, end; void load_csv(int*data, char *csv_file, int rows, int cols, int cols_t){ FILE* file = fopen(csv_file, "r"); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { ...
3,891
#include "includes.h" __global__ void computeGradientCentralDiff(const float* similarities, float* gradient, int* activeMask, int activeSlices, int slices, int p) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i >= activeSlices) return; int slice = activeMask[i]; float dx = similarities[slice] - similarities[sli...
3,892
extern "C" { #define FLT_MIN 1.175494351e-38F #define FLT_MAX 3.402823466e+38F __global__ void separateChannels(const uchar4* const inputImageRGBA, int numRows, int numCols, float* const redChannel, ...
3,893
#include "includes.h" __global__ void kern_DivideBuffers(float* dst, float* src, const int size) { int idx = CUDASTDOFFSET; float value1 = src[idx]; float value2 = dst[idx]; float minVal = value2 / value1; if( idx < size ) { dst[idx] = minVal; } }
3,894
#include<stdio.h> __global__ void helloFromGPU(){ printf("Hello World from GPU: %d\n",threadIdx.x); } int main(void){ helloFromGPU<<<1,10>>>(); cudaDeviceReset(); //cudaDeviceSynchronize(); return 0; }
3,895
#include "includes.h" __global__ void addScannedBlockSums(float *input, float *aux, int len) { int tx = threadIdx.x; int bx = blockIdx.x; int dx = blockDim.x; int i = 2 * bx * dx + tx; if (bx > 0) { if (i < len) aux[i] += input[bx-1]; if (i + dx < len) aux[i + dx] += input[blockIdx.x - 1]; } }
3,896
__device__ int xorShift(int seed) { seed ^= seed << 13; seed ^= seed >> 17; seed ^= seed << 5; return seed; } /* dropout probability is 1 - keep probability and should be less than 1. seed + 2147483648.0: [0, 2^32/2 + 2^32/2-1 = 4294967295] (seed + 2147483648.0) / 4294967295.0: [0 to 1]...
3,897
//////////////////////////////////////// // 2D Quadrature Rules //////////////////////////////////////// // order goes (r1, s1, w1, r2, s2, w2, ...) // 1 point double quad_2d_degree1[] = {0.333333333333333, 0.333333333333333, 1.0}; // 3 points double quad_2d_degree2[] = {0.166666666666666, 0.166666666666666, 0.3333333...
3,898
#include <cmath> #include <cstdlib> #include <cstdio> #include <chrono> using namespace std; #define num_devs 4 __global__ void cudamatmul(float *A, float *B, float *C, int N) { int i = blockIdx.y; int j = threadIdx.x + blockDim.x * blockIdx.x; float sum = 0.0f; extern __shared__ float A_s[]; for (int ks=0;...
3,899
#include <stdlib.h> #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda_runtime.h> #include <sys/time.h> #include <time.h> const int listLength = 700; __global__ void squareKernel(float* d_in, float *d_out, int threads_num) { const unsigned int lid = threadIdx.x; // local id insi...
3,900
#include "cell.cuh" #include <stdlib.h> #include <stdio.h> __host__ __device__ Cell::Cell(){ // Cell Geometry pi = 2*acos(0.0); // future function "initial conditions" V = -8.12e1; // mV h = 9.65e-1; d = 1.37e-4; xr = 3.29e-5; Nai = 1.12e1; // Initial Intracellular Na (mM) Ki = 1.3...