serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
17,701
#include <iostream> #include <chrono> #define BLOCKSIZE 512 __global__ void polynomial_expansion(float *poly, int degree, int n, float *array) { //TODO: Write code to use the GPU here! //code should write the output back to array int index = threadIdx.x + blockIdx.x * blockDim.x; if (index < n) { ...
17,702
#include <stdio.h> __global__ void initWith(float num, float *a, int N) { int index = threadIdx.x + blockIdx.x * blockDim.x; int stride = blockDim.x * gridDim.x; for(int i = index; i < N; i += stride) { a[i] = num; } } __global__ void addVectorsInto(float *result, float *a, float *b, int N) { int in...
17,703
#include <bits/stdc++.h> #include <thrust/device_vector.h> #include <thrust/copy.h> #include <thrust/execution_policy.h> #define to_ptr(x) thrust::raw_pointer_cast(&x[0]) #define gpu_copy(x, y) thrust::copy((x).begin(), (x).end(), (y).begin()) #define gpu_copy_to(x, y, pos) thrust::copy((x).begin(), (x).end(), (y).begi...
17,704
#include <cstdio> #include <cstring> #include <fstream> #include <string> #define BASE_OFFSET 256 #define THREAD_SIZE 564 #define M_BLOCK_OFFSET 0 #define M_H_OFFSET 128 #define W_OFFSET 160 #define WV_OFFSET 416 #define NONCE_INPUT_OFFSET 448 #define DIGEST_OFFSET 528 #define THREAD_VAR(offset) (shared_mem + BASE_O...
17,705
/* * a simple test */ __shared__ float data1[32]; __shared__ float data2[32]; __shared__ float data3[32]; __device__ void mult(__shared__ float d1[32], __shared__ float d2[32], __shared__ float d3[32], int idx) { int i; int j, k, l; j = 0; k = ...
17,706
/* GPU Kernels for the mesh to particles functions @author: Stefan Hegglin, Adrian Oeftiger */ extern "C" { __global__ void mesh_to_particles_2d(int nparticles, double* particles_quantity, double *mesh_quantity, const int stridex, ...
17,707
/** * CUDA kernels for convolution. * * Yujia Li, 03/2015 */ #include "cudamat_conv_kernels.cuh" __global__ void kConvolveV1(float* image, float* filter, float* target, int n, int c, int im_h, int im_w, int n_ftr, int ftr_h, int ftr_w) { const int target_h = im_h - ftr_h + 1; const int target_w =...
17,708
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #define NUM_BLOCKS 16 #define THREADS 1 __global__ void helloWorld() { printf("Hello Worlds! I'm a thread in block %d \n", blockIdx.x); } int main(int argc, char ** argv) { helloWorld <<< NUM_BLOCKS, THREADS >>> (); cudaDevice...
17,709
#include <cuda.h> #include <cuda_runtime.h> #include <iostream> #include <math.h> using namespace std; const int N = 5; //data on device float * dev_matA; float * dev_matB; float * dev_res; //data on host float * matA = (float *)malloc(N*N*sizeof(float)); float * matB = (float *)malloc(N*N*sizeof(float)); float * re...
17,710
#include <iostream> #include <cstdlib> #include <cstdio> using namespace std; void YukSerial(float2* pos, float2* acc, float k, int N){ float2 del; float r2, r; float kr; float termo; for (int i=0; i<N; i++){ for (int j=0; j<N; j++){ if (i!=j){ //Calculate distances del.x = pos[i].x - pos[j]....
17,711
#include <type_traits> #ifdef _WIN32 # define EXPORT __declspec(dllexport) #else # define EXPORT #endif using tt = std::true_type; using ft = std::false_type; EXPORT int __host__ shared_cuda11_func(int x) { return x * x + std::integral_constant<int, 17>::value; }
17,712
#include<cstdio> #include<iostream> using namespace std; int main() { cout<<"Hello World!"<<endl; return 0; }
17,713
#include <iostream> #include <memory> #include <cassert> using namespace std; #include <cuda.h> struct MyStruct { float *p1; float *p2; }; __global__ void struct_byvalue(struct MyStruct mystruct) { mystruct.p1[0] = 9.0f; mystruct.p2[0] = 10.0f; } __global__ void struct_aspointer(struct MyStruct *m...
17,714
#include<stdio.h> #include<math.h> #include<time.h> #define N 256 void matrix_vecter_multi_cpu(float *A,float *B,float *C){ int i,j; for(j=0;j<N;j++){ A[j]=0.0F; for(i=0;i<N;i++){ A[j]=A[j]+B[j*N+i]*C[i]; } } } int main(){ int i,j; float A[N],B[N*N],C[N]; clock_t start,end; for(j=0...
17,715
__device__ double _sum_reduce(double buffer[]) { int nTotalThreads = blockDim.x; __syncthreads(); while (nTotalThreads > 1) { int halfPoint = ((1 + nTotalThreads) >> 1); if (threadIdx.x >= halfPoint) { double temp = 0.0; if (threadIdx.x < nTotalThreads) { te...
17,716
#include<cuda_runtime_api.h> #include <stdio.h> #include <cuda.h> inline int n_blocks(int size, int block_size) { return size / block_size + ((size % block_size == 0)? 0 : 1); } __global__ void _max_stride(float *src,float *dst, int stride, int src_ldx, int dst_ldx, int step, int size, int *mask) { int i,r; ...
17,717
/** * CUDA MD5 cracker * Copyright (C) 2015 Konrad Kusnierz <iryont@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) an...
17,718
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <inttypes.h> #include <cuda.h> #include <cuda_runtime.h> #define BLOCK_WIDTH 32 #define TAILLE 4096 #define gettime(t) clock_gettime(CLOCK_MONOTONIC_RAW, t) #define get_sub_seconde(t) (1e-9*(double)t.tv_nsec) /** return time in second */ double get_ela...
17,719
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <complex.h> #include <cuda.h> #include <cuComplex.h> #include <png.h> #include <time.h> __global__ void gen_fractal(double centerX, double centerY, double scale, unsigned int *output, double const_real, double const_imag, unsigned s...
17,720
#include <cuda.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <math.h> /* Convert the index of 2D Matrix in 1D array*/ #define index(i, j, N) ((i)*(N)) + (j) /*****************************************************************/ /* Function declarations used in the program */ // CPU Implementaion...
17,721
extern "C" { __global__ void multiply_step(size_t* size, double* in, double* out,double* factor) { for (int i = blockDim.x * blockIdx.x + threadIdx.x; i < size[0]; i += gridDim.x * blockDim.x) { out[i] = in[i] * factor[0]; } } } extern "C" { __global__ void add_step(size_t* size, double* in, double* in2, doubl...
17,722
#include<stdio.h> // called kernel in GPU ( in CPU its called function) __global__ void hello() { //__global__ is specifier indicating function runs in GPU (aka device) printf("Hello CUDA\n"); } int main() { // execute kernal hello <<<1,1>>>(); //<<<M,T>>> M - #ThreadBlock & T - #Threa...
17,723
#include <stdio.h> #include <assert.h> #define THREADS_PER_BLOCK 768 #define ARRAY_SIZE THREADS_PER_BLOCK * 1024 static void HandleError(cudaError_t error, const char *file, int line) { if (error != cudaSuccess) { printf("%s in %s at line %d\n", cudaGetErrorString(error), file, line); exit( EXIT_F...
17,724
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> int NoofReal; int NoofRand; float *real_rasc, *real_decl; float *rand_rasc, *rand_decl; unsigned int *histogramDR, *histogramDD, *histogramRR; long int CPUMemory = 0L; long int GPUMemory = 0L; __global__ void fill...
17,725
#include <stdio.h> #include <cuda.h> #define NUM_THREADS 100 #define BLOCK_DIM 100 #define ARRAY_SIZE 100 __global__ void barriersTestKernel(float* d_arr) { int idx = blockIdx.x * blockDim.x + threadIdx.x; d_arr[idx] += 1; // __syncthreads(); float sum = 0; for (int i = 0; i <= threadIdx.x; i++) { sum += d_ar...
17,726
//Required libraries #include <stdlib.h> #include <assert.h> #include <stdio.h> #include <math.h> #include <string.h> #include <iostream> #include <fstream> #include <sstream> #include <curand_kernel.h> //algorithm params #define ANTS 1024 #define ALPHA 0.2 #define BETA 0.1 #define RHO 0.1 #define Q 10 #define MAX_ITE...
17,727
#include <iostream> using namespace std; #define gpuErrchk(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: %d %s %s %d\n", code, cudaGetErrorString(code), file, line)...
17,728
#include <stdio.h> #include <iostream> using namespace std; #define N_particles 512 #define L 1.0f #define N_particles_1_axis 8 dim3 particleThreads(64); dim3 particleBlocks(N_particles/particleThreads.x); static void CUDA_ERROR( cudaError_t err) { if (err != cudaSuccess) { printf("CUDA ERROR: %s, exiting...
17,729
/* * ECE 5720 Parallel Computing Final Project * KMP parallel on MPI * Feng Qi, fq26 * Ying Zong, yz887 * Cornell University * * Compile : /usr/local/cuda-8.0/bin/nvcc -arch=compute_35 -o cuda kmp-cuda.cu * Run : ./cuda */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> // b...
17,730
#include "includes.h" __global__ void run_reduction(int *con, int *blockCon,int* ActiveList, int nActiveBlock, int* blockSizes) { int list_idx = blockIdx.x; int tx = threadIdx.x; int block_idx = ActiveList[list_idx]; int start = block_idx*blockDim.x * 2; int blocksize = blockSizes[block_idx]; __shared__ int s_block_con...
17,731
__global__ void recurrentKernel () { }
17,732
// // // gpu-poly // // // Polygon functions for the GPU // #include <cstdlib> #include <cstring> #include <cstdio> #include "spatial.cuh" #define CLIP 0 #define SUBJ 1 // // Determines of the specified point is in the specified polygon // // __device__ bool PointInPoly(vertex point, vertex *poly, int polySize)...
17,733
#include<thrust/sort.h> #include<stdio.h> #include<cuda.h> #include<thrust/device_ptr.h> int main() { const int N = 6; int keys_h[N] = { 1, 2, 1, 2, 4, 1}; int values_h[N] = {10,20,300,400,600,200}; int *keys_d,*values_d; size_t size = N * sizeof(int); cudaMalloc((void **) &keys_d, size);...
17,734
#include <cuda.h> #include <stdio.h> #include <math.h> #include <time.h> #include <string.h> #include <stdlib.h> __global__ void mul(float* Ad, float* Bd, float* Cd, int msize); int main(int argc, char **argv){ clock_t start = clock(); int msize; msize = atoi(argv[1]); int i, j; //input matrix float *A,*B,*...
17,735
#ifdef _WIN32 # define EXPORT __declspec(dllexport) #else # define EXPORT #endif void __global__ file2_kernel(int x, int& r) { r = -x; } EXPORT int file2_launch_kernel(int x) { int r = 0; file2_kernel<<<1, 1>>>(x, r); return r; }
17,736
#include <cstdlib> #include <ctime> #include <iostream> __device__ unsigned int Nmax = 10000; template <typename TYPE> __device__ TYPE myAbs(TYPE x) { if (x >= static_cast<TYPE>(0.)) { return x; } else { return -x; } } template <typename TYPE> __device__ TYPE func(TYPE x) { return x*x*x + static_cast<TYPE>(2...
17,737
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <float.h> #include <ctime> #define MAX_RANDOM 2147483647 #define NMAX 100000 #define DEBUG 1 //set level of debug visibility [0=>off,1=>min,2=>max] #define NOISEOFF 0 //set to suppress noise in channel #define N_ITERATION 2 //no. of turbo de...
17,738
extern "C" __device__ void createNewNormal(int* x, int* y, int* z,int* nX, int* nY, int* nZ, int i) { int j = 0; nX[i]=0; nY[i]=0; nZ[i]=0; for (int k = 0; k < 3; k++) { if (k < 2) { j = k + 1; nX[i] += -(y[k] - y[j]) * (z[k] + z[j]); nY[i] += -(z[k] ...
17,739
#include "includes.h" /* This file is copied from https://github.com/jzbonter/mc-cnn */ extern "C" { } #define TB 128 #define DISP_MAX 256 __global__ void Normalize_get_norm_(float *input, float *norm, int size1, int size23, int size023) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < size023) { int dim...
17,740
/*************************************************** * Multiply all the elements of a matrix for the elements of the second one * Author: Alonso Vidales <alonso.vidales@tras2.es> * * To be compiled with nvcc -ptx matrix_mult_all.cu * Debug: nvcc -arch=sm_20 -ptx matrix_mult_all.cu * *****************************...
17,741
#include <cstdlib> #include <cassert> #include <iostream> // this will be the size of our 256 * 1 float array // since we have 256 threads per thread block, we must size our // shared mamory such that each thread can keep at least one element. #define TILE_SIZE 256 // __global__ indicates it will called from the host...
17,742
#include <stdio.h> #include <stdlib.h> #include <time.h> //__global__ --> GPU function which can be launched by many blocks and threads //__device__ --> GPU function or variables //__host__ --> CPU function or variables // Compile this program with ---> nvcc -o PasswordCrack PasswordCrack.cu //This function encr...
17,743
//#include "CudaVideoStitching.cuh" //#include "cuda.h" //#include <iostream> //#include <cufft.h> //#include "cublas_v2.h" //#include <stdio.h> //#include <stdlib.h> // // //CGPUACC::CGPUACC(void) //{ // //} // //CGPUACC::~CGPUACC(void) //{ //}
17,744
typedef enum {DT_UNDEFINED = 0, DT_INT, DT_FLOAT, DT_STRING, DT_BOOLEAN} DataType; typedef enum {OP_UNDEFINED = 0, OP_EQUAL_TO, OP_GREATER_THAN, OP_GREATER_THAN_OR_EQUAL_TO, OP_LESS_THAN, OP_LESS_THAN_OR_EQUAL_TO, OP_LOGICAL_AND, OP_LOGICAL_OR, OP_NOT_EQUAL_TO} Operator; typedef enum {DL_ERROR = 0, DL_FALSE = 1,...
17,745
/** * KERNEL d_MM() - Takes two 2D matrices and multiplies them * Result is divided into threads, each thread iterating over datasets * to obtain the final answer. C[Thread] = Sum { A column * B Row } * @param a - 1st Matrix * @param b - 2nd Matrix * @param c - Result Matrix * @param wA - length of A and depth ...
17,746
#include <iostream> #include <ctime> #include <cstdlib> #include <math.h> #include <stdio.h> #include <iostream> #include <string> #include <stdio.h> using namespace std; #define SIZE 1024 #define MAX_PRIME 1024 #define passwordSize 4 __global__ void PasswordCrack(int *a, int n) { int i = blockDim.x * blockIdx...
17,747
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N 300 #define BLOCK_SIZE 15 struct timeval start, end; // get global offset of a given block and given index in block __device__ int global_offset(int block_row, int block_col, int row, int col) { return block_row*BLOCK_SIZE*...
17,748
#include "includes.h" __device__ __forceinline__ size_t gpu_scalar_index(unsigned int x, unsigned int y) { return NX*y+x; } __device__ __forceinline__ size_t gpu_s_scalar_index(unsigned int x, unsigned int y) { return (2*RAD + nThreads)*y + x; } __global__ void gpu_poisson(double *c, double *fi,double *R){ unsigned int...
17,749
#include "includes.h" //////////////////////////////////////////////////////////////////////////////// /* Hologram generating algorithms for CUDA Devices Copyright 2009, 2010, 2011, 2012 Martin Persson martin.persson@physics.gu.se This file is part of GenerateHologramCUDA. GenerateHologramCUDA is free software: you ...
17,750
/* ============================================================================ Name : cuda_example_1.cu Author : me Version : Copyright : Your copyright notice Description : CUDA compute reciprocals ============================================================================ */ #include <ios...
17,751
#ifndef __STD_KERNEL_CU__ #define __STD_KERNEL_CU__ #ifndef M_PI #define M_PI 3.1415926535897 #endif __device__ int getLargest(double* v) { if (v[0]>v[1]) { if (v[0]>v[2]) { return 0; } else { return 2; } } else { if (v[1]>v[2]) { return 1; } else { return 2; } } } __devic...
17,752
/* * Copyright (c) 2019, 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 ...
17,753
/** * @author Mihai Maruseasc (Mihai.Maruseac001@umb.edu) * * @section DESCRIPTION * Bignum addition on each thread on CUDA. */ #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #ifndef THREADS #define THREADS 128 #endif #ifndef BLOCKS #define BLOCKS 16 #endif #define ...
17,754
#include "cuda_runtime.h" #include "device_launch_parameters.h" __global__ void add(int a, int b, int *c) { *c = a + b; } int calculateAddOnGPU(int a, int b) { int* c = new int(0); cudaMallocManaged(&c, sizeof(int)); add<<<1, 1>>>(a, b, c); cudaDeviceSynchronize(); const unsigned int result = *c; cudaFree(...
17,755
#include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void Vec_add(float x[], float y[], float z[], int n) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < n){ z[i] = x[i] + y[i]; } } int main(int argc, char* argv[]) { int n, i; float *h_x, *h_y, *h_z; float *d_x, *d_y, *...
17,756
#include "includes.h" __global__ void kern_ResetSinkBuffer(float* sink, float* source, float* div, float* label, float ik, float iCC, int size) { int idx = CUDASTDOFFSET; float value = (1.0f-ik)*sink[idx] + ik*(source[idx] - div[idx] + label[idx] * iCC); if( idx < size ) { sink[idx] = value; } }
17,757
#include <iostream> #include <cuda.h> #include <assert.h> #define cudaCheckError(msg) \ do { \ cudaError_t __err = cudaGetLastError(); \ if (__err != cudaSuccess) { \ fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \ msg, cudaGetErrorString(__err), \ ...
17,758
#include <stdio.h> #include <string.h> #include <stdlib.h> #define BYTE unsigned char #define BLOCKSIZE 16 int pic_len; void printBytes(BYTE b[], int len) { int i; for (i=0; i<len; i++) printf("%d ", b[i]); printf("\n"); } /*****************************************************************************...
17,759
#include <stdio.h> void init(int *a, int N) { for (int i = 0; i < N; ++i) { a[i] = 2; } } int main(int argc, char **argv) { int E = 20; if (argc > 1) E = atoi(argv[1]); int N = 2<<E; printf("N is 2<<%d: %d\n", E, 2<<E); int *a; size_t size = N * sizeof(int); cudaMallocManaged(&a, size); ...
17,760
#include<stdio.h> #include<iostream> #include<stdlib.h> #include<assert.h> using namespace::std; __global__ void g_mat_mul( int *a, int *b, int *c, int m){ //Kernel for matrix multiplication on GPU int index = blockIdx.x*blockDim.x + threadIdx.x; for(int i=0; i < m; i++){ //printf("\nValue of a is %d a...
17,761
#include "includes.h" __global__ void NormalizeKernel(const float *normalization_factor, int w, int h, int s, float *image) { int i = threadIdx.y + blockDim.y * blockIdx.y; int j = threadIdx.x + blockDim.x * blockIdx.x; if (i >= h || j >= w) return; const int pos = i * s + j; float scale = normalization_factor[pos];...
17,762
#include "includes.h" __global__ void sxypz_kernel_large(float a, const float* x, const float* y, const float* z, float* result, unsigned int len, unsigned int rowsz) { unsigned int idx = threadIdx.x + blockIdx.x * blockDim.x + blockIdx.y * rowsz; if (idx < len) result[idx] = a * x[idx] * y[idx] + z[idx]; }
17,763
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "cuda_fp16.h" #include <stdio.h> #include <iostream> using namespace std; #define CHECK(call) \ { \ const cudaError_t error = call; \ if (error != cudaSuccess) \ { \ printf("Error: %s: %d, ", __FILE__, __LINE__); \ printf("code: %d, reaso...
17,764
/* This program queries the device information using the built-in API functions, and outputs everything to STDOUT */ /* No GPU programming is involved */ #include <stdio.h> int main(int argc, char **argv) { int device; cudaDeviceProp prop; device = 0; if(argc > 1) device = atoi(argv[1]); cudaGetDevicePr...
17,765
#include <stdio.h> #include <stdlib.h> const int INF = ((1 << 30) - 1); const int V = 20000; void input(char* inFileName); void output(char* outFileName); int ceil(int a, int b); __global__ void phase1(int round, int n, int V, int* Dist, int B); __global__ void phase2(int round, int n, int V, int* Dist, int B); __glo...
17,766
#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...
17,767
#include <stdio.h> #include <pthread.h> const int N = 1 << 27; __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)); } } void *thread(void *args) { int * thread_data = (in...
17,768
#include<iostream> #include<vector> const int N = 16*16; const int sharedMemsize = 16*16*sizeof(float); __global__ void matMultiply(float *A, float *B, float *C){ auto i = blockDim.y * blockIdx.y + threadIdx.y; auto j = blockDim.x * blockIdx.x + threadIdx.x; __shared__ float s_A[sharedMemsize]; __shared__ float...
17,769
/******************************************************************************/ /* CUDA Sample Program (Matrix Multiplication) monotone-RK 2014.11.23 */ /******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time...
17,770
#include "includes.h" __global__ void _negateStencilKernel(int* stencil, int size, int* out) { unsigned int idx = blockDim.x * blockIdx.x + threadIdx.x; if (idx >= size) return; out[idx] = stencil[idx] == 1 ? 0 : 1; }
17,771
#include "includes.h" __global__ void makeHE( float *HE, float *force1, float4 *force2, float *masses, float eps, int k, int m, int N ) { int elementNum = blockIdx.x * blockDim.x + threadIdx.x; int atom = elementNum / 3; if( elementNum >= N ) { return; } int axis = elementNum % 3; if( axis == 0 ) { HE[elementNum * m +...
17,772
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void add(int *a, int *b, int *c) { int i = blockIdx.x; c[i] = a[i] + b[i]; } __global__ void add2(int *a, int *b, int *c) { int i = threadIdx.x; c[i] = a[i] + b[i]; } __global__ voi...
17,773
// Note this file isn't configured to automatically compile. // Here's how: // If you want to look at the ptx first: // nvcc -arch sm_50 -m 32 -ptx sgemm.cu // Manually compile your kernel to a cubin. // You should only have to do this once, unless you change params or shared size or globals: // nvcc -arch sm_50 -m 3...
17,774
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cstdlib> #include <iostream> #include <fstream> #include <string> #include <vector> #include <chrono> using namespace std; template <typename T> struct mat { int rows; int cols; vector<T> data; }; cudaError_t multMatri...
17,775
#include "includes.h" /////////////////////////////////////////////////////////////////////////////// //Round a / b to nearest higher integer value __global__ void calculateSlopeKernel(float* h, float2 *slopeOut, unsigned int width, unsigned int height){ unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; unsigned i...
17,776
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <cuda_runtime_api.h> // Convenience function for checking CUDA runtime API results // can be wrapped around any runtime API call. No-op in release builds. inline cudaError_t checkCuda(cudaError_t result) { //#if defined(DEBUG) || defined(_DEBUG) if...
17,777
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> void CPU_kernel(int max_itemcount) { int i; for (i = 0; i < max_itemcount; ++i) { printf("%i\n", i); } } int main(void) { CPU_kernel(100); printf("Finished execution!\n"); return 0; }
17,778
//CUDE_2d_arraySum_again.cu //Ben Talotta #include "stdio.h" #define COLUMNS 8 #define ROWS 8 //based off sum2darr.cu and kernal test code examples code __global__ void add(int* a,int* c) { __shared__ int cache[COLUMNS]; int tid = threadIdx.x + (blockIdx.x * blockDim.x); int x = threadIdx.x; cache[x] = ...
17,779
#define EPS 0.00001 __device__ float distance(const float2 f1, const float2 f2) { float2 v; v.x = f2.x - f1.x; v.y = f2.y - f1.y; return sqrt(v.x * v.x + v.y * v.y); } __device__ float distance_f2_f(const float2 f1, const float f2_x, const float f2_y) { float2 v; v.x = f2_x - f1.x; v.y = ...
17,780
#include <stdio.h> #define NUM_BLOCKS 8 #define BLOCK_SIZE 64 #define WINDOW_SIZE 3 #define NUM_ELEMENTS (NUM_BLOCKS * BLOCK_SIZE) __global__ void mykernel(int *xp, int *result) { int globalIdx = (blockIdx.x * blockDim.x) + threadIdx.x; int localIdx = threadIdx.x + WINDOW_SIZE; // Keep a local buffer that's fa...
17,781
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #include <ctype.h> __global__ void vectorMult(float *a, float *b, float *c, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; while (i < n) { c[i] = a[i] * b[i]; i+= blockDim.x * gridDim.x; } } int main(int argc, char **argv)...
17,782
#include <stdio.h> #define ABS(X) X < 0 ? -X : X extern "C" float *create_mandelbrot(int res_x, int res_y, float min_x, float min_y, float max_x, float max_y, int iter); __global__ void mandelbrot(float *region, int offset, int2 res, float4 boundary, int iter); /* We define a maximum number of iterations t...
17,783
#include<stdio.h> //#include "cutil.h" #define FADD(a,b) __fadd_rn(a,b) #define sof sizeof(float) #ifdef __DEVICE_EMULATION__ #define EMUSYNC __syncthreads() #else #define EMUSYNC #endif /////////////////////////////////////////////////////////////////////// /** parallel reduction Harris 07 This version adds ...
17,784
#include <stdio.h> // For use of the printf function #include <sys/time.h> // For use of gettimeofday function #define NUM_ITERATIONS 10000 #define ABS(a) ((a) < 0 ? -(a) : (a)) #define DT 1 int NUM_PARTICLES; // # of particles to simulate, equivalent to # of threads int BLOCK_SIZE; // Threads PER block // Gravi...
17,785
// TODO, Sep 21st, 2017 // TODO, right nwo is working on another project, yound man
17,786
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cmath> #define n 10000 #define BLOCK 1000 __global__ void Su(float *a,float *b,float *h) { int i = threadIdx.x + blockIdx.x*blockDim.x; b[i] = (*h)*sqrtf(1 - a[i] * a[i]); } int main() { float a = 0, b = 1; float h = (...
17,787
//MatAdd.cu // author: Pan Yang // date : 2015-7-4 #include <stdio.h> #include <stdlib.h> #include <time.h> #define M 512 // height of A #define N 512 // width of A ( == height of B) #define P 512 // width of B #define BLOCK_SIZE 32 typedef struct { int height; int width; float *elements; }Matr...
17,788
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> long int factorial(int x); long int nCr(int n, int r); struct timeval start, end; void starttime(){ gettimeofday(&start, 0); } void endtime(const char * c){ gettimeofday(&end, 0); double elapsed = (end.tv_sec - start.tv_sec) * 1000....
17,789
#include "includes.h" #define CUDA_CHECK_ERROR #define CudaSafeCall(err) __CudaSafeCall(err, __FILE__, __LINE__) #define CudaCheckError() __CudaCheckError(__FILE__, __LINE__) __global__ void transform(float *input, const float *raw_input, const int width, const int channels) { int thread_id = blockDim.x * blockIdx...
17,790
#include <iostream> #include <string> #include <limits> #include <fstream> #include <algorithm> #define BLOCK_SIZE 512 using namespace std; //floyd-warshall algorithm //finds shortest paths to every vertex in matrix for all vertexes /*__global__ void floyd(int *matrix, int l) { //int LARGE_INT = numeric_limits<int>...
17,791
#include<stdio.h> #include"scrImagePgmPpmPackage.h" //Kernel which calculate the resized image __global__ void createResizedImage(unsigned char *imageScaledData, int scaled_width, float scale_factor, cudaTextureObject_t texObj) { const unsigned int tidX = blockIdx.x*blockDim.x + threadIdx.x; const unsigned int tidY ...
17,792
#include "stdio.h" #include "stdlib.h" __global__ void VecAdd(float* A, float* B, float* C, int N) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) C[i] = A[i] + B[i]; } void array_print(float* array, int size) { for (int i = 0; i < size; i++) { printf("%f ", *(array+i)); } ...
17,793
#include "includes.h" __global__ void compute_shared_inv(const int* destination_offsets, const int* source_indices, const float* out_degrees, const int node_count, const float* input, float *output) { int dest = blockDim.x*blockIdx.x + threadIdx.x; __shared__ int s_dest_off[BLOCK_SIZE + 1]; if (dest<node_count) { s_des...
17,794
#include <iostream> #define N 10000 float *a, *b, *c; __global__ void add(){ } int main() { add<<<1,1>>>(); a = (float*)malloc(sizeof(float)*N); b = (float*)malloc(sizeof(float)*N); c = (float*)malloc(sizeof(float)*N); for (int i = 1; i <= N; i++){ a[i] = i; b[i] = i*2; c...
17,795
//nvcc -ptx EM3.cu -ccbin "F:Visual Studio\VC\Tools\MSVC\14.12.25827\bin\Hostx64\x64" __device__ void EM1( double * Er0, double * Ez0, double * Hphi0, double * Er, double * Ez, double * jr, doub...
17,796
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <assert.h> #include <sys/time.h> #include <vector> #include <limits> #include <iostream> #include <unistd.h> #define THREADS 512 #ifdef __cplusplus extern "C" { #endif using namespace std; float *cu_grid; // initialize grid with all 0 values float* ...
17,797
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand.h> #include <time.h> __global__ void kernel(int* count_d, float* randomnums) { int i; double x,y,z; int tid = blockDim.x * blockIdx.x + threadIdx.x; i = tid; int xidx = 0, yidx = 0; xidx = (i+i); yidx = (xidx+1); x = randomnums[xidx]; ...
17,798
// (c) Copyright 2013 Lev Barash, Landau Institute for Theoretical Physics, Russian Academy of Sciences // This is supplement to the paper: // L.Yu. Barash, L.N. Shchur, "PRAND: GPU accelerated parallel random number generation library: Using most reliable algorithms and applying parallelism of modern GPUs and CPUs". /...
17,799
#include <stdio.h> #include <assert.h> #include <inttypes.h> #include <stdint.h> #include <thrust/execution_policy.h> #include <thrust/reduce.h> #define MAXN 16777216 #define ThreadSize 256 #define SeqSize 1024 #define atomicN ThreadSize __device__ __host__ int CeilDiv(int a, int b) { return (a-1)/b + 1; } __device__...
17,800
#include <stdlib.h> #include <stdio.h> #include <fstream> #include <cuda.h> #include <iostream> #include <iomanip> #include <time.h> using namespace std; #define TILE 16 /* LU Decomposition using Shared Memory \ \ CUDA \ \ \ \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...