serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
19,401
#include <cuda_runtime.h> #define REGISTER_BLOCKING 4 #define BLOCK_SIZE 64 __global__ void matmult_gpu4Kernel(int m, int n, int k, double * d_A, double * d_B, double * d_C); // REGISTER BLOCKING ALONG THE ROWS OF C /* extern "C" { void matmult_gpu4(int m, int n, int k, double * A, double * B, double * C){ double *...
19,402
#include<iostream> #include<ctime> #define exp 20 #define Size 512 using namespace std; struct AoS{ float x,y; }; void __global__ AoS(AoS* data,unsigned int n) { unsigned int idx = threadIdx.x + blockDim.x * blockIdx.x; if (idx < n) { data[idx].x += 1.0f; data[idx].y += 2.0f; } } int main() { int dev ...
19,403
#include <iostream> #include "cuda_runtime_api.h" int main(int argc, char* argv[]) { (void)argc; (void)argv; cudaSetDevice(0); cudaEvent_t start; cudaEvent_t end; cudaEventCreate(&start); cudaEventCreate(&end); cudaEventRecord(start); cudaEventRecord(end); cudaEventSynchronize(end); float elapse...
19,404
#include "includes.h" __global__ void MatrixMulKernel(float *d_M, float *d_N, float *d_P,int width){ int Row = blockIdx.y*blockDim.y + threadIdx.y; int Col = blockIdx.x*blockDim.x + threadIdx.x; if ((Row < width)&&(Col < width)){ float Pvalue = 0; for (int i = 0; i < width; ++i){ Pvalue += d_M[Row*width+i]*d_N[i*width...
19,405
#include "includes.h" __device__ void recover_deleted_rows(short *deleted_rows, const int search_depth, const int total_dl_matrix_row_num) { for (int i = threadIdx.x; i < total_dl_matrix_row_num; i = i + blockDim.x) { if (abs(deleted_rows[i]) > search_depth || deleted_rows[i] == search_depth) { deleted_rows[i] = 0; } }...
19,406
__global__ void test_input_args(int* buffer_arg, int x) { int val = buffer_arg[1]; buffer_arg[2] = 42; buffer_arg[x] = 42; buffer_arg[x + 1] = 42; x = 1; buffer_arg[x] = 42; }
19,407
#include "includes.h" using namespace std; #define ULL unsigned long long const long MAXDIM = 10; const double RMIN = 2.0; const double RMAX = 7.0; #define MAX_THREADS 1024 #define MAX_BLOCKS 65535 //Global kernel code that runs on the device __global__ void count_in(ULL *dev_count, long dev_ntotal,long dev_nd...
19,408
#include <iostream> #include <cstdlib> #include <ctime> #include <string> #include <cuda_runtime.h> #include <chrono> using namespace std; using namespace chrono; const int MAX_TRIES = 5; #define WORD_SIZE 1048576 void init_zero(int* a, int n) { for (int i = 0; i < n; i++) a[i] = 0; } void init_null(char* a, in...
19,409
#include "includes.h" __device__ __forceinline__ size_t gpu_scalar_index(unsigned int x, unsigned int y) { return NX*y+x; } __global__ void gpu_efield(double *fi, double *ex, double *ey){ unsigned int y = blockIdx.y; unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; unsigned int xp1 = (x + 1) % NX; unsigned int yp...
19,410
#include <cuda_runtime.h> //uchar4 __global__ void split_channels(uchar4 *input_image, unsigned char *red, unsigned char *green, unsigned char *blue){ int row = threadIdx.x; int col = blockIdx.x; int idx = col + row*360; red[idx] = input_image[idx].x; green[idx] = input_image[idx].y; blue[idx]...
19,411
#include "cuda_runtime.h" void initialize_cuda_runtime(void) { cudaSetDevice(0); cudaFree(0); }
19,412
#include <iomanip> #include <iostream> #include <string> const long int GLOBAL_SIZE = 1024; const int TILE_DIM = 32; const int BLOCK_ROWS = 8; const int NUM_ITERS = 100; __global__ void copy(float* A, float* B) { int row = blockIdx.y * blockDim.x + threadIdx.y; int col = blockIdx.x * blockDim...
19,413
#include "includes.h" __global__ void cuArraysCopyToBatch_kernel(const float2 *imageIn, const int inNX, const int inNY, float2 *imageOut, const int outNX, const int outNY, const int nImagesX, const int nImagesY, const int strideX, const int strideY) { int idxImage = blockIdx.z; int outx = threadIdx.x + blockDim.x*block...
19,414
#include <stdio.h> #include <cuda.h> #include<sys/time.h> #include <time.h> #include<math.h> // Kernel that executes on the CUDA device __global__ void square_array(float *a, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx<N) a[idx] = sqrtf(powf(2,a[idx]) + powf(a[idx],3)); } // main routi...
19,415
#include "includes.h" // ERROR CHECKING MACROS ////////////////////////////////////////////////////// __global__ void computeStateMinMax(int noControls, int noDims, int noPaths, int* dataPoints, float* xvals, float* xmins, float* xmaxes) { for (int ii = 0; ii < noControls; ii++) { float *xmin, *xmax; xmin = (float*)...
19,416
#include<stdlib.h> #include<stdio.h> #include<unistd.h> #include<sys/time.h> #include<math.h> #include<iostream> struct Particle{ float px; float py; float pz; float vx; float vy; float vz; }; typedef struct timeval tval; double get_elapsed(tval t0, tval t1); void get_input_data(struct Partic...
19,417
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda.h> #include <cuda_runtime.h> #include <cuda.h> #include <device_launch_parameters.h> #define LIST_SIZE_GLOBAL 3000000 #define LIST_SIZE 10000 extern "C" __device__ unsigned long long load_store_index[LIST_SIZE]; extern "C" __...
19,418
#include <iostream> using namespace std; __global__ void SumaColMatrizKernel(int f,int c,float*Md,float*Nd){ float Pvalue=0; for(int k=threadIdx.x;k<f*c;k+=c){ Pvalue=Pvalue+Md[k]; } Nd[threadIdx.x]=Pvalue; } void SumaColMatrizHost(int f,int c,float*Mh){ float *P; P=new float[c]; for (int j=0;j<c;j++){ P[j...
19,419
// Jin Pyo Jeon // Assign 7 #include <cuda.h> #include <stdlib.h> #include <time.h> #include <stdio.h> #include <math.h> #include <assert.h> #define T 1024 // Shared needs to be known at compile time?? #define B 65536 #define TB (B / T) #define N (134217728) // Times for Reduced and non-reduced dot product // N Red...
19,420
#include <math.h> __device__ size_t calculateGlobalIndex() { // Which block are we? size_t const globalBlockIndex = blockIdx.x + blockIdx.y * gridDim.x; // Which thread are we within the block? size_t const localThreadIdx = threadIdx.x + blockDim.x * blockIdx.y; // How big is each block? size_t...
19,421
// // Created by Anikait Singh on 2019-08-01. // for interpolation // //arr[i][j] to arr[j][i] //r is rows //c is columns //static double transposeLookup2D(double *arr, int i, int j, int r, int c) { // return arr[j * r + i]; //} //arr[i][j][k][l] to arr[l][k][j][i] //s1,s2,s3,s4 is size of i, j, k, l respetively ...
19,422
#include "includes.h" __global__ void transpose(int N, double *A) { int row,col,k; double temp; k = (blockIdx.y*gridDim.x+blockIdx.x)*(blockDim.x*blockDim.y)+(threadIdx.y*blockDim.x+threadIdx.x); row = k/N; col = k - row*N; if(row<col){ temp = A[row*N+col]; A[row*N+col] = A[col*N+row]; A[col*N+row] = temp; } }
19,423
#include <stdio.h> #include <stdlib.h> #define N 10 // ( N )x( N ) matrix containing data // The idea with an aligned array is that the GPU will perform better if you pad // it's data array so that it can fit better in cache. CUDA accomplishes this // with the cudaMallocPitch() call. pitch (of type size_t) is the nu...
19,424
#include <stdio.h> #define N 10 __global__ void add(int *a, int *b) { int i = blockIdx.x; printf("Hello cuda from thread %d\n", i); b[i] = 2*a[i]; } int main() { int ha[N], hb[N]; int *da, *db; cudaMalloc((void **)&da, N*sizeof(int)); cudaMalloc((void **)&db, N*sizeof(int)); for (int i = ...
19,425
// file esempio sommavettore_gpu with herror handling #include "stdio.h" #define N 32 // 100 #define NumThPerBlock 32 //256 #define NumBlocks 1 static void HandleError( cudaError_t err, const char *file, int line) { if (err != cudaSuccess) { printf("%s in %s at line %d\n", cudaGetErrorString( err ), file, line)...
19,426
#include <stdio.h> #include <stdlib.h> #include <time.h> __device__ float ed1D(float *x, float *y, int K){ int i; float d=0; for(i=0;i<K;i++) d += pow((x[i] - y[i]), 2); return sqrt(d); } __device__ float ed2D(float *x, float *y, int T, int K){ int i; float d=0; for (i =0; i < T; i++){ d += ed1D(&x[i...
19,427
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> int main() { cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, 0); printf("Device name : %s\n", deviceProp.name); printf("Total global memory : %d MB\n",deviceProp.totalGlobalMem / 1024 / 1024); print...
19,428
#include <iostream> #include <cuda.h> #include <cuda_runtime.h> typedef unsigned int uint; // O kernel processará o espaço do bloco, eliminando todos os múltiplos de k __global__ void sieve(uint* d_array, uint k) { int idx = threadIdx.x + (32 * blockIdx.x); if ( (d_array[idx] % k) == 0) { d_array...
19,429
float h_A[]= { 0.9082878423605707, 0.689461402011782, 0.5463360405647449, 0.505607877073731, 0.7714555565241021, 0.7929819094507726, 0.6788033919030121, 0.5687240568421572, 0.8389623664839443, 0.634043583652253, 0.9457857509154202, 0.7519147147958488, 0.9843117506047065, 0.9676874072673204, 0.798158570093222, 0.9318072...
19,430
#include "includes.h" __global__ void set_with_value_util_kernel( float4 * __restrict buf, float v, int elem_count) { int elem_id = blockDim.x * blockIdx.x + threadIdx.x; if (elem_id < elem_count) { float4 val; val.x = v; val.y = v; val.z = v; val.w = v; buf[elem_id] = val; } }
19,431
//===================================================================== // MAIN FUNCTION //===================================================================== void kernel_fin(float *initvalu, int initvalu_offset_ecc, int initvalu_offset_Dyad, int initvalu_offset_SL, int initvalu_offset_Cyt, float *parameter, floa...
19,432
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void addElement(int *a,int *b,int *t) { int v = threadIdx.y; int n = v*blockDim.x+threadIdx.x; t[n] = a[n]+b[n]; } __global__ void addCol(int *a , int *b , int *t) { int lp =0; int ...
19,433
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BLOCKS 1024 #define THREADS 1024 #define SIZE BLOCKS*THREADS*16 void print(int *vec){ for(int i = 0; i < SIZE; i++) printf("%d ", vec[i]); printf("\n"); } int *get_vector(int n){ int *res = (int *) malloc(sizeof(int) * n); for(int i = 0; i < n;...
19,434
/****************************************************************************** * * XXXII Heidelberg Physics Graduate Days - GPU Computing * * Gruppe : TODO * * File : main.cu * * Purpose : n-Body Computation * ****************************************...
19,435
#include <algorithm> #include <cassert> #include <cstdlib> #include <functional> #include <iostream> #include <vector> #include <chrono> using namespace std; const int M = 1 << 3; //8 const int N = 1 << 3; const int K = 1 << 3; const int SHMEM_SIZE = 1 << 3; //4 __global__ void matrixMul(const int *a, con...
19,436
// Ceres Solver - A fast non-linear least squares minimizer // Copyright 2022 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of so...
19,437
/* compile $ nvcc -o matrix_elementwise matrix_elementwise.cu elementwise multiplication and subtraction numpy version import numpy as np m1 = np.array(((0, 1, 2), (3, 4, 5), (6, 7, 8))) m2 = np.array(((8, 7, 6), (5, 4, 3), (2, 1, 0))) m1*m2 # or np.multiply(m1, m2) m1-m2 */ #include <stdio.h> #include <cuda....
19,438
/* Mnozenie macierzy CUDA, Jakub Ciechowski GPU 2012 */ #include <cuda.h> #include <stdio.h> #include <stdlib.h> #define TILE_WIDTH 2 __global__ void sharedMul(int *M, int *N, int *P, int width) { __shared__ int Ms[TILE_WIDTH][TILE_WIDTH]; __shared__ int Ns[TILE_WIDTH][TILE_WIDTH]; int bx = blockIdx.x; in...
19,439
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <inttypes.h> #define ErrorCheck(ans) { CheckFun((ans), __FILE__, __LINE__); } inline void CheckFun(cudaError_t code, const char *file, int line) { if (code != cudaSuccess) { ...
19,440
extern "C" { __global__ void binaryentropy_32(const int lengthX, const float *x, const float *y, float *z) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i<lengthX) { z[i] = x[i]*log(x[i]/y[i])+ (1.0-x[i])*log((1.0-x[i])/(1.0-y[i])); } } }
19,441
#include <cuda.h> #include <math.h> #include <iostream> using namespace std; __global__ void convStandard(uint32_t* d_MATDIM, uint32_t* d_KERDIM, double* mat, double* ker, double* res) { uint32_t MATDIM = d_MATDIM[0]; uint32_t KERDIM = d_KERDIM[0]; uint32_t threadID = blockIdx.x * blockDim.x + threadIdx.x; if (t...
19,442
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #define NUM 32 #define CUDA_ERROR_EXIT(str) do{\ cudaError err = cudaGetLastError();\ if( err != cudaSuccess){\ printf("Cuda Error: '%s' for %...
19,443
#include <device_launch_parameters.h> #include <cstdio> extern "C" { // PUT YOUR KERNEL FUNCTION HERE __global__ void bfs_visit_next( int* adjacencyList, int* edgesOffset, int* edgesSize, int* distance, int* parent, int* currentQueue, int* nextQueue, ...
19,444
#include <iostream> #include "../include/gpu_queue.h" #include <thrust/device_vector.h> #define def_dvec(t) thrust::device_vector<t> #define to_ptr(x) thrust::raw_pointer_cast(&x[0]) using namespace std; const int MAX_QUEUE_SIZE = 50; __global__ void test(float *output){ gpu_queue<float, MAX_QUEUE_SIZE> que; f...
19,445
#include <iostream> #include <chrono> void Run(int particlesCount, int blockSize, float3 *hostPositions, float deltaTime, float softeningRate, int iterationsCount, bool validate = false); float3 *GenerateParticles(int particlesCount) { auto *positions = new float3[particlesCount]; for (int i = 0; i < particl...
19,446
#include "includes.h" extern "C" { #ifndef REAL #define REAL float #endif } __global__ void ge_set (const int sd, const int fd, const REAL val, REAL* a, const int offset_a, const int ld_a) { const int gid_0 = blockIdx.x * blockDim.x + threadIdx.x; const int gid_1 = blockIdx.y * blockDim.y + thread...
19,447
#include<stdio.h> #include<cuda.h> __global__ void hwkernal(){ printf("hello world\n"); } int main(){ hwkernal<<<1,5>>>(); cudaThreadSynchronize();; }
19,448
#include "includes.h" __global__ void kernelF(const float *d_xAx, const float *d_bx, const float *d_c, float *d_y) { *d_y = *d_xAx + *d_bx + *d_c; }
19,449
#include<iostream> #include<cstdlib> using namespace std; __global__ void vectorAdd(int *a, int *b, int *result, int n) { int tid = blockIdx.x*blockDim.x + threadIdx.x; if(tid <= n) { result[tid] = a[tid] + b[tid]; } } void print_array(int *a, int N) { for(int i=0; i<N; i++) { cout<<" ...
19,450
__device__ float giveFloat(){ return 3.2;}
19,451
#include <stdio.h> #include "kernelMedianFilter.cu" #define BNX 16 #define BNY 16 #if defined Zero #define KER "kernelFilterZero" #elif defined Shrink #define KER "kernelFilterShrink" #elif defined Extend #define KER "kernelFilterExtend" #else #define KER "kernelFilterDiscard" #endif #ifdef Bubble #define MDN "media...
19,452
#include <stdio.h> #include <stdlib.h> #include <time.h> #define CLOCKS_PAR_SEC 1000000l #define N 256 /************************************************************************/ /* Example */ /*************************************************************...
19,453
#include <stdio.h> #include <time.h> #include <unistd.h> #include <stdlib.h> #include <math.h> __global__ void Mat_hist(int x[], int z[], int n) { int thread_id = threadIdx.x + blockIdx.x * blockDim.x; __shared__ int hist[256]; if(threadIdx.x < 256) hist[threadIdx.x]=0; __syncthreads(); ...
19,454
#include <stdio.h> #include <assert.h> #include <pthread.h> #define THREADS 4 int intervalsT=100000000; double partialStore[]={0.0, 0.0, 0.0, 0.0}; // -:YOUR CODE HERE:- void *threadRoutine(void *param) { // -:YOUR CODE HERE:- return 0; } void calculatePIHostMultiple(){ // -:YOUR CODE HERE:- ...
19,455
#include <iostream> #include <stdio.h> #include "clahe.cuh" #define BIN_SIZE 101 __global__ void clahe(float* L, int width, int height, int threshold, float* dCdf) { __shared__ int bins[BIN_SIZE]; computeHistogram(L, width, height, bins); clipHistogram(bins, threshold); generateCdf(bins, dCdf); } __...
19,456
#include "includes.h" __global__ void intArrayIdentity(int size, int *input, int *output, int length) { const int ix = threadIdx.x + blockIdx.x * (long)blockDim.x; if (ix < size) { // copy int array const int *inArrayBody = &input[ix * length]; int *outArrayBody = &output[ix * length]; for (long i = 0; i < length; i...
19,457
#include <stdio.h> int main() { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("Device Number: %d\n", i); printf(" Device name: %s\n", prop.name); printf(" Memory Clo...
19,458
#include <stdlib.h> #include <stdio.h> #include<math.h> #include<time.h> // row-wise nonzero counting __global__ void count_nonzero(int n, float *A, int *nz){ int row = blockIdx.x*blockDim.x + threadIdx.x; int count = 0; for (int i=0; i<n; i++) if (A[row*n+i] != 0) count += 1; n...
19,459
#include<stdio.h> #include<stdlib.h> __global__ void mul(int *a, int *b, int *c, int n) { int row = blockIdx.y*blockDim.y + threadIdx.y; int col = blockIdx.x*blockDim.x + threadIdx.x; int sum = 0; int i; if(row < n && col < n) { for(i =0; i<n; i++) { sum += a[row*n+i]*b[i*n+col]; } c[row*n+col] = su...
19,460
#include<iostream> #include <sys/time.h> using namespace std; const int threadsPerBlock = 256; const int N = (1 <<20) -3; const int blocksPerGrid = (N + threadsPerBlock * 2 - 1)/ (threadsPerBlock * 2); // 维持block数量不变 const int iters = 100; __global__ void kernel4(float* arr, float* out, int...
19,461
#include <iostream> //#include "gpu.hpp" /*__global__ void filter(unsigned int *input, unsigned int *od, int w, int h, int r) { } extern "C" double boxFilterRGBA(unsigned int *d_src, unsigned int *d_temp, unsigned int *d_dest, int width, int height, int radius, int iterations, int nthreads, Stop...
19,462
// Tests CUDA compilation pipeline construction in Driver. // REQUIRES: clang-driver // REQUIRES: x86-registered-target // REQUIRES: nvptx-registered-target // Simple compilation case. Compile device-side to PTX assembly and make sure // we use it on the host side. // RUN: %clang -### -target x86_64-linux-gnu -c %s 2>...
19,463
struct node { int items[10]; int parent[10]; }; __global__ void generate_fp_tree(unsigned int* input, node *output) { int tx = threadIdx.x; int gtx = blockIdx.x * blockDim.x + threadIdx.x; if(input[gtx]!=0) atomicAdd(&output[tx].items[input[gtx]-65],1); //output[tx].items[input[gtx]...
19,464
// ########################################################## // By Eugene Ch'ng | www.complexity.io // Email: genechng@gmail.com // ---------------------------------------------------------- // The ERC 'Lost Frontiers' Project // Development for the Parallelisation of ABM Simulation // ------------------------------...
19,465
#include<bits/stdc++.h> using namespace std; #define BLOCK_SIZE 256 __global__ void pegasos_per_thread(int num_samples, int num_features, double * W, double * X, double * Y, double lambda, int num_iters, double * random_arr, int k) { int index = blockIdx.x * blockDim.x + threadIdx.x; int n_samples_per_thread ...
19,466
#include "includes.h" __global__ void scale_values(float *num, size_t size, float abs_max) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < size) num[idx] = (abs_max + abs_max) * num[idx] - abs_max; }
19,467
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> int *IntArray(int length, int first = 0, int step = 0) { int *av = (int *)malloc(sizeof(int) * length); for (int i = 0; i < length; i++) { av[i] = first + step * i; } return av; } bool CompIntArrays(int *a, i...
19,468
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #define BLOCKS 12 #define BLOCKSIZE 1024 //#define BSize 32 //#define QSize (BLOCKS*BLOCKSIZE)/BSize/32 #define BSize 24 #define QSize 16 struct kernel_para{ volatile int *A, *B, *C; volatile int size; volatile int block; volatile int thread; volatile int war...
19,469
float h_A[]= { 0.6077304871894453, 0.8936961933315026, 0.7270382344822287, 0.8023482238859894, 0.6075262879503021, 0.6641276886564242, 0.6947977310727611, 0.7349836135509735, 0.9990753103838406, 0.8299995402483878, 0.7080981018287671, 0.6435698793550537, 0.5146250303212558, 0.9750651429625462, 0.7535471719286995, 0.795...
19,470
#include "includes.h" __global__ void InvolveVector(float* input, float* output, int inputSize) { 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(threadId < inputSize - 1) { output[0] = input[0]; output[...
19,471
#include <stdlib.h> #include <stdio.h> #include <iostream> #include <unistd.h> #include <sys/time.h> __global__ void add(float *array, int dimensions, int num_elements) { int index = (threadIdx.x + blockIdx.x * blockDim.x) * dimensions; // + blockIdx.y * blockDim.y + blockIdx.z * blockDim.z; if (threadIdx.x ...
19,472
#include <iostream> #include <cuda.h> static void HandleError( cudaError_t err, const char *file, int line) { if (err != cudaSuccess) { std::cout << "Error Name: " << cudaGetErrorName( err ) << std::endl; std::cout << cudaGetErrorString( err ) << " in " << file << " line " << line << std::endl; exit(EXIT...
19,473
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> // a = b * c __global__ void mmult(float *a, float *b, float *c, int N) { int row = blockIdx.y; int col = blockIdx.x*32 + threadIdx.x; float sum = 0.0f; for (int n = 0; n < N; ++n) { sum += a[row*N+n]*b[n*N+col]; } c[row*N+col] = sum; } // a...
19,474
// // include files // #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> // // template kernel routine // template <typename T> __global__ void my_first_kernel(T *x) { int tid = threadIdx.x + blockDim.x*blockIdx.x; x[tid...
19,475
#include "includes.h" __global__ void blendFloatImageFloatLabelToRGBA_kernel( uchar4 *out_image, const float *in_image, const float *label, int width, int height, float lowerLim, float upperLim) { const int x = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; const int y = __mul24(blockIdx.y, blockDim.y) + threadIdx.y; u...
19,476
#include <stdio.h> #include <chrono> #define block_size_x 256 #define num_blocks 1024 //a naive summation in C float sum_floats(float *in_array, int n) { float sum = 0.0; for (int i=0; i<n; i++) { sum += in_array[i]; } return sum; } //Kahan summation to avoid floating-point precision errors...
19,477
#include <cstdio> __global__ void my_kernel() { printf("Hello from block %i of %i and thread %i \n ", blockIdx.x, blockDim.x, threadIdx.x); } int main() { my_kernel <<<16, 16 >>> (); cudaError_t cuda_err = cudaDeviceSynchronize(); if (cuda_err != cudaSuccess) printf("kernel launch failed w...
19,478
// CUDA multiple threads #include <cuda.h> #include <cuda_runtime.h> __global__ void rgb2grey_kernel(const uchar4* const rgbaImage, unsigned char* const greyImage, int numRows, int numCols) { int idx = threadIdx.x+ blockIdx.x* blockDim.x; if (idx < numCols*numRow...
19,479
// // Created by harshvardhanchandirasekar on 8/1/20. // #include "planet.cuh" int main() { return 0; }
19,480
#include "includes.h" __global__ void main_set(float *data, float val) { data[threadIdx.x] = val; }
19,481
#include<cstdio> #include<fstream> #include<cmath> #include<cuda.h> int threshold=256; int xthread=32; __global__ void multiply(float* A,float* B,float* C,int jump,int jump1,int jump2,int iter) { __shared__ float A1[32][32],B1[32][32]; int posy=blockIdx.y*blockDim.y+threadIdx.y; int posx=blockIdx.x*block...
19,482
#include <stdio.h> //__global__ void kernel( void ) { // does nothing //} int main(int argc, char** argv) { // default the loop count to equal 1 int loopCount = 1; // take in a command line arg to set the loop count if(argc > 1){ loopCount = atoi(argv[1]); } // delcare two variables int *dev_...
19,483
/* kernel.cu Holds the kernel for the main program */ #include <iostream> #define BLOCK_WIDTH 32 #define cuda_check_errors(val) check( (val), #val, __FILE__, __LINE__) using namespace std; /* Reports the location of the occured error and exits the program */ template<typename T> void check(T err, const char* con...
19,484
#include <iostream> int main() { cudaDeviceProp prop; int devcount; cudaGetDeviceCount(&devcount); std::cout << "Devices found: " << devcount << std::endl; for(int i=0; i<devcount; i++) { cudaGetDeviceProperties(&prop, i); std::cout << "------------------" << std::endl; std::cout << "Device: " << i << std::...
19,485
#include <chrono> #include <cmath> #include <cstdio> #include <cstdlib> #include <cuda_runtime.h> #include <iomanip> #include <iostream> // helper for time measurement typedef std::chrono::duration<double, std::milli> d_ms; const auto &now = std::chrono::high_resolution_clock::now; // Define Error Checking Macro #def...
19,486
#include "includes.h" __global__ static void kernelFindMax4(const int* dataArray, int arraySize, int* maxVal) { __shared__ extern int cache[]; int cacheIndex = threadIdx.x; int arrayIndex1 = (int)(blockDim.x * blockIdx.x + threadIdx.x); // グローバルメモリの1つ目の要素番号 int arrayIndex2 = arrayIndex1 + gridDim.x * blockDim.x; ...
19,487
#include <cuda_runtime.h> #include <stdio.h> constexpr size_t N = 512; __global__ void add_one(size_t n, float* x) { int i = threadIdx.x; if (i < n) { x[i] = x[i] + 1; } } void switch_device() { // select device 0 size_t size = N * sizeof(float); cudaSetDevice(0); // Set device 0 as ...
19,488
// Dan Rolfe #define BLOCKSIZE 32 /** * cuda vector add function **/ // there is a problem here, running this ruins the add __global__ void d_add( float* __restrict__ x, float* __restrict__ y, float* __restrict__ z, int size) { int index = threadIdx.x + blockIdx.x * blockDim.x; if(index < size) z[index] = x[i...
19,489
#include <iostream> struct fields { unsigned a : 4; unsigned b : 4; unsigned c : 4; unsigned d : 4; unsigned e : 4; unsigned f : 4; unsigned g : 4; unsigned h : 4; }; union u { unsigned int i; fields f; }; __device__ __forceinline__ unsigned int bfe(unsigned int x, unsigned int bit, unsigne...
19,490
#include <thrust/random.h> #include <thrust/iterator/counting_iterator.h> #include <thrust/transform.h> #include <thrust/device_vector.h> #include <thrust/functional.h> #include <iostream> struct randf :public thrust::unary_function<int, float> { int seed; randf(int seed_) :seed(seed_){} __device__ __host_...
19,491
// file esempio querydevice #include "stdio.h" static void HandleError( cudaError_t err, const char *file, int line) { if (err != cudaSuccess) { printf("%s in %s at line %d\n", cudaGetErrorString( err ), file, line); exit(EXIT_FAILURE); } } #define HANDLE_ERROR(err)(HandleError(err, __FILE__, __LINE__)) ...
19,492
#include <cuda.h> extern "C" __global__ void kern(int *out) { out[0] = 1; }
19,493
#include "includes.h" __global__ void MatrixMulKernel (float* Md, float* Nd, float* Pd, int ncols) { int row = blockIdx.y*blockDim.y + threadIdx.y; int col = blockIdx.x*blockDim.x + threadIdx.x; // Pvalue is used to store the element of the output matrix // that is computed by the thread float Pvalue = 0; for (int k...
19,494
#include "includes.h" __global__ void MatrixTranspose(const float *A_elements, float *B_elements, const int A_width, const int A_height) { int strideRow = blockDim.y * gridDim.y; int strideCol = blockDim.x * gridDim.x; for(int row = blockIdx.y * blockDim.y + threadIdx.y; row < A_width; row += strideRow) for(int col = ...
19,495
// nvcc -arch=sm_21 -o cuda_dstar cuda_dstar.cu -lrt -lm #include <cstdio> #include <cstdlib> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #define MAPROW 5 #define MAPCOL 5 #define MAX 9999 #define STRCOL 0 #define STRROW 0 #define DSTCOL 4 #define DSTROW 4 #define BLOCK 5 typed...
19,496
#include <cstdio> #define DLIMIT 99999999 // Cluster Center // // float* f; // vector of size #channels // float x, y, z; // #define __min(a, b) (((a) < (b)) ? (a) : (b)) #define __max(a, b) (((a) >= (b)) ? (a) : (b)) /* * P = point * S = data shape * F = data # features */ __device__ float at(const float* d...
19,497
#include <stdio.h> #define N 3 #define M 2 __global__ void add(int *a, int *b, int *c) { int tid = threadIdx.x; // if(tid < N) for(int i = 0; i < N; i++) c[tid * N + i] = a[tid * N + i] + b[tid * N + i]; } int main() { // int *a, *b, *c; int a[M * N], b[M * N], c[M * N]; // host copies of variables a, b & c i...
19,498
#include <stdio.h> #include <time.h> #include <unistd.h> #include <stdlib.h> #include <math.h> using namespace std; __device__ void _2Dstencil_(int *d_e,int *d_r,float* c_coeff,int X,int Y,int k, int x, int y,int GX,int Gx,int Gy) { int h_e_i; int h_r_i = x + ( y * (X) ); h_e_i = h_r_i; int temp =...
19,499
#define TUD 2 #define BPW 3 #define WST 8 #define WSU 8 #define WSV 8 #define WS (WST*WSU*WSV) #define CELL_LENGTH 4 #define CELL_SIZE (4*4*4) #define BLOCK_SIZE (WS*CELL_SIZE) #define BS_NUINT (BLOCK_SIZE/4) #define WLT (WST*CELL_LENGTH) #define WLU (WSU*CELL_LENGTH) #define WLV (WSV*CELL_LENGTH) #define TUV_MASK 0x4...
19,500
/****************************************************************************** * 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...