serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
4,701
#include "includes.h" __global__ void kDot_m1T_m2(const int nThreads, const float *m1, const float *m2, float *output, const int m1_rows, const int m1_columns, const int m2_columns ){ /* Increments the output matrix with the product of two matrices: m1 transposed and m2. Inputs: m1: array, left matrix of size m1_rows ...
4,702
#include <stdio.h> #define N 2048 * 2048 // Number of elements in each vector /* * Optimize this already-accelerated codebase. Work iteratively, * and use nsys to support your work. * * Aim to profile `saxpy` (without modifying `N`) running under * 20us. * * Some bugs have been placed in this codebase for your...
4,703
#include <iostream> using namespace std; #define N 32 #define NT 16 #define NB 2 // reduction with 2 blocks of 16 each __global__ void reduction(int * input, int * output) { __shared__ int tmp[NT]; tmp[threadIdx.x] = input[threadIdx.x + blockIdx.x * blockDim.x]; __syncthreads(); // 16 -> 8 if (threadIdx.x ...
4,704
#include <stdio.h> #include <assert.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #define warp_size 32 #define Hwarp_size 16 #define A 0 #define B 15 void checkCUDAError(const char* msg); __host__ __device__ inline double f(double x) { return exp(x)*sin(x); } __host__ __device__ inline unsigned in...
4,705
/* Simple example on using the Unified Memory https://devblogs.nvidia.com/parallelforall/ To compile nvcc managedMemoryAdd.cu -o managedMemoryAdd To profile nvprof ./managedMemoryAdd */ #include <iostream> #include <stdio.h> #include <math.h> // Simple kernel to add elements __global__ void addSingleThread(int n, f...
4,706
#include <stdlib.h> #include <math.h> void distance(float *dist,int dim,int *m,int *n) { int i,j,k,h=0; float x[3],dm[3]; float voxel_side = 2.0f; h = 0; dm[0] = (float)m[0]; dm[1] = (float)m[1]; dm[2] = (float)m[2]; for (i=0;i<m[0];i++) { x[0] = (float)i; if (dm[0]/2. < x[0] && x[0] < dm[0]) x[...
4,707
// fermi // Avoid mangling of function names extern "C" { __global__ void matmulKernel (int n, int m, int p, float* c, const float* a, const float* b); } __global__ void matmulKernel (int n, int m, int p, float* c, const float* a, const float* b) { const int ttj = threadIdx.x; const int wtj = threadIdx....
4,708
//============================================================================ // Name : AddingVectors.cu // Author : Rashi Goyal // Version : // Copyright : Your copyright notice // Description : Vector Addition using CUDA & C++, //=====================================================================...
4,709
#include<cmath> /* // make sure function are inlined to avoid multiple definition #ifndef __CUDA_ARCH__ #undef __global__ #define __global__ inline __attribute__((always_inline)) #undef __forceinline__ #define __forceinline__ inline __attribute__((always_inline)) #endif */ namespace edm { template<typename X, typen...
4,710
#include <cstdio> #include <cstdlib> static const int DIM = 128; __global__ void Normalize128(float *data, const int N) { float tmp[DIM]; float norm1 = 0; float *start = data + threadIdx.x + blockIdx.x*blockDim.x; #pragma unroll for (int i = 0; i < DIM; ++i) { tmp[i] = *start; norm1 += abs(tmp[i]); ...
4,711
#include "includes.h" __global__ void cunnx_WindowGate2_updateOutput_kernel( float *output, float *centroids, float *normalizedCentroids, float *inputIndice, float *outputIndice, const float *input, const float *noise, int inputSize, int outputSize, int inputWindowSize, int outputWindowSize, int windowStride, int train...
4,712
#include "includes.h" __global__ void force_calc_EMA ( float *Force, double *Force_old, int num_atom, int num_q, float *f_ptxc, float *f_ptyc, float *f_ptzc, int num_atom2, int num_q2, int *Ele, double EMA_norm, float force_ramp) { // Do column tree sum of f_ptxc for f_ptx for every atom, then assign threadIdx.x == 0 (...
4,713
#include <bits/stdc++.h> #include <cuda.h> using namespace std; #define CEIL(a,b) ((a-1)/b+1) #define N 1024 __global__ void Sum(float* d_a,float* d_b,float* d_c,int r,int c) { int x=blockIdx.x*blockDim.x + threadIdx.x; int y=blockIdx.y*blockDim.y + threadIdx.y; int index=c*y+x; if(x<c && y<r) ...
4,714
#include <iostream> using namespace std; __global__ void cube(float * d_out, float * d_in){ int idx = threadIdx.x; float val = d_in[idx]; d_out[idx] = val*val*val; } int main(){ const int ARRAY_SIZE = 96; const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float); float h_in[ARRAY_SIZE]; float h_out[ARRAY_SIZE]; ...
4,715
#include <iostream> #include "cuda_runtime.h" #include "device_launch_parameters.h" #include "definitions.cuh" #include <time.h> #include "stdio.h" //Number of elements on which to perform CFD unsigned int Ni = 512; // Y elements unsigned int Nj = 512; // X elements unsigned int nIterations = 10000; // No Of Iteration...
4,716
#include "cuda_runtime.h" #include "device_launch_parameters.h" __global__ void touchMemory(float* memory) { const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; }
4,717
#include <iostream> #include <cuda.h> #include <stdlib.h> #include <ctime> #include <cmath> #include <limits> __global__ void sum_vectors(double *a, double *b, double *c, int size){ int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < size) { c[idx] = a[idx] + b[idx]; } } int check(double *a...
4,718
#include "includes.h" extern "C" extern "C" __global__ void dropoutTrain( const float* arguments, float* dropoutMask, float* results, const float dropoutFraction, const long size ) { const int X = gridDim.x; const int index = gridDim.y * X * threadIdx.x + X * blockIdx.y + blockIdx.x; if(index < size) { const float ma...
4,719
/* * Copyright 1993-2009 NVIDIA Corporation. All rights reserved. * * NVIDIA Corporation and its licensors retain all intellectual property and * proprietary rights in and to this software and related documentation and * any modifications thereto. Any use, reproduction, disclosure, or distribution * of this ...
4,720
/******************************************************************* * * DESCRIPTION: This program performs the multiplication between * a matrix and a vector in a GPU * * AUTHOR: Eduardo Gutarra Velez * * DATE: 02/01/2010 * *******************************************************************/ #include <ios...
4,721
#define t_max 1 #define t 1 /* (ux[0][0][0][0][1]=(alpha*(u[1][0][0][0][0]+u[-1][0][0][0][0]))) (uy[0][0][0][0][2]=(beta*(u[0][1][0][0][0]+u[0][-1][0][0][0]))) (uz[0][0][0][0][3]=(gamma*(u[0][0][1][0][0]+u[0][0][-1][0][0]))) */ __global__ void gradient(float * * ux_1_0_out, float * * uy_2_0_out, float * * uz_3_...
4,722
#include<stdio.h> #include<iostream> #include <thrust/device_vector.h> #include <thrust/host_vector.h> int main(int argc, char **argv) { FILE *fptr; int ch=1; int inputLength; /* parse the input arguments */ //@@ Insert code here // Import host input data //@@ Read data from the raw files here //@@ ...
4,723
template<typename T> __device__ void getRow(const T* matrix, const int row, T* result, const int rows, const int cols) { int bx = blockIdx.x; int tx = threadIdx.x; int index = bx * blockDim.x + tx; result[index] = matrix[row * cols + index]; } template<typename T> __device__ void matrixAd...
4,724
#include "device_launch_parameters.h" #include <stdio.h> /* enum Type { NOT_NODE = 0, AND_NODE, IMPLIES_NODE, UNIVERSAL_NODE, EXISTENTIAL_NODE, BFUNC_NODE, EMPTY_NODE, SAME, SZ_SPD_CLOSE, SZ_LOC_CLOSE, SZ_LOC_DIST, SZ_LOC_DIST_NEQ , SZ_LOC_RANGE, OR_NODE };*/ #define NOT_NODE 0 #define AND_NODE 1 #define...
4,725
#include "includes.h" __global__ void calc(float *result, float *b, float *a, int size){ int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < size){ float temp; for (int j = 0; j < size; j++){ temp = *(a + j + (idx * size)) * (*(b + j)); atomicAdd(&result[idx], temp); } } }
4,726
#include "includes.h" __global__ void dot_cmp_kernal_reduce(float *g_idata1, float *g_idata2, float *g_odata) { extern __shared__ float sdata[]; // each thread loads one element from global to shared mem unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x*(blockDim.x*2) + threadIdx.x; sdata[tid] = g_idata1[i]*g...
4,727
#include <iostream> #include <fstream> #include <vector> #include <stdio.h> #include <algorithm> #include <time.h> using namespace std; void readInt(int &n, int &m) { ifstream fin_n("data/nums.txt"); fin_n >> n >> m; } void readGraph(unsigned long long *neib, int n, int m) { ifstream fin_g("data/graph.txt"); vec...
4,728
#include <vector> #include <iostream> #include <sstream> #include <fstream> #include <string> #include <climits> #include <cmath> const int DIMENSION = 3; const int BLOCK_SIZE = 1024; const int BLOCK_ITEMS = 2048; const int EXPONENT = 11; const int DEVICE_ID = 0; const int ELEMENTS = DIMENSION * DIMENSION; void read_...
4,729
#ifndef THREADS_PER_BLOCK #define THREADS_PER_BLOCK 1024 #endif __global__ void vc(float *dA, float *dB, int N) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < N) { dA[id] = dB[id]; } } extern "C" { void vcGPU(float* A, float *B, int start, int end, int GPUN) { float *dA, *dB; cudaM...
4,730
/* * This is a CUDA version of bellman_ford algorithm * Compile: nvcc -std=c++11 -arch=sm_52 -o cuda_bellman_ford cuda_bellman_ford.cu * Run: ./cuda_bellman_ford <input file> <number of blocks per grid> <number of threads per block>, you will find the output file 'output.txt' * */ #include <string> #include <casse...
4,731
__global__ void rgb2gray(double * result, double * * I, int rows, int cols) { *result = rows; }
4,732
#include "includes.h" __global__ void computeCost(const double *Params, const float *uproj, const float *mu, const float *W, const bool *match, const int *iC, const int *call, float *cmax){ int NrankPC,j, NchanNear, tid, bid, Nspikes, Nthreads, k, my_chan, this_chan, Nchan; float xsum = 0.0f, Ci, lam; Nspikes ...
4,733
#include "includes.h" __global__ void ReferenceGemm_kernel( int M, int N, int K, float alpha, float const *A, int lda, float const *B, int ldb, float beta, float *C, int ldc) { int i = threadIdx.x + blockIdx.x * blockDim.x; int j = threadIdx.y + blockIdx.y * blockDim.y; if (i < M && j < N) { float accumulator = 0; f...
4,734
/****************************************************************************** *cr *cr (C) Copyright 2010 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr *****************************************************************...
4,735
#include <cstdio> #include <cstdlib> #include <iostream> #include <ctime> #include <cuda_runtime.h> using namespace std; int main(int argc, char** argv){ int count = 0; cudaGetDeviceCount(&count); if (count == 0) { cerr << "There is no device" << endl; system("pause"); return 0; } int i; for (int i = 0; i ...
4,736
// CUDACast #2 #include <stdio.h> #define SIZE 1024 // Enable to launch on GPU // tells compiler that function is going to be executed // on the gpu and callable on the host __global__ void VectorAdd(int* a, int* b, int* c, int n) { // Select the thread index to figure out how to index into vector int i = threadId...
4,737
#include "cuda_runtime.h" #include <stdio.h> #include <time.h> const int M = 1024; const int N = 512; //2维网格1维线程块 __global__ void VectorAdd(float* a, float* b, float* c) { int thread_id = blockIdx.y * gridDim.x * blockDim.x + blockIdx.x * blockDim.x + threadIdx.x; c[thread_id] = a[thread_id] + b[thread_id]; }...
4,738
#include "includes.h" __global__ void triad(float* A, float* B, float* C, float s) { int gid = threadIdx.x + (blockIdx.x * blockDim.x); C[gid] = A[gid] + s*B[gid]; }
4,739
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <float.h> #include <cublas_v2.h> #include "utils.cuh" #include "gpchange.cuh" /* Minimize the marginal or conditional log likelihood of given data * as a function of the hyper-parameters using conjugate gradient descent. * * The current values of th...
4,740
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, float var_1,float var_2,float var_3,float var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,floa...
4,741
#include "rgb2yuv.cuh" #include <stdint.h> #include <cuda_runtime.h> #define CHECK(res) { if(res != cudaSuccess){printf("Error :%s:%d , ", __FILE__,__LINE__); \ printf("code : %d , reason : %s \n", res,cudaGetErrorString(res));exit(-1);}} #define CUDA(x) cudaCheckError((x), #x, __FILE__, __LINE__) #define CUDA_F...
4,742
#include <stdio.h> #include <fstream> #include <iostream> #include <vector> #include <random> #include <unistd.h> #include <math.h> #include <assert.h> #include <string.h> #include <chrono> /* we need these includes for CUDA's random number stuff */ #include <cuda.h> #include <curand.h> #include <curand_kernel.h> #d...
4,743
//============================================================================================================= /** * @file rapmusic_kernel.cu * @author Christoph Dinh <christoph.dinh@live.de>; * @version 1.0 * @date March, 2011 * * @section LICENSE * * Copyright (C) 2011 Christoph Dinh. All rights reserved...
4,744
/** * The program must read in an NxN matrix with floating point numbers. The program must determine * the index of columns, which contains one element that is equal to the average of the values in * the same column. The outputs are the indices of the columns. */ #include <math.h> #include <stdio.h> #include <stdl...
4,745
//n<=4096, m<=1024 __global__ void approxmatch(int b,int n,int m,const float * __restrict__ xyz1,const float * __restrict__ xyz2,float * __restrict__ match){ const int MaxN=4096,MaxM=1024; __shared__ float remainL[MaxN],remainR[MaxM],ratioR[MaxM],ratioL[MaxN]; __shared__ int listR[MaxM],lc; float multiL,multiR; if...
4,746
#include <stdio.h> __global__ void helloCUDA(float f) { printf("Hello thread %d, f=%f\n", threadIdx.x, f); } int main() { helloCUDA<<<1, 1>>>(1.2345f); //cudaDeviceSynchronize(); return 0; }
4,747
// Compile with "nvcc -o contacts --std=c++11 contacts.cu" // This is a simple kernel with a skeletal demo app showing how to use it. // It ended up a lot faster than I thought it would... // Type Time(%) Time Calls Avg Min Max Name // GPU activities: 46.91% 8.2560us 2...
4,748
#include "includes.h" __global__ void gpu_mull2(float* a, float* b, float* c, int n, int m,int p) { int i = blockIdx.x * 32 + threadIdx.x; int j = blockIdx.y; float sum = 0.0f; for (int k = 0; k < p; ++k) { sum += b[i + n * k] * c[k + p * j]; } a[i + n * j] = sum; }
4,749
#include "includes.h" __global__ void vanrossum_get_indices_to_apply_stdp (int* d_postsyns, float* d_last_spike_time_of_each_neuron, float* d_time_of_last_spike_to_reach_synapse, int* d_index_of_last_afferent_synapse_to_spike, bool* d_isindexed_ltd_synapse_spike, int* d_index_of_first_synapse_spiked_after_postneuron, f...
4,750
#include "includes.h" __global__ void set_valid_pos(int32_t* pos_buff, int32_t* count_buff, const int32_t entry_count) { const int32_t start = threadIdx.x + blockDim.x * blockIdx.x; const int32_t step = blockDim.x * gridDim.x; for (int32_t i = start; i < entry_count; i += step) { if (VALID_POS_FLAG == pos_buff[i]) { po...
4,751
#include "includes.h" __global__ void Add(float *A, int size) { const unsigned int numThreads = blockDim.x * gridDim.x; const int idx = (blockIdx.x * blockDim.x) + threadIdx.x; for (unsigned int i = idx;i < size; i += numThreads) A[i] = A[i]+ A[i]; }
4,752
#include "includes.h" __global__ void relu_grad(float *pre_grad, float *output, 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; if (output[i * cols + j] <= 0) pre_grad[i * cols + j] = 0; }
4,753
// TESTTING
4,754
#include <stdio.h> #include <cuda_runtime.h> #include <cuda.h> #include <chrono> #include <iostream> // Compile with // nvcc -O2 -std=c++11 cuda.cu __global__ void empty() { } int main(int argc, char **argv) { // Error code to check return values for CUDA calls cudaError_t err = cudaSuccess; int threa...
4,755
/** CUDAで学ぶアルゴリズムとデータ構造 ステップバイステップでN−クイーン問題を最適化 一般社団法人 共同通信社 情報技術局 鈴木 維一郎(suzuki.iichiro@kyodonews.jp) コンパイルと実行 $ nvcc -O3 CUDA**_N-Queen.cu && ./a.out (-c|-r|-g) -c:cpu -r cpu再帰 -g GPU 3.バックトラック  各列、対角線上にクイーンがあるかどうかのフラグを用意し、途中で制約を満た さない事が明らか...
4,756
#include <stdio.h> // this should use with MPS __global__ void k() { int i = 0; while (true) { i++; } } int main(int argc, char *argv[]) { int *mem, *mem2; int i; cudaFree(0); size_t avail, total; cudaMemGetInfo(&avail, &total); printf("total available memory: %ld\n", ...
4,757
#include <stdio.h> #include "cuda.h" #define DIM 20 #define TURNS 1 __global__ void gridmean(float grid[DIM][DIM], float tmp_grid[DIM][DIM]){ int x = blockIdx.x * blockDim.x; int y = blockIdx.y * blockDim.y; float tmp = 0; for(int i = x-1; i <= x+1; i++){ for(int j = y-1; j <= y+1; j++){ if(!(i < 0 || j < ...
4,758
#include <stdexcept> #include <algorithm> #include <cuda_runtime.h> #include <iostream> #include <vector> #include <stdlib.h> #include <time.h> template <class T> class dev_array { // public functions public: explicit dev_array() : start_(0), end_(0) {} // constructor explicit dev_ar...
4,759
__global__ void actiune_thread(float* a_d, float* b_d,float *r_d,int N); // Kernelul ce se executa pe device-ul CUDA __global__ void actiune_thread(float* a_d, float* b_d,float *r_d,int N) { /* int i = blockIdx.x*32 + threadIdx.x; int j = blockIdx.y; float sum = 0.0f; for (int k = 0; k < N; ++k) sum += a_d...
4,760
__global__ void gradient_func(double** X, double** Y, long A, long B) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if(i < A && j < B){ X[i][j] = Y[i][j+1]*(1 - pow (tanh (X[i][j]), 2)); } }
4,761
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <time.h> // Input Array Variables float* h_MatA = NULL; // Output Array float* h_VecV = NULL; float* h_VecW = NULL; float* h_NormW = NULL; // Variables to change int GlobalSize = 5000; // this is the dimension of the matrix...
4,762
// Name: U.H. Anuji de Silva // Student Id: 1432292 #include <stdio.h> //inserting stdlib.h library to run Cuda Malloc #include <stdlib.h> #define N 4 int main() { int i, j =0; int A[N][N] = { {1, 5, 6, 7}, {4, 4, 8, 0}, {2, 3, 4, 5}, {2, 3, 4, 5} }; int B[N][N] = { ...
4,763
#include "includes.h" __global__ void kernel(void) { while(1); }
4,764
__global__ void g_getCost_3(float* cost, float* weight, float lambda, int wlen) { __shared__ float _sum[32]; _sum[threadIdx.x] = 0; __syncthreads(); for(int i = 0; i < wlen; i += blockDim.x) { int id = i + threadIdx.x; if(id < wlen) { _sum[threadIdx.x] += weight[id] * weight[id]; } } int len = b...
4,765
#include "includes.h" using namespace std; /* const int sizePoint = 5; const int sizeIndividum = 5; const int mathValueMutation = 5; const float dispersionMutation = 5.0f; const int powCount = 3; const float randMaxCount = 20.0f; */ const int sizePoint = 500; const int sizeIndividum = 1000; const int mathValueMutation...
4,766
/************************************************************************************\ * * * Copyright � 2014 Advanced Micro Devices, Inc. * * Copyright (c) 2015 Mark D. Hill and David A. Wood ...
4,767
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> // matrix transpose: from (out_w * in_w) to (in_w * out_w) #define IN_WIDTH 1000 #define OUT_WIDTH 100 #define N IN_WIDTH * OUT_WIDTH #define BLOCK_SIZE 16 #define MAX_ERR 1e-6 __global__ void ma...
4,768
#include <iostream> #include <chrono> void polynomial_expansion (float* poly, int degree, int n, float* array) { } int main (int argc, char* argv[]) { //TODO: add usage if (argc < 3) { std::cerr<<"usage: "<<argv[0]<<" n degree"<<std::endl; return -1; } int n = atoi(argv[1]); //TODO: at...
4,769
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <cuda.h> //#define SHARED_SIZE_LIMIT 1024 #define NUM_THREADS 1024 #define NUM_BLOCKS 32768 #define NUM_VALS NUM_THREADS*NUM_BLOCKS #define SHARED_SIZE_LIMIT 1024 int random_float() { return (int)rand()/(int)RAND_MAX; } void array_print(int *arr, i...
4,770
#include <stdio.h> // __global__ 告诉编译器这个函数会从CPU中调用,然后在GPU上执行 __global__ void helloFromGPU(void) { printf("Hello world from GPU!\n"); } int main(void) { printf("Hello world from CPU!\n"); // <<<意为着主线程到设备端代码的调用。一个内核函数通过一组线程来执行,所有线程执行相同的代码。10个GPU线程被调用。 helloFromGPU <<<1, 10>>>(); // 显示的释放和清空当前进程中与当前设备有关的所有资源 cudaDe...
4,771
// Note this file isn't configured to automatically compile #include <device_functions.h> #include <device_launch_parameters.h> // Build: // nvcc -l cuda -o microbench microbench.cpp // nvcc -arch sm_50 -cubin microbench.cu // Inspect a cubin (use nvdisasm from cuda 6.5 for best results): // maxas.pl -e microbench....
4,772
#include<bits/stdc++.h> #include<cuda_runtime.h> #include<device_launch_parameters.h> using namespace std; #define N 2048 void initialise(int* v,int n){ for(int i = 0;i<n;i++){ v[i] = rand()%1000; } } __global__ void mat_vec_mult(int* mat,int*v,int* res,int n){ int tid = threadIdx.x; res[tid] = 0; for...
4,773
/*************************************************** * Module for PIR * * To be compiled with nvcc -ptx pir.cu * Debug: nvcc -arch=sm_20 -ptx pir.cu * Note: CUDA may not support all versions of gcc; * See * https://groups.google.com/forum/#!topic/torch7/WaNmWZqMnzw **************************************************/ /...
4,774
#include "includes.h" __global__ void stencil_1d(int *in, int *out, int dim) { __shared__ int temp[BLOCK_SIZE + 2*RADIUS]; int lindex = threadIdx.x + RADIUS; int gindex = threadIdx.x + blockDim.x * blockIdx.x; int stride = gridDim.x * blockDim.x; int left, right; // Go through all data // Step all threads in a block...
4,775
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 1000 //Job size = 1K, 10K, 100K, 1M and 10M //add kernel __global__ void add(int *a, int *b, int *c) { c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x]; } //function to generate random numbers void random_ints(int* x, int size) { int i; for (i=0;i<...
4,776
void modify_param(int x) { /*@ requires x == 10; ensures x == 11; */ x++; } void test1(unsigned int s) { /*@ requires s > 0; ensures s >= 0; */ s /= 2; }
4,777
#include "includes.h" __global__ void Copy_matA_to_matB_withShuffleIdx (float * A , float * B , int size, int cols , float * new_idxs, int max_rows){ int id = blockDim.x*blockIdx.y*gridDim.x + blockDim.x*blockIdx.x + threadIdx.x; int irow = id / cols; int icol = id % cols; if (id<size){ int irow_new = max_rows - 1 - i...
4,778
#include "includes.h" __global__ void recenter_3D(float* coords, size_t dim_z, size_t dim_y, size_t dim_x){ size_t index = blockIdx.x * blockDim.x + threadIdx.x; size_t total = dim_x * dim_y * dim_z; if(index < total){ coords[index] += (float)dim_z/2.0; coords[index + total] += (float)dim_y/2.0; coords[index + 2 * tota...
4,779
#include <assert.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define BLOCK_SIZE 512 #define MAX_POINTS 100000000 // 100M points #define MAX_MEANS 1000 #define MAX_ITER 30 // CUDA prefers struct-of-arrays style here (for cache purposes) typedef struct { double *x...
4,780
#include "includes.h" #define WARP_SIZE 32 // # of threads that are executed together (constant valid on most hardware) /* Simple CUDA example showing: 1) how to sum the values of an array in parallel 2) how to add a scaler to values of an array in parallel 3) how to query GPU hardware Compile with minimum archetect...
4,781
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <time.h> #include <cuda.h> void initialize(int *menacc, int *womenacc, int *menpre, int *womenlock, int n) { int i; for(i=0; i<=n; i++) { menacc[i] = -1; womenacc[i] = -1; menpre[i] = 1; womenlock[i] = 0; }...
4,782
#include <stdio.h> #include <cuda.h> #include "mytime.h" __global__ void bankcheck() { __shared__ unsigned s[1024]; s[1 * threadIdx.x] = threadIdx.x; } __global__ void bankcheck2() { __shared__ unsigned s[1024]; s[32 * threadIdx.x] = threadIdx.x; } int main() { int ii; double start, end; bankcheck<<<1, 32>>>(...
4,783
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void addThreadId() { int i = threadIdx.x; printf("Hello world! My threadId is %d\n",i); } int main() { const int threads = 256; addThreadId <<<1, threads >>> (); cudaDeviceSynchronize(); return 0; }
4,784
#pragma region License /* The MIT License Copyright (c) 2009 Sky Morey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, m...
4,785
#include <cuda.h> #include <iostream> #include <random> #include <chrono> #define N 300000 #define checkCudaErrors(msg) err_msg(msg, __LINE__) void err_msg(cudaError_t msg, int x) { if (msg != cudaSuccess) { std::cerr << "In line: " << x << ". error: " << cudaGetErrorString(msg) << std::endl; exit(1); } re...
4,786
#include "includes.h" __global__ void vecmabite( int *out, int *in, int threads, std::size_t size ) { auto tid_x = threadIdx.x; auto tid_b = blockIdx.x; out[ tid_x + threads * tid_b] = in[ 2 * (tid_x + threads * tid_b) ]; }
4,787
#include "includes.h" __global__ void ShortestPath1(float *Arr1,float *Arr2,int N,int rows, int rank){ //rowNum is number of rows for each process (full assigned to process) //Arr1 input array,Holds of (u,v) //Arr2 output array int k; int col=blockIdx.x * blockDim.x + threadIdx.x; int row=blockIdx.y * blockDim.y +...
4,788
#include "includes.h" /* Sample input file format: 1.Line : 6 => Number of nodes(int) 2.Line : 7 => Number of edges(int) 3.Line : 1 2 5.0 ---------------- 4.Line : 2 3 1.5 | 5.Line : 1 3 2.1 | 6.Line : 1 4 1.2 |=> Edges 7.Line : 1 5 15.5 | 8.Line : 2 5 3.6 | 9.Line : 3 6 1.2-----------------...
4,789
#include "includes.h" __global__ void sgemm_kernel(const float *A, const float *B, float *C, int M, int N, int K, float alpha, float beta) { int col = blockIdx.x * blockDim.x + threadIdx.x; int row = blockIdx.y * blockDim.y + threadIdx.y; float element_c = 0.f; for (int e = 0; e < K; e++) element_c += A[row * K + e] *...
4,790
#include <stdlib.h> #include <stdio.h> #include <math.h> #define N 10000 #define TPB 128 /* indica o no. de threads por bloco */ __global__ void add( int *a, int *b, int *c ) { /* * threadIdx.x contém o Id da thread a ser executada * blockIdx.x contém o Id do bloco * blockDim.x contém o nr de thr...
4,791
#include <fstream> #include <iostream> #include <cuda_runtime.h> // C++ Program for Floyd Warshall Algorithm //#include <bits/stdc++.h> #include <chrono> #include <ctime> using namespace std; /* Define Infinite as a large enough value.This value will be used for vertices not connected to each other */ #defi...
4,792
#include "includes.h" __global__ static void solveEnd ( double* data, const double a, const double b, const double d, const double e, const double omega_11, const double omega_12, const double omega_21, const double omega_22, const int nx, const int nBatch ) { // Matrix index int globalIdx = blockDim.x * blockIdx.x ...
4,793
#include <stdio.h> #include <stdlib.h> #define SIZE 8 __global__ void addArray(double * result, double * array); int main(){ cudaEvent_t start,stop; float elapsedtime; //the moment at which we start measuring the time cudaEventCreate(&start); cudaEventRecord(start,0); double array[SIZE]; double result[SI...
4,794
#include<iostream> using namespace std; __global__ void MatrixMulKernel(float *Md,float *Nd,float *Pd,int Width){ int tx=threadIdx.x; int ty=threadIdx.y; float Pvalue=0; for(int k=0;k<Width;k++){ float Mdelement=Md[ty*Width+k]; float Ndelement=Nd[k*Width+tx]; Pvalue+=Mdelement*Nd...
4,795
#include <stdio.h> #include <cuda_runtime_api.h> namespace LSW_CUDA{ template<typename real> __global__ void EleProductKernelFun(const real* v1, const real* v2, real* v1v2,int N){ int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N){ v1v2[i] = v1[i]*v2[i]; } } /** * use cuda to compute the pe...
4,796
#include "includes.h" __global__ void sum_partial(double4 *a, double4 *b, unsigned int nextsize){ unsigned int i = blockIdx.x*blockDim.x + threadIdx.x; if(i >= nextsize) return; extern __shared__ double4 shaccelerations[]; double4 *shacc = (double4*) shaccelerations; double4 myacc; myacc = b[i]; shacc[threadIdx.x] ...
4,797
/* Please use "inp.txt" as input file and output/write your results of each question to a separate file named as "q1a.txt", "q1b.txt" etc. The output file should have the same format as the input file. You only need to submit three source code files, e.g. q1.cu, q2.cu and q3.cu and the input file "inp.txt". Don't subm...
4,798
// // Assignment 1: ParallelSine // CSCI 415: Networking and Parallel Computation // Spring 2017 // Name(s): Kelan Riley // Sine implementation derived from slides here: http://15418.courses.cs.cmu.edu/spring2016/lecture/basicarch // standard imports #include <stdio.h> #include <math.h> #include <iomanip> #include <i...
4,799
// Ref:https://github.com/PacktPublishing/Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA/blob/master/Chapter2/03_thread_execution_example.cu #include <iostream> #include <stdio.h> __global__ void myfirstkernel(void) { printf("Hello! I'm thread in block: %d\n", blockIdx.x); } int main() { myfi...
4,800
#include "math.cuh" template <typename T> __device__ double degree_to_radian(T degree){ double PI = 3.1415926535897932384626433832; double radian = degree * PI / 180; return radian; } template __device__ double degree_to_radian<int>(int degree); template __device__ double degree_to_radian<double>(double degree);...