serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
15,901
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> int error(int* device_a); __global__ void identity(int* device_a, int size) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; printf("Block: (%d, %d), Thread: (%d, %d), Block ...
15,902
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void parallel_for_loop() { printf("Current Iteration Number: %d\n", threadIdx.x); } class ParallelizedForLoopProgram { public: int n; ParallelizedForLoopProgram(int n); void run(); }; ParallelizedForLoo...
15,903
#include <cstdio> #include <cassert> // https://cs.calvin.edu/courses/cs/374/CUDA/CUDA-Thread-Indexing-Cheatsheet.pdf __global__ void init_random_numbers(unsigned int seed) { printf("seed = %d\n", seed); assert(seed != 0); } int main() { init_random_numbers<<<1024, 1024>>>(1); return 0; }
15,904
#include "includes.h" #define T_PER_BLOCK 16 #define MINF __int_as_float(0xff800000) __global__ void erodeDepthMapDevice(float* d_output, float* d_input, int structureSize, int width, int height, float dThresh, float fracReq) { const int x = blockIdx.x*blockDim.x + threadIdx.x; const int y = blockIdx.y*blockDim....
15,905
#include <cuda.h> #include <cuda_runtime.h> #include <math.h> #include <stdio.h> #define CHECK \ { \ const cudaError_t i = cudaGetLastError();\ if(i) \ printf("(%s:%i) %s\n", __FILE__, __LINE__-1, cudaGetErrorString(i));\ } #define IDX_PATT(a, b) \ const int a = blockDim.x * blockIdx.x + threadIdx.x; \ const i...
15,906
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <algorithm> #include <cstdlib> #include <iostream> int main() { // generate 1024 random numbers serially thrust::host_vector<int> h_vec(1 << 10); std::generate(h_...
15,907
#include <stdio.h> #define NUM_BLOCKS 16 #define BLOCK_WIDTH 1 __global__ void hello() { printf("Hello world. I'm a thread in block %d\n", blockIdx.x); printf("Hello world. I'm a thread number %d\n", threadIdx.x); } int main(int argc, char **argv) { hello<<<NUM_BLOCKS, BLOCK_WIDTH>>>(); //cudaDeviceSynchronize(...
15,908
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ )) void HandleError(cudaError_t err, const char *file, int line ) { if...
15,909
/**********:{******************************************************************** *cr *cr (C) Copyright 2010 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr ***************************************************************...
15,910
#include "includes.h" __global__ void Accumulate(float4 *src, float4 *dest, int loop) { const size_t i = blockDim.x * blockIdx.x + threadIdx.x; const size_t k = blockDim.x * gridDim.x; dest[i] = src[i]; for (int n=1; n<loop; n++) { dest[i].x += src[i+n*k].x; dest[i].y += src[i+n*k].y; dest[i].z += src[i+n*k].z; de...
15,911
#include "includes.h" __global__ void apply_gradient_with_weight_decay_util_kernel( const float2 * __restrict gradient, const float2 * __restrict learning_rates, float2 * __restrict weights, float weight_decay, int elem_count) { int elem_id = blockDim.x * blockIdx.x + threadIdx.x; if (elem_id < elem_count) { float2 lr ...
15,912
#include <stdio.h> #include <unistd.h> // __global__ 修饰符,将告诉编译器,函数在设备(GPU)上运行而不是在主机(CPU)上运行 __global__ void kernel(void) { printf("Hello world!\n"); } int main(void) { while(1) { kernel<<<1,1>>>(); sleep(1); } return 0; } // compile // nvcc hello.cu -o hello
15,913
//////////////////////////////////////////////////////////////////////////// // Calculate scalar products of VectorN vectors of ElementN elements on CPU. // Straight accumulation in double precision. //////////////////////////////////////////////////////////////////////////// #include <iostream> #include <cmath> using...
15,914
/** * Generate Uniformly-Distributed Random Numbers via the CUDA cuRAND Library on the NVIDIA GPU. */ #include <stdio.h> #include <math.h> #include <time.h> /** * NOTE that on Ubuntu, the below header files are generally located in: * /usr/local/cuda/include/ */ #include <cuda_runtime.h> #include <curand_ke...
15,915
// Compile: nvcc -arch=sm_61 -std=c++11 assignment5-p2.cu -o assignment5-p2 #include <cmath> #include <cstdint> #include <iostream> #include <sys/time.h> #define THRESHOLD (0.000001) #define SIZE1 4096 #define SIZE2 4097 #define ITER 100 using namespace std; __global__ void kernel1(double* A) { // SB: Write the ...
15,916
#include <stdio.h> #include <stdint.h> #include <assert.h> // #define DEBUG #define UINT uint32_t #define TOPM 26 #define MAXN 1024 #define MULSIDE 16 // each block has size SIDE x SIDE #define MULBLK (MAXN / MULSIDE) // divide C into BLK x BLK blocks #define ADDSIDE 256 #define ADDBLK (MAXN*(MAXN / ADDSIDE)) //...
15,917
#include <stdio.h> #include <cuda.h> //----------------------------------------------------------------------------- // TheKernel: basic kernel containing a print statement. //----------------------------------------------------------------------------- __global__ void TheKernel() { // The variable "threadIdx" is gi...
15,918
/* * * 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 relat...
15,919
#include <stdio.h> #define SIZE 1024 __global__ void VectorAdd(int* a, int* b, int* c, int n) { int i = threadIdx.x; if(i < n) c[i] = a[i] + b[i]; } int main() { int* a, * b, * c; cudaMallocManaged(&a, SIZE * sizeof(int)); cudaMallocManaged(&b, SIZE * sizeof(int)); cudaMallocManaged(&c, SIZE * sizeof(int))...
15,920
#include<stdio.h> #include<assert.h> #define N 4 //size of the matrix in one dimension #define THREADSPERBLOCK 4 void PRINT_MAT(int P, int M, double * matr){ for(int j = 0; j < P; j++ ){ for(int i = 0; i < M; i++ ){ printf("%f ",matr[i+j*M]); } printf("\n"); } } __global__ void transpose( doubl...
15,921
#include "includes.h" __global__ void update(float * weights, float * grad,float lr,int N) { int x = blockDim.x*blockIdx.x + threadIdx.x; if(x<N) weights[x] -= lr*grad[x]; grad[x] = 0.0; }
15,922
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #define ITER 4000 #define MIN(x, y) (x<y?x:y) typedef struct Map{ int length; double *A; int *x; int *dx; int *y; int *dy; int *delta; int *phi; }Map; ...
15,923
// Exemplo 17: Soma de matrizes // Usa grid e blocos bidimensionais // Para compilar: nvcc ex17.cu -o ex17 // Para executar: ./ex17 #include <stdio.h> #include <stdlib.h> void soma_matriz_CPU(int nLinhas, int nColunas, int *a, int *b, int *c) { int i, j; for (i = 0; i < nLinhas; i++) for (j = 0; j < ...
15,924
#include "includes.h" __global__ void convertDepthImageToMeter_kernel(float *d_depth_image_meter, const unsigned int *d_depth_image_millimeter, int n_rows, int n_cols) { const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; if (x < n_cols && y < n_rows) { int ind = ...
15,925
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <math.h> #include <limits.h> #include "cuda_kernel.cuh" int solveProblem(const int argc, const char* argv[]){ cudaError_t return_value; if(argc == 2){ cudaEvent_t start, stop, memcopystart, memcopystop; float time, memcopytime; int vectorl...
15,926
#include <iostream> #include <fstream> #include <sstream> #include <string> #include "vector" #include <math.h> #include <stdlib.h> #include <cmath> #include <stdio.h> using namespace std; __global__ void odd_count(int n, int *a, int *odd_cnt){ int index = threadIdx.x; int stride = blockDim.x; for (int i = inde...
15,927
#include "includes.h" __global__ static void k_count_received(int nr_total_blocks, uint *d_n_recv_by_block, uint *d_spine_cnts) { int bid = threadIdx.x + THREADS_PER_BLOCK * blockIdx.x; if (bid < nr_total_blocks) { d_spine_cnts[bid * 10 + CUDA_BND_S_NEW] = d_n_recv_by_block[bid]; } }
15,928
#include "includes.h" __global__ void geometricDOF( float *Qi_gdof, float4 *positions, float *masses, int *blocknums, int *blocksizes, int largestsize, float *norm, float *pos_center ) { int blockNum = blockIdx.x * blockDim.x + threadIdx.x; for( int j = 0; j < blocksizes[blockNum] - 3; j += 3 ) { int atom = ( blocknum...
15,929
/*! * Compute the next power of 2 which occurs after a number. * * @param n */ __device__ int nextPower2(int n) { int pow2 = 2; while ( pow2 < n ) { pow2 *= 2; } return pow2; } /*! * Swap two values * * @param a * @param b */ __device__ void swapF(float *a, float *b) { floa...
15,930
// vanessa writes a targa file // compiling and running this program will produce a targa file // wip: optionally using CUDA/GPU // TODO: fix directions // // compile : $ gcc create-tga-from-any-input.c -o targa-exe // usage : $ ./targa-exe input-file output-filename dimensions // example : $ ./targa-exe /usr/input...
15,931
#define _CRT_SECURE_NO_DEPRECATE #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> //Error handling macro, wrap it around cuda function whenever possible static void HandleError(cudaError_t err, const char *file, int line) { if...
15,932
//подключение библиотек #include "cuda_runtime.h" #include "curand_kernel.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <string> #include <iomanip> #include <time.h> #include <iostream> using namespace std; int homeWork2() { return 0; }
15,933
#include <iostream> #include "../include/gpu_list.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; __global__ void test(float *output){ gpu_list<float> list; for(int i=0;i<80;++i) list.push_back(float(i)); ...
15,934
#ifndef GPU_VECTOR3D_H #define GPU_VECTOR3D_H class gpuVector3D { public: float x,y,z; __device__ __host__ gpuVector3D(): x(0.0), y(0.0), z(0.0){} __device__ __host__ gpuVector3D(float x, float y, float z): x(x), y(y), z(z){} __device__ __host__ gpuVector3D(float c): x(c), y(c), z(c){} ...
15,935
#include <stdlib.h> #include <iostream> #include <cuda_runtime_api.h> #include <assert.h> #include <string.h> #include <cooperative_groups.h> #include <chrono> namespace cg = cooperative_groups; using namespace std; #define CUDA_CHECK(e) do { \ if (cudaSuccess != (e)) { \ fprintf(stderr, "Cuda runtime error i...
15,936
#include "includes.h" cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); __global__ void addKernel(int *c, const int *a, const int *b) { int i = threadIdx.x; c[i] = a[i] + b[i]; c[i] = a[i] - b[i]; }
15,937
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define ARR_LEN 12 /* * Q2. Sort an array of size ARR_LEN using parallel selection sort. */ __global__ void selectionSort(int *arr, int *result, int n) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id > n) return; int pos = 0; ...
15,938
/********************* @author: Maziar Raissi *********************/ /**************************************************** To compile and run use: nvcc -std=c++11 CudaSimpleNN.cu -o CudaSimpleNN ./CudaSimpleNN ****************************************************/ #include <iostream> #include <fstream> #includ...
15,939
//Editor: Michael Lukiman //Spiking neuron network region implementation in CUDA with additional spatial winner-take-all dynamics //GPU Architecture and Programming - Fall 2018 // As this is a faithful representation of neuronal spiking in a 'region' of the brain, we will do out best to cut down library use and use t...
15,940
//////////////////////////////////////////////////////////////////////////// // // Copyright 1993-2015 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 u...
15,941
#include <iostream> #include <cuda_runtime.h> #include <cuda.h> #include <thrust/sort.h> #include <thrust/execution_policy.h> //typedef unsigned _int64 uint64_t int main(){ uint64_t key[5] = {234,5938,23,94,55}; int index[5] = {0,1,2,3,4}; uint64_t* key_d; int* index_d; cudaMalloc((voi...
15,942
#include <iostream> #include <algorithm> #include <cstdlib> #include <ctime> #include <cuda.h> #include <stdio.h> #include <cassert> //! Get the block id __device__ int block_idx(int grid_dim) { int block_id = blockIdx.x + (grid_dim == 2 ? 1 : 0) * blockIdx.y * gridDim.x + (grid_dim == 3 ? 1 : 0) * ...
15,943
#include<cuda.h> #include<cuda_runtime.h> #include<stdio.h> #include<stdlib.h> #include<cmath> #define TILE_SIZE 4 // Tile size and block size, both are taken as 32 __device__ void store_full_row(float*,float*,int,int); __device__ void load_full_row(float*,float*,int,int); __device__ void store_full(float*,f...
15,944
#include <iostream> #include <stdio.h> __global__ void add(int a, int b, int *c) { *c = a + b; //must compiled under compiler:cuda4.0 or above, runned under Fermi architecture //eg /opt/cuda42/bin/nvcc -arch sm_20 page25_sum.cu printf("I am inside.\n"); } int main (void){ int c; int *dev_c; cudaMalloc ((void**...
15,945
#include "includes.h" __global__ void calcRouteForwardGPU(float *in, float *out, int in_size_x, int in_size_y, int in_size_z, int z_offset, int elements ) { // int i = blockIdx.x*blockDim.x + threadIdx.x; int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; if( id < elements ){ int id_in = id; int...
15,946
#include "includes.h" __global__ void transposeGlobalKernel(float* idata, float* odata, int width, int height) { int tidx = blockIdx.x * blockDim.x + threadIdx.x; int tidy = blockIdx.y * blockDim.y+ threadIdx.y; if(tidx < width && tidy < height) { odata[tidx*height + tidy] = idata[tidy*width + tidx]; } }
15,947
#include "includes.h" __global__ static void yuv422_to_yuv444_kernel(const void * src, void * out, int pix_count) { // coordinates of this thread const int block_idx_x = threadIdx.x + blockIdx.x * blockDim.x; // skip if out of bounds if(block_idx_x >= pix_count / 2) { return; } uchar4 *this_src = ((uchar4 *) src) + b...
15,948
#include<stdio.h> #include<stdlib.h> #include<math.h> #define N 8192 #define N_THREADS 64 // space for function __global__ void mat_transpose(int *mat_in_dev, int *mat_out_dev){ int index = threadIdx.x + blockIdx.x*blockDim.x; int x = index%N; int y = index/N; mat_out_dev[y*N+ x] =...
15,949
#include <stdio.h> #include <inttypes.h> #include <cuda.h> #include <stdlib.h> #include <string.h> __global__ void warmup(uint8_t *arr, size_t n) { uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x; arr[tid] = 1U; } __global__ void test(uint8_t *arr, size_t n, size_t stride, uint64_t *timer) { size_t i...
15,950
#include <stdio.h> __global__ void cuda_hello(){ printf("Hello World from GPU!\n"); } int main() { // kernel function name <<< number of block, number of thread >>> (arguments) cuda_hello<<<1,1>>>(); // https://qiita.com/JmpM/items/ada670ec80be9566269e // CPU waits for GPU operation cudaD...
15,951
/********************************************************************* * @file check_gpuinfo.cu * @brief display gpu information * @author Bin Qu * @email benquickdenn@foxmail.com * @date 2019-11-26 * you can reedit or modify this file *********************************************************************/ #i...
15,952
#include <stdio.h> #include <cuda_runtime_api.h> #include <time.h> __device__ int is_a_match(char * attempt) { char password1[] = "AP25"; char password2[] = "AN52"; char password3[] = "RA25"; char password4[] = "RC80"; char * a = attempt; char * b = attempt; char * c = attempt; char * d = attempt; ...
15,953
/* #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <opencv2/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgui.hpp> #include<opencv2\imgproc.hpp> #include <iostream> #define N 1024*1024 #define FullSize 20*N __global__ void kernel(unsigned int* a, unsigned...
15,954
#include "includes.h" __device__ inline float d_square_prox(float x0, float c, float f, float tau) { return (x0 + 2.f * tau * c * f) / (1.f + 2.f * tau * c * c); } __device__ void d_calcDivergence(const float *v1, const float *v2, float &divv, size_t width, size_t height, size_t c, const bool *mask) { const int x = blo...
15,955
extern "C" __global__ void solve_jit_flipped(double *rateConst, double *state, double *deriv, int numcell) { size_t tid; ...
15,956
// // Created by Filippos Kasioulis on 25/01/2019. // #include <stdio.h> #include <time.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <string.h> #include <cuda.h> #include <sys/time.h> typedef struct { float x; float y; float z; }Point; __global__ void knn_search(Point* al...
15,957
#include "includes.h" #define DATA_SIZE (1024 * 1024 * 256) #define DATA_RANGE (256) void printHist(int * arr, char * str); __global__ void histogram_shared(float * a, int * histo, int n) { int tid = blockIdx.x * blockDim.x + threadIdx.x; __shared__ int sh[DATA_RANGE]; if(threadIdx.x < 256) sh[threadIdx.x] = 0;...
15,958
__global__ void vsortSmall(int *input0,int *result0){ unsigned int tid = threadIdx.x; unsigned int bid = blockIdx.x; extern __shared__ unsigned char sbase[]; (( int *)sbase)[(tid+(tid&4294967040))] = min(input0[((bid*512)+(tid+(tid&4294967040)))],input0[((bid*512)+((tid+(tid&4294967040))^256))]); (( int *)...
15,959
#include <iostream> #include <fstream> #include <vector> #include <unistd.h> #include <string> #include <stdio.h> using std::cout; using std::endl; using std::vector; using std::ifstream; using std::swap; using std::string; using namespace std; #define ALIVE 'X' #define DEAD '-' #define THREADS 512 __global__ void p...
15,960
#include <cuda.h> #include <stdio.h> __global__ void scaleit_kernel(double *a,int n, int scaleBy) { /* Determine my index */ int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { a[i] = a[i] * (double)scaleBy; } } /* nvcc uses C++ name mangling by default */ extern "C" { int scaleit_launcher_(...
15,961
#include "includes.h" __global__ void current_calculate_postsynaptic_current_injection_kernel(float* d_synaptic_efficacies_or_weights, float* d_time_of_last_spike_to_reach_synapse, int* d_postsynaptic_neuron_indices, float* d_neurons_current_injections, float current_time_in_seconds, size_t total_number_of_synapses){ ...
15,962
//xfail:ASSERTION_ERROR //--gridDim=1 --blockDim=32 --no-inline #define memset(dst,val,len) __builtin_memset(dst,val,len) __device__ int bar(void); __global__ void kernel(uint4 *out) { memset(0, 0, 16); }
15,963
#include "includes.h" __global__ void _fill_gradBias(float *gradBias, const float *gradOutput, float scale, int batch_n, int output_n, int output_h, int output_w) { gradOutput += blockIdx.x*output_h*output_w; __shared__ float shGrad[128]; // 32*4 float g = .0f; int oz,oxy; for (oz = threadIdx.y; oz < batch_n; oz += 4) ...
15,964
/* 159735 Parallel Programming Assignment 5 To compile: nvcc -o hyperSpace hyperSpace.cu To run: ./hyperSpace [nTrails] nTrails is 20 by default For example: "./hyperSpace 50" will generate a hyper sphere for 50 times, and count the number of integer coordinate points inside every sphere, by bo...
15,965
#include <stdio.h> #include <math.h> #include <time.h> #include <unistd.h> #include <cuda_runtime_api.h> #include <errno.h> #include <unistd.h> /****************************************************************************** * This program takes an initial estimate of m and c and finds the associated * rms error. It...
15,966
/* Kam Pui So (Anthony) CS510 GPU Project Group A Appliction: Matrix Addition base on CUDA TOOLKIT Documentation */ #include <sys/time.h> #include <time.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <cuda_profiler_api.h> //global //const int TESTSIZE[] = {1, 2, 4, 8, 16, ...
15,967
#include <stdio.h> #include <stdlib.h> __global__ void distance(float *x, float *y, float *z, int NUM_PART, float *dist) { float posx, posy, posz; int idx = blockIdx.x * blockDim.x + threadIdx.x; int idx_dist = idx * (NUM_PART); for(int i=0; i<NUM_PART; i++) { if(idx != i) {...
15,968
#include "includes.h" __global__ void findDesirabilityKernel(int size, int optimalSize, int *adjIndexes, int *adjacency, int *partition, int *partSizes, int *nodeWeights, int *swap_to, int *swap_from, int *swap_index, float *desirability) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < size) { int currentPa...
15,969
#include "includes.h" __global__ void kernel_histo_stride( unsigned int *ct, unsigned int *histo){ int i = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; while( i < constant_n_hits*constant_n_test_vertices ){ atomicAdd( &histo[ct[i]], 1); i += stride; } }
15,970
/***************************************************************************** Example : VectVectMult.cu Objective : Write a CUDA Program to perform Vector Vector multiplication using global memory implementation. Input : None Output : Execution time in seconds , Gflops ...
15,971
#include <stdio.h> #include <time.h> typedef struct vertex vertex; struct vertex { unsigned int vertex_id; float pagerank; float pagerank_next; unsigned int n_successors; vertex ** successors; }; float abs_float(float in) { if (in >= 0) return in; else return -in; } int main(int arg...
15,972
__global__ void registerDemo(int width) { int start = width * threadIdx.x; int end = start + width; for (int i = start; i < end; i++) { // some codes here } }
15,973
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #define CUDA_ERROR_EXIT(str) do{\ cudaError err = cudaGetLastError();\ if( err != cudaSuccess){\ printf("Cuda Error: '%s' for %s\n", cudaGetE...
15,974
#include <cuda.h> #include <stdio.h> __global__ void scan_local(float *in, float *out) { out[0] = in[0]; for (int i = 0; i < 32; i ++) { out[i] = out[i-1] + in[i]; } } int main(void) { float v[32]; float r[32]; float *dv; float *dr; for (int i = 0; i < 32; i ++) { v[...
15,975
#include <stdlib.h> #include <stdio.h> #include <ctime> #include <vector> #include <algorithm> #include <thrust/random/linear_congruential_engine.h> #include <thrust/random/uniform_real_distribution.h> #include <thrust/random/uniform_int_distribution.h> #include <thrust/random/normal_distribution.h> __global__ void in...
15,976
#include <stdio.h> __global__ void holaCUDA(float e) { printf("Hola, soy el hilo %d del bloque %d con valor pi->%f\n", threadIdx.x,blockIdx.x,e); } int main(int argc, char **argv){ holaCUDA<<<8,4>>>(3.1416); cudaDeviceReset(); //Esta llamada reinicializa el device return 0; }
15,977
float h_A[]= { 0.6341792875205959, 0.6098888678948859, 0.6635213795067179, 0.8400797798346671, 0.8983777292367168, 0.9291282973058768, 0.8855207616863526, 0.5873761142783284, 0.8524519412600629, 0.6937154330744035, 0.7946123839135799, 0.6970440247561547, 0.7941531842223644, 0.7202732259058222, 0.771791474816776, 0.8186...
15,978
const int N = 1 << 20; __global__ void kernel(float *x, int n) { int tid = threadIdx.x + blockIdx.x * blockDim.x; for (int i = tid; i < n; i += blockDim.x * gridDim.x) { x[i] = sqrt(pow(3.14159,i)); } }
15,979
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #define LIST_SIZE 100000 __device__ int init_flag = 0; __device__ unsigned long long shiftCount[LIST_SIZE]; __device__ unsigned long long shiftVal[LIST_SIZE]; __device__ unsigned long long record_flag = 0; extern "C" __device__ void profi...
15,980
#include<iostream> #include <cuda_runtime.h> using namespace std; __global__ void exchangeMin(int* arr, int start){ int tID = blockDim.x*blockIdx.x + threadIdx.x; if (arr[start + tID*2] <= arr[start + tID*2 + 1]){ return; } int temp = arr[start + tID*2]; arr[start + tID*2] = arr[start + t...
15,981
#include <thrust/iterator/constant_iterator.h> #include <thrust/iterator/zip_iterator.h> #include <thrust/reduce.h> #include <thrust/device_vector.h> #include <iostream> int main(int argc, char* argv[]) { // create iterators // thrust::constant_iterator<int> first(10); // thrust::constant_iterator<int> last ...
15,982
#include<stdio.h> #include<iostream> #include<cuda.h> __global__ void simpleKernel(int* data) { data[(blockIdx.x* blockDim.x)+threadIdx.x] = blockIdx.x + threadIdx.x; //to print the result in the device array printf("\n %d + \t %d \t %d",threadIdx.x, blockIdx.x, data[(blockIdx.x * blockDim.x)+ th...
15,983
#include <iostream> #include <cstdlib> #include <stdlib.h> #include <ctime> #define N 10000 __global__ void findmaximum(float *A, float *max,int n) { int index = threadIdx.x + blockIdx.x*blockDim.x; int dim = gridDim.x*blockDim.x; int offset =0; float temp; while(index + offset < n){ temp = fmaxf(temp, ...
15,984
#include "includes.h" #define ROUND_OFF 50000 #define CUDA_NUM_THREADS 1024 #define WARPS_PER_BLOCK 1 #define THREADS_PER_WARP 32 #define CUDA_KERNEL_LOOP(i, n) for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < (n); i += blockDim.x * gridDim.x) #define GET_BLOCKS(n, t) (n+t-1) / t // == Dimension rearrangeme...
15,985
// reverseArray.cu // Chenfeng Hao // HW 7 // reverse in place #include <iostream> #include <cstdlib> #include <chrono> using namespace std; #define ARRAY_SIZE 20 #define BLOCK_SIZE 4 __global__ void cu_reverseArray(int arr_in[]) { // compute thread index // use it to retrieve block and thread IDs ...
15,986
#include <iostream> #include <iterator> #include <algorithm> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <cuda.h> #include <sys/times.h> #include <stdint.h> void start_clock(void); void end_clock(char *msg); static clock_t st_time; static clock_t en_time; static struct tms st_cpu; static ...
15,987
#include "includes.h" __global__ void pool(unsigned char* image, unsigned char* new_image, unsigned height, unsigned width, int thread_count) { // process image int offset = (blockIdx.x * blockDim.x + threadIdx.x)*4; for (int i = offset; i < (width*height); i+=(thread_count*4) ) { int x = i % (width * 2) * 2; int y = ...
15,988
#include <stdio.h> #include <math.h> #include <cuda.h> #define BLOCK_DIM 16 #define CHANNELS 3 /** * Kernel for conversion * * @param Pout Value of the pixel point in grey scale image * @param Pin Value of the pixel point in color image * @width width of image * @height height of image */ __glob...
15,989
#include <stdlib.h> #include <stdio.h> #define N 512 #define THREADS_PER_BLOCK 8 __global__ void deviceAdd(int* a, int* b, int* c){ int index = threadIdx.x + blockIdx.x * blockDim.x; c[index] = a[index] + b[index]; } void hostAdd(int* a, int* b, int* c){ for(int index = 0; index < N; index++){ c[index] = a[inde...
15,990
#include <stdio.h> #include <sys/time.h> ////////////////////////////////////////////////////////////// // Simple vector addition in CUDA with Unified Memory ////////////////////////////////////////////////////////////// #define N 1024*1024 //Number of elements in the vector // Definition of the kernel that will ...
15,991
// NaiveDTF_cuda is used to verify the correctness of other FFT version. // struct NaiveDFT_cuda { // static constexpr char Name[] = "NaiveDFT_cuda"; // const std::size_t N; // NaiveDFT_cuda(std::size_t N) : N(N) {} // ~NaiveDFT_cuda(){cudaDeviceReset();} // void dft(Comp* Y, const Comp* X){ // ...
15,992
#include <cstdio> __global__ void helloFromGPU() { printf("Hello from GPU thread %d!\n", threadIdx.x); } int main() { helloFromGPU<<< 1, 10 >>>(); cudaDeviceSynchronize(); return 0; }
15,993
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> const int BLOCKSIZE = 128; const int NUMBLOCKS = 1000; // set this to 1 or 2 for debugging const int N = BLOCKSIZE*NUMBLOCKS; struct GpuTimer { cudaEvent_t start; cudaEvent_t stop; GpuTimer () { cudaEventCreate(&start); cudaEventCreate(&stop);...
15,994
void convLayer_backward_wgrad(int M, int C, int H, int W, int K, float* dE_dY, float * X, float * dE_dW) { int m,c,h,w,p,q; int H_out = H-K+1; int W_out = W-K+1; for(m = 0; m < M; m++) for(c = 0; c < C; c++) for(p = 0; p < K; p++) for(q = 0; q < K; q++) dE_dW[m,c,p,q] = 0.; for(m = 0; m < M; m++) f...
15,995
#include <stdio.h> #include <stdlib.h> struct node{ int dst; struct node* next; }; struct list{ struct node *head; }; struct graph{ int n; struct list* set; }; extern __managed__ struct node* newnode; extern __managed__ struct graph* newgraph; /*struct node* new_node(int dst){ cudaMallocManaged(&newnode, s...
15,996
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <sys/resource.h> //134217728 // Definición de nuestro kernel para función cuadradoV __global__ void sumV_kernel_cuda(double *arrayA,double *arrayB , int n){ unsigned long int global_id = blockIdx.x * blockDim.x + threadIdx.x; if (global_id...
15,997
#include <cuda.h> #include <device_launch_parameters.h> #include "float.h" extern "C" { __global__ void DrawBoxPlotKernel(int* box, // all vals int boxIdx, // actual value int ax, // top-left corner x int ay, // top-left corner y int textureWidth, int textureHeight, int boxWidth, int boxHeight, floa...
15,998
//THRUST #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/reduce.h> #include <thrust/functional.h> //STL #include <algorithm> #include <cstdlib> #include <time.h> using std::cout; using std::endl; __global__ void emptyKernel( void ){}; int main(void) { ...
15,999
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #define BLOCK_SIZE 32 #define WA 64 #define HA 64 #define HC 3 #define WC 3 #define WB (WA - WC + 1) #define HB (HA - HC + 1) #define CHANNEL_SIZE 3 __global__ void Convolution(float* A, float* B, float* C) { int col = blockIdx.x * (BLOCK_SIZ...
16,000
//#include "cuda_runtime.h" //#include "device_launch_parameters.h" //#include <stdio.h> //#include <stdlib.h> //#include <fstream> //#include <string> //#include <sstream> // //__global__ void checkCorrectness(int data[9][9], int* d_number_presence) //{ // extern __shared__ int number_presence[]; // int idx = blockDim...