serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
6,001
#include <bits/stdc++.h> #include <chrono> using namespace std::chrono; using namespace std; typedef complex<float> base; int n = 4,m = 4,k = 3; template <typename T> ostream &operator<<(ostream &o, vector<T> v) { if (v.size() > 0) o << v[0]; for (unsigned i = 1; i < v.size(); i++) o << " " <...
6,002
// Note that in this model we do not check // the error codes and status of kernel call. #include <cstdio> #include <cmath> __global__ void set(int *A, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < N) A[idx] = idx; } int main(void) { const int N = 128; int *d_A; int *h...
6,003
#include <stdio.h> #include <stdlib.h> #include <math.h> // Maximo numero de blocks sem estourar a capacidade do hardware // (Esse não é o limite real do hardware do parsusy, é apenas uma estimação feita impiricamente) int MAX_N_BLOCK = 1024; // Maximo numero de threads sem estourar a capacidade do hardware // (Ess...
6,004
#include <stdio.h> /*CUDA error wraper*/ static void CUDA_ERROR( cudaError_t err) { if (err != cudaSuccess) { printf("CUDA ERROR: %s, exiting\n", cudaGetErrorString(err)); exit(-1); } } struct Arrays { int* i; int* j; int N; }; __global__ void increment(Arrays d_arrays) { int...
6,005
#include <stdio.h> #include <stdlib.h> typedef struct hib { int * h_a; int * d_a; }hib; int main() { return 0; }
6,006
#include <stdio.h> #include <sys/time.h> #define N 65535 #define T 1024 // max threads per block double myDiffTime(struct timeval &start, struct timeval &end) { double d_start, d_end; d_start = (double)(start.tv_sec + start.tv_usec/1000000.0); d_end = (double)(end.tv_sec + end.tv_usec/1000000.0); return (d_end - ...
6,007
#include <stdio.h> #include <math.h> #ifndef ARRAY_SIZE #define ARRAY_SIZE 256 #endif // !ARRAY_SIZE #define ARRAY_SIZE_IN_BYTES (sizeof(unsigned int) * (ARRAY_SIZE)) #ifndef BLOCK_SIZE #define BLOCK_SIZE 16 #endif // !BLOCK_SIZE /* Declare statically two arrays of ARRAY_SIZE each */ unsigned int cpu_block[ARRAY_...
6,008
/*Ron Pyka CS 553 Assignment 1 GPU Benchmark */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #include <sys/types.h> #include <sys/times.h> #include <sys/time.h> #include <time.h> #define BLOCK_SIZE 16 /* Arrays */ volatile float A[1], B[1000], C[1000000], D[10000][10000]; volati...
6,009
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <cuda.h> #include <curand_kernel.h> // Random Gamma variates in CUDA... // Surprisingly, there doesn't seem to be any standard way to // generate these from the SDK. This is the CUDA port of the // rgamma code as used by R. extern "C" { // __constan...
6,010
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define NUM_THREADS 64 typedef double MYTYPE; __global__ void mat_trans(MYTYPE* a, MYTYPE* at, int size){ // MYTYPE tmp; // threadIdx from 0 to NUM_THREADS // blockIdx = (size*size + NUM_THREADS)/NUM_THREADS int idx = blockIdx.x * blockDim.x + thread...
6,011
#include <algorithm> #include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <thrust/iterator/zip_iterator.h> #include <thrust/random.h> #include <thrust/sort.h> #include <time.h> #define CUDA_CAL...
6,012
// CUDA programming // Exercise n. 00 #include <errno.h> #include <cuda.h> #include <stdio.h> #define BLOCKS 1 #define THREADS 32 // Prototypes void cpu_hello_world(void); __global__ void gpu_hello_world(void); int main(void) { // Call the CPU version cpu_hello_world(); // Call the GPU version gp...
6,013
// fermi /* * Copyright 2018 Vrije Universiteit Amsterdam, The Netherlands * * 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 * Unles...
6,014
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N (2048*2048) #define THREADS_PER_BLOCK 512 __global__ void add( int *a, int *b, int *c ) { c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x]; } int main( void ) { int *a, *b, *c; // host copies of a, b, c int *dev_a, *dev_b, *dev_c; // device copies o...
6,015
#include "includes.h" __global__ void mapScan(unsigned int *d_array, unsigned int *d_total, size_t n) { int tx = threadIdx.x; int bx = blockIdx.x; int index = BLOCK_WIDTH * bx + tx; if(index < n) { d_array[index] += d_total[bx]; } }
6,016
#include "gpu_automata_cuda.cuh" // TODO Experiment with this function #if 1 // 2D-GAME OF LIFE: __device__ bool update_fun(bool *neighbors) { int count = 0; for (int i= 9; i < 18; i++) { if (i != 13) { count += neighbors[i] ? 1 : 0; } } if (neighbors[13]) ...
6,017
/* ============================================================================ Name : Isolated_SW.cu Author : Vuong Pham Duy Version : Copyright : Your copyright notice Description : debugging Smith-Waterman Score Matrix Kernel ==================================================================...
6,018
#include <stdio.h> #include <math.h> #define N 8 #define THREAD_PER_BLOCK 2 __global__ void transpose(int * in, int * out, int size) { int index = threadIdx.x + blockIdx.x * blockDim.x; out[index] = in[(index / size) + size * (index % size)]; } int main() { int * in, * out; int * d_in, * d_out; i...
6,019
#include <iostream> using namespace std; __device__ double counter = 0.5; __device__ double myAtomicAdd(double * address, double val) { unsigned long long int * address_as_ull = (unsigned long long int*)address; unsigned long long int old = *address_as_ull, assumed; do { assumed = old; old = atom...
6,020
////#include<math.h> ////#include<cuda.h> ////#include<helper_math.h> //#include<device_launch_parameters.h> //#include<cutil_math.h> //#include<cutil_inline.h> //#include<cutil_gl_inline.h> //#include<cuda_gl_interop.h> //////////////////////////////////for __syncthreads() //#ifndef __CUDACC__ // #define __CUDACC__ //...
6,021
/**************************************** ADD Description TODO *****************************************/ #include <cuda.h> __global__ void setVal(double * B, size_t size, double val) { int tid = threadIdx.x + blockDim.x * blockIdx.x; int stride = blockDim.x * gridDim.x; for(; tid < size; tid += stride) ...
6,022
__global__ void kernel(float *a) { int i = gridDim.x; a[i] = i; }
6,023
#include "includes.h" __global__ void gpu_copy_velocity( const int num_atoms, const double* g_vx_i, const double* g_vy_i, const double* g_vz_i, float* g_vx_o, float* g_vy_o, float* g_vz_o) { const int n = threadIdx.x + blockIdx.x * blockDim.x; if (n < num_atoms) { g_vx_o[n] = g_vx_i[n]; g_vy_o[n] = g_vy_i[n]; g_vz_o[n]...
6,024
/* Code adapted from book "CUDA by Example: An Introduction to General-Purpose GPU Programming" This code computes a visualization of the Julia set. Two-dimenansional "bitman" data which can be plotted is computed by the function kernel. The data can be viewed with gnuplot. The Julia set iteration is: z= z**2 +...
6,025
#include <stdio.h> #include <math.h> #define BLOCK_DIM_X 32 #define BLOCK_DIM_Y 16 #define VECTOR_DIM 300 #define PARTITION_DIM 32 __global__ void vectorAdd(float *A, const float *B,unsigned int numElements) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < numElements) { A[i] = B[i] - ...
6,026
#include "time.cuh" double gettime(){ double tseconds=0.0; struct timeval mytime; gettimeofday(&mytime,(struct timezone*)0); tseconds=(double)(mytime.tv_sec+mytime.tv_usec*1.0e-6); return tseconds; }
6,027
/* * Vector addition example using CUDA. * This is a non-optimised example that is likely to benefit * from * - adaptig the main kernel launch configuration, so that * it creates a grid containing a number of blocks that is * a multiple of the number of SMs on the device. */ #include <stdio.h> /...
6,028
#include<iostream> #include<cuda.h> using namespace std; #define N 40*1024 __global__ void add(int *a,int *b,int *c){ int tid=threadIdx.x+blockIdx.x*blockDim.x; while(tid<N){ c[tid]=a[tid]+b[tid]; tid+=blockDim.x*gridDim.x; } } int main(){ int a[N],b[N],c[N]; int *dev_a,*dev_b,*dev_c...
6,029
#include <stdio.h> // code from mixbench #define CUDA_SAFE_CALL( call) { \ cudaError err = call; \ if( cudaSuccess != err) { \ fprintf(stderr, "Cuda error in file '%s' in line %i...
6,030
/* 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,int var_3,float var_4,float var_5,float var_6,float var_7,float var_8,float var_9,float var_10,float var_11,float var_12,float var_13,float ...
6,031
/* nvcc flagg_low.cu -o flagg_low ./flagg_low -h */ #include <iostream> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #define NCHANS 8 // # of channels -- assume no more than 2048 channels for now, see blinest call in main{} #define NANTS 2048 // # of antennas #define...
6,032
#include <cstdio> __global__ void mykernel(void) { } int main() { mykernel<<<1,1>>>(); printf("Hello CPU\n"); return 0; }
6,033
/* #include "engine.h" struct Point point_init(struct Point pt, double x, double y, double z){ pt.x = (double *)malloc(sizeof(double)); pt.y = (double *)malloc(sizeof(double)); pt.z = (double *)malloc(sizeof(double)); pt->x = x; pt->y = y; pt->z = z; pt->cons = 1; return pt; } */
6,034
#include <stdio.h> #include <cuda.h> #define N 4096 #define G 4 #define B 1024 __global__ void vectorAddKernel(int * a, int * b, int * c){ int index = blockIdx.x*blockDim.x + threadIdx.x; c[index] = a[index] + b[index]; } int main(){ dim3 grid(G, 1, 1); //e.g. dim3 grid(4,1,1) dim3 block(B, 1, 1); //e.g. ...
6,035
#include "includes.h" __global__ void kSelectRows(float* source, float* target, float* indices, int nRowIs, int nCols, int nSourceRows){ __shared__ int sourceRowIndices[32]; const int startTargetRowI = blockIdx.x * 32; const int tid = threadIdx.x; const int localNRowIs = min(32, nRowIs-startTargetRowI); // cooperative...
6,036
#include <stdio.h> #include <cuda.h> #define THREADS_PER_BLOCK 1024 void matrixAdd(int *a, int *b, int *c, int N) { int index; for (int col = 0; col < N; col++) { for (int row = 0; row < N; row++) { c[index] = a[index] + b[index]; } } } __global__ void matrixAddKernel(int *a, int *b, int *c, int N...
6,037
/* Matrix normalization using CUDA * Compile with "nvcc matrixNorm.cu" */ /* ****** ADD YOUR CODE AT THE END OF THIS FILE. ****** * You need not submit the provided code. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #include <sys/types.h> #include <sys/times.h> #include <sys/time.h>...
6,038
// // Created by Cheevarit Rodnuson on 11/21/17. // #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <string.h> #include <iostream> #include <stdlib.h> #include <stdio.h> long* createVector (long size, long inivalue) { long* vector = (long*) malloc(sizeof(long)*size); for (long i = ...
6,039
#include <stdio.h> #include <cuda.h> #include <stdlib.h> #include <math.h> //#include <ctime> #include <time.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #define true 1 #define false 0 //#define M_PI 3.141592653589793 //#define INFINITY 1e8 #define MAX_RA...
6,040
__global__ void find_primes(int *a, int n) { int idx = threadIdx.x + blockIdx.x * blockDim.x; // int total_threads = gridDim.x * blockDim.x; int is_prime = 1; if (idx > 1 && idx < n){ int j; for (j=2; j<idx/2+1; ++j){ if (!(idx % j) && j != idx){ is_prime =...
6,041
/* declare a 1d array and find the maximum of each chunk using reduce method. No shared memory is used * *chunksize must be an exponential of 2 how to compile: nvcc para when n is 600,000 or more, the results are not correct probably because there is not enough threads. The 1d array used for testing is a sequence ...
6,042
// // include files // #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cuda_runtime.h> #include <time.h> /* when block=1, threads have to be the * the maximum based on current kernel * implementations */ #define N 512 #define THREADS_PER_BLOCK 512 // // kernel routine // /...
6,043
#include <stdio.h> #include <cassert> #define ALLOC_SIZE 128 __global__ void test_malloc(int **controller) { __shared__ int *ptr; int bx = blockIdx.x; if (threadIdx.x == 0) { ptr = (int*)malloc(ALLOC_SIZE * sizeof(int)); controller[bx] = ptr; printf("allocate GPU memory at %d\n", ptr); } __syncthr...
6,044
#include "includes.h" __global__ void MatrixMulKernel(float *d_x, float *d_y, float *d_z, int Width) { int idx = threadIdx.x; int idy = threadIdx.y; float kernelSum = 0; if ((idx < Width) && (idy < Width)) { for (int k = 0; k < Width; ++k) { kernelSum += d_x[idy * Width + k] * d_y[k * Width + idx]; } d_z[idy * Width ...
6,045
/* * main.cu * * Created on: Nov 14, 2019 * Author: cuda-s01 */ #include <stdio.h> const int TILE_WIDTH = 2; __global__ void matrixMultiplicationKernel(float* M, float* N, float* P, int Width) { // Calculate the row index of the P element and M int Row = blockIdx.y*blockDim.y+threadIdx.y; // Calculate ...
6,046
/********************************************************************** * DESCRIPTION: * Serial Concurrent Wave Equation - C Version * This program implements the concurrent wave equation *********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math...
6,047
#include <stdio.h> #include "curand.h" #include "curand_kernel.h" #include "math.h" #include <thrust/device_vector.h> __global__ void calc_pi(int *dev, long num_trials, double r) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx >= num_trials) return; double x, y, test; int Ncirc = 0; curandS...
6,048
/* * Copyright 1993-2006 NVIDIA Corporation. All rights reserved. * * NOTICE TO USER: * * This source code is subject to NVIDIA ownership rights under U.S. and * international Copyright laws. * * This software and the information contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being...
6,049
#include <stdio.h> __device__ static int *arrptr; __device__ static int x; extern "C" { __device__ void sub1_() { arrptr = (int *) malloc (10); x = 11; printf ("sub1: arrptr=%p\n", arrptr); printf ("sub1: x=%d\n", x); } __device__ void sub2_() { printf ("sub2: arrptr=%p\n", arrptr); printf ("sub2: x=%d\...
6,050
#include <stdint.h> #include <cuda.h> __global__ void add(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t n) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if (i < n && j < n) { int idx = i * n + j; c[idx] = a[idx] + b[idx]; } }
6,051
// This example introduces __device__ functions, which are special functions // which may be called from code executing on the device. #include <stdlib.h> #include <stdio.h> // __device__ functions may only be called from __global__ functions or other // __device__ functions. Unlike __global__ functions, __device__...
6,052
#include <iostream> #include <cstdlib> #include <cstdio> #include <curand_kernel.h> #include <thrust/reduce.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> #include <thrust/extrema.h> #include <thrust/device_ptr.h> using namespace std; __device__ int sum = 1; __global__ void degreeCalc (int...
6,053
#include "update.hh" #include <cassert> #include <stdexcept> #include "graph.hh" #include "mse-grad.hh" #include "ops-builder.hh" #include "variable.hh" #include "../runtime/node.hh" #include "../memory/alloc.hh" namespace ops { Update::Update(Variable* var, Op* dt, Op* coeff) : Op("update", var->shape_ge...
6,054
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> using namespace std; #define BLOCK_SIZE 16 #define BASE_TYPE double __global__ void matrixMult(const BASE_TYPE *A, BASE_TYPE *C, int Acols, int Arows) { int i0 = Acols *(blockDim.y*blockIdx.y + threadIdx.y); //int ...
6,055
#ifndef _EXP_KERNEL_ #define _EXP_KERNEL_ #include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <math.h> /* * The actual kernel */ template <class T> __global__ void expKernel(T * in, T * out, int n) { int index = threadIdx.x + blockIdx.x * blockDim.x; if(index < n) out[index] = ex...
6,056
#include "includes.h" __global__ void FloatDiv(float *A, float *B, float *C) { unsigned int i = blockIdx.x * gridDim.y * gridDim.z * blockDim.x + blockIdx.y * gridDim.z * blockDim.x + blockIdx.z * blockDim.x + threadIdx.x; if (B[i] != 0) { C[i] = A[i] / B[i]; } else { C[i] = 0; } }
6,057
#include <stdio.h> #include <cuda.h> #include <sys/time.h> __global__ void matTran(int result_row_size, int result_col_size, float* result, int input_row_size, int input_col_size, float* matrix){ // each row is a block // size of row (vert length) is block dim int current_row = blockIdx.x; int current_col = thr...
6,058
#include <stdio.h> #include <cuda_runtime.h> // #include <helper_cuda.h> #define N 1000 #define THREADS_PER_BLOCK 10 __global__ void histogram(char *buffer, int *frequencies){ int i = blockIdx.x * blockDim.x + threadIdx.x; if(i < N) frequencies[(int) buffer[i]]++; } int main(void){ cudaError_t err = cudaSuccess...
6,059
#include <stdio.h> #include <time.h> #define PerThread 1024*16//每个线程计算多少个i #define N 64*256*1024*16//积分计算PI总共划分为这么多项相加 #define BlockNum 64 //block的数量 #define ThreadNum 256 //每个block中threads的数量 __global__ void Gpu_calPI(double* Gpu_list) { __shared__ double cache[ThreadNum];//每个block共享一个shared memory. int cach...
6,060
#include "includes.h" __global__ void gpu_calculation(float c0r, float c0i, float float_step, float imag_step, int *results, unsigned n, int W, int H, int inicial){ // index = m*x + y const long unsigned globalIndex = blockDim.x*blockIdx.x + threadIdx.x; // printf("%d %d\n", blockIdx.x, threadIdx.x); if (globalInde...
6,061
#include <iostream> #include <fstream> #include <string.h> #include <sys/time.h> #include <math.h> #include <random> #include <cuda_runtime.h> #include <device_launch_parameters.h> using namespace std; #define BLOCKSIZE 1024 #define FLOAT_MIN 10 #define FLOAT_MAX 100 #define GPU_ERR_CHK(ans) \ ...
6,062
#include <stdio.h> #include <stdlib.h> #define HOST_TO_DEVICE 0 #define DEVICE_TO_HOST 1 // Print the usage of the program inline void usage(char *program) { fprintf(stderr, "usage: %s memsize iters [-r]\n", program); fprintf(stderr, " memsize : memory transferred in bytes (>0)\n"); fp...
6,063
#include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #include <math.h> #include "device_launch_parameters.h" #include "openglcuda.cuh" #include <time.h> int numElementsRand = 10, numElementsMat = 100, numElementsBestCost = 100; int sizeRand = numElementsMat * sizeof(int); int sizeMat = numElementsMat * si...
6,064
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> // CUDA runtime #include <cuda_runtime.h> /* Problem size */ #define NI 4096 #define NJ 4096 __global__ void Convolution(double* A, double* B) { int i, j; double c11, c12, c13, c21, c22, c23, c31, c32, c33; c11 = +0.2; c21 = +0.5; ...
6,065
#include <cstdio> #include <cstdlib> #include <cstring> #include <cuda_runtime.h> #include <iomanip> #include <iostream> #include <vector> inline void check(cudaError_t err, const char* context) { if (err != cudaSuccess) { std::cerr << "CUDA error: " << context << ": " << cudaGetErrorString(err...
6,066
#include <stdio.h> __global__ void loop() { int i = threadIdx.x + blockIdx.x * blockDim.x; printf("This is iteration number %d\n", i); } int main() { loop<<<2, 5>>>(); cudaDeviceSynchronize(); }
6,067
#include <stdlib.h> #include <stdio.h> #define CSC(call) \ do { \ cudaError_t res = call; \ if (res != cudaSuccess) { \ ...
6,068
#include <cstdio> __global__ void iwarp(int* out) { volatile int* vout = out; *vout = threadIdx.x; } int main() { int* din; cudaMalloc((void**)&din, sizeof(int)); int in = 0; cudaMemcpy(din, &in, sizeof(int), cudaMemcpyHostToDevice); iwarp<<<1,16>>>(din); int output; cudaMemcpy(&output, din, sizeof(...
6,069
#include "includes.h" __global__ void sgemvn_kernel2_fermi(int n, int m, int n1, float alpha, float* A, int lda, float *x, float *y) { int ind = blockIdx.x*num_threads + threadIdx.x; A += ind; x += threadIdx.x; float res = 0.f; __shared__ float buff[num_threads]; for(int i=0; i<n1; i += num_threads ){ __syncthreads...
6,070
/* Taken from gputools with the purpos of showing how we can . */ #define NUM_THREADS 32 /* vg_a and vg_b are two matrices. n_a, n_b are the number of rows/observations in the respective matrices. pitch_a, pitch_b are the number of bytes (not elements) between observations in a row, i.e. the stride k - n...
6,071
#include "includes.h" __global__ void Make1DprofileKernel (double *gridfield, double *axifield, int nsec, int nrad) { int i = threadIdx.x + blockDim.x*blockIdx.x; int j; if (i < nrad){ double sum = 0.0; for (j = 0; j < nsec; j++) sum += gridfield[i*nsec + j]; axifield[i] = sum/(double)nsec; } }
6,072
#include "includes.h" __global__ void helloWorld(){ }
6,073
/* objective * C = A*B // A[m][k], B[k][n], C[m][n] * compile: nvcc --gpu-architecture=compute_60 --gpu-code=sm_60 -O3 matmul_double.cu -o matmul_double Using nvprof for this lab nvprof -- query-metrics nvprof dram_read_transactions ./test 1024 1024 128 nvprof ./test 1024 102...
6,074
#include "includes.h" __global__ void matrixMulKernel(float *C, float *A, float *B, int width, int height){ int tx = blockIdx.x * blockDim.x + threadIdx.x; int ty = blockIdx.y * blockDim.y + threadIdx.y; if(tx >= width || ty >= height) return; float sum = 0; for(int i=0; i<width; ++i){ sum += A[ty * width + i] * B[i *...
6,075
#include <stdio.h> // #include <cutil.h> #define MAX 1000000 #define MAX_ITERATIONS 1000 #define CUDA_SAFE_CALL(x) x __global__ void kernel(int* a) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int i = 0; unsigned int answer = idx; if (idx != 0 && idx <= MAX) { while (answer != 1 && i < MAX_ITERAT...
6,076
#define SQRT_TWO_PI 2.506628274631000 extern "C" __global__ void calc_loglik(double* vals, int N, double mu, double sigma) { // note that this assumes no third dimension to the grid // id of the block int myblock = blockIdx.x + blockIdx.y * gridDim.x; // size of each block (within grid of blocks) in...
6,077
/* * @author Connie Shi * Lab 3: Write a reduction program in CUDA that finds the maximum * of an array of M integers. * Part 1: Write a CUDA version that does not take thread divergence * into account. Uses interleaved addressing. * * Should be run on cuda1 machine with 1024 max threads per b...
6,078
#define t_max 1 #define t 1 /* (T[0][0][0][1][0]=((((T[0][0][0][0][0]*((c[0][0][0][0][1]*T[0][0][0][0][0])+c[0][0][0][0][2]))+c[0][0][0][0][3])+((c[0][0][0][0][4]*T[-1][0][0][0][0])+(c[0][0][0][0][5]*T[1][0][0][0][0])))+(((c[0][0][0][0][6]*T[0][-1][0][0][0])+(c[0][0][0][0][7]*T[0][1][0][0][0]))+((c[0][0][0][0][8]*T[0]...
6,079
//#include <math.h> //#include <stdio.h> //#include <time.h> //#include <vector_functions.h> //#include "stereo_cuda_shared.h" // // //#define USE_NCC 1 //#define USE_SQRT_APPROX 1 // //#define BLOCK_SIZE 32 //#define NCC_HEIGHT 3 //#define NCC_WIDTH 7 //#define HF_NCC_HEIGHT (NCC_HEIGHT / 2) //#define HF_NCC_WIDTH (NC...
6,080
#include "includes.h" __device__ int GPUKernel_Position(int i,int j) { if (i<j){ return j*(j+1)/2+i; } return i*(i+1)/2+j; } __global__ void GPUKernel_VpVm_v2(int a, int b,int v,double * in,double * outp,double * outm) { int blockid = blockIdx.x*gridDim.y + blockIdx.y; int id = blockid*blockDim.x + threadIdx.x; ...
6,081
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <iostream> int main(void) { // H has storage for 4 integers thrust::host_vector<int> H(4); // initialize individual elements H[0] = 14; H[1] = 20; H[2] = 38; H[3] = 46; // H.size() returns the size of vector H std::cout << "H has si...
6,082
/** * * bash版キャリーチェーンのC言語版のGPU/CUDA移植版 * 詳しい説明はこちらをどうぞ https://suzukiiichiro.github.io/search/?keyword=Nクイーン問題 * アーキテクチャの指定(なくても問題なし、あれば高速) -arch=sm_13 or -arch=sm_61 CPUの再帰での実行 $ nvcc -O3 -arch=sm_61 05CUDA_CarryChain.cu && ./a.out -r CPUの非再帰での実行 $ nvcc -O3 -arch=sm_61 05CUDA_CarryChain.cu && ./a.out -c GPUのシ...
6,083
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <sys/time.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #define checkCudaError(o, l) _checkCudaError(o, l, __func__) #define SHARED_MEMORY_BANKS 32 #define LOG_MEM_BANKS 5 #define CONFLICT_FREE_OFFSET(n) ((n) >> LOG_MEM_BANKS) #inclu...
6,084
#ifndef __U_TENSOR_OPERATION_GPU_HPP__ #define __U_TENSOR_OPERATION_GPU_HPP__ /*** u-op-gpu.hpp base functions for tensor Copyright (C) 2017 Renweu Gao 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 Foundati...
6,085
/*------------check.cu------------------------------------------------------// * * Purpose: This is a simple cuda file for checking your gpu works * * It prints 0 -> 63 * *-----------------------------------------------------------------------------*/ #include <iostream> #include <math.h> __global__ void fin...
6,086
#include "includes.h" __global__ void _calculate_wnp( const long* edge_num, const long* edge_start_idx, float* weight, long* ind, const int b, const int n, const int orig_p_num, const int p_num ) { int index = threadIdx.x + blockIdx.x * blockDim.x; if (index >= b * n * orig_p_num) return; const int c_b = index / (n * ...
6,087
#include "includes.h" __global__ void ForwardReLU(float* Z, int nRowsZ, int nColsZ, float* A) { int index = blockIdx.x * blockDim.x + threadIdx.x; if (index < nRowsZ * nColsZ) { if (Z[index] >= 0) A[index] = Z[index]; else A[index] = 0; } }
6,088
#include <iostream> #include <vector> __global__ void vecadd( int * v0, int * v1, std::size_t size ) { auto tid = threadIdx.x; v0[ tid ] += v1[ tid ]; } int main() { cudaError_t err; std::size_t const size = 100; std::size_t const sizeb = size * sizeof( int ); int * v0_h = nullptr; int * v1_h = ...
6,089
// REQUIRES: nvptx-registered-target // RUN: %clang_cc1 -triple nvptx -fcuda-is-device \ // RUN: -fgpu-allow-device-init \ // RUN: %s 2>&1 | FileCheck %s // CHECK: warning: '-fgpu-allow-device-init' is ignored since it is only supported for HIP
6,090
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #define error 1e-6 #define BLOCK_SIZE 32 ///////////////////////////////////////// UTILITIES //////////////////////////////////////////////////////////////////////////////////////////// /* **************************************************...
6,091
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> __global__ void add(int *X, int *Y, int *alpha){ int idx = blockIdx.x; Y[idx] = ((*alpha)*(X[idx])) + Y[idx]; } int main(){ int alpha,*X,*Y, N; //program vars int *d_x, *d_y, *d_a; //device vars int size = siz...
6,092
#define t_max 1 #define t 1 /* (u[0][0][0][1][0]=((((u[1][0][0][0][0]+(u[-1][0][0][0][0]+u[0][1][0][0][0]))+(u[0][-1][0][0][0]+(u[0][0][1][0][0]+u[0][0][-1][0][0])))*0.25)-u[0][0][0][0][0])) */ __global__ void laplacian(float * * u_0_1_out, float * u_0_0, float * u_0_1, int x_max, int y_max, int z_max, int tbx, in...
6,093
#include <iostream> #include <vector> #include <chrono> #include <thread> class memory_keeper { private: std::vector<void*> _memory; const size_t _block_size = 128 * 1024 * 1024; //128MB. size_t _blocks; void allocate_block() { void *block; cudaMalloc(&block, _block_size);...
6,094
#include "includes.h" __global__ void matrixMultKernel (float *d_A, float *d_B, float *d_C, int N) { // Calculate the row index of the d_C element and d_A int row = blockIdx.y * blockDim.y + threadIdx.y; // Calculate the column index of d_C and d_B int col = blockIdx.x * blockDim.x + threadIdx.x; if ((row < N) && (co...
6,095
/***************************************************************************//** * \file intermediatePressure.cu * \author Christopher Minar (minarc@oregonstate.edu) * \brief kernels to generate the right hand side of the poission equation */ #include "intermediatePressure.h" /** * \namespace kernels * \brief C...
6,096
#include <iostream> #include <cstdlib> #include <cfloat> #include <math.h> #include <sys/time.h> #define THREADS_PER_BLOCK 32 __global__ void voronoi_d (int *imageArray, int *points, int imageSize, int numPoints) { // use x to access each cell and compare it to each point and assign the cell's value to match the ...
6,097
#include <cuda_runtime.h> #include <stdio.h> #include <time.h> #include <stdlib.h> #include <sys/time.h> #define DIMBLOCK_X 65535 //2^16 #define DIMBLOCK_Y 32 //2^5 #define DIMTHREAD_X 1024 //2^10 //Total 2^31 __device__ char found(0); __global__ void searchFactor(unsigned long int * number, unsigned int * factor)...
6,098
#include <stdio.h> __global__ void add(int* a, int* b, int* c, int n) { int id = threadIdx.x; if(id < n ) c[id] = a[id] + b[id]; } int main(void) { int n = 1000; int* a; int* b; int* c; size_t nbytes = n * sizeof(int); cudaMallocManaged (&a, nbytes); ...
6,099
#include "includes.h" __global__ void addVector(int *d1_in, int *d2_in, int *d_out, int n){ int ind = blockDim.x*blockIdx.x + threadIdx.x; if(ind<n){ d_out[ind] = d1_in[ind]+d2_in[ind]; } }
6,100
// compile command: // https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#gpu-feature-list // nvcc binary_arithmetics.cu --ptx -o binary_arithmetics.ptx --gpu-architecture=compute_70 --gpu-code=sm_70,compute_70 #define ADD + #define SUB - #define MUL * #define DIV / #define MOD % #define BINARY_EXPRESS...