serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
21,701
#include <cstdio> #define cudaCheckError() { \ cudaError_t e=cudaGetLastError(); \ if(e!=cudaSuccess) { \ ...
21,702
#include "includes.h" __global__ void implantCoeffs(float* matrices, float *coeffArray, int savedCoeffs, int dimsize){ int id = blockIdx.x * blockDim.x * blockDim.y * blockDim.z + threadIdx.z * blockDim.y * blockDim.x + threadIdx.y * blockDim.x + threadIdx.x; int offsetMatrix = id * dimsize * dimsize, offsetCoeff = i...
21,703
#include <stdio.h> #include <math.h> #include <stdlib.h> #define N (2048*2048) #define THREAD_PER_BLOCK 512 __global__ void reverse(int* a, int* b){ int index_in = threadIdx.x + blockIdx.x * blockDim.x; int index_out = gridDim.x * blockDim.x - index_in - 1; b[index_out] = a[index_in]; } void random_ints(in...
21,704
extern "C" __global__ void uppercase(char* b, char* a) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (a[i] >= 'a' && a[i] <= 'z') b[i] = a[i] + 'A' - 'a'; else b[i] = a[i]; }
21,705
/* mini EP 11 NOME: Your name here NUSP: Your NUSP here */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> long getMS() { struct timespec s; clock_gettime(CLOCK_REALTIME, &s); return s.tv_sec*1000 + s.tv_nsec/1000000; } // number of tests #define NTESTS 10 #define SEED 123456 ...
21,706
#include "includes.h" __global__ void imageSplitKernel(float3 *ptr, float *dst, int width, int height) { int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; if (x >= width || y >= height) { return; } float3 color = ptr[y * width + x]; dst[y * width + x] = color.x; dst[y * wi...
21,707
#include "includes.h" __global__ void rectified_linear_kernel( float4 * __restrict output, const float4 * __restrict input, float negative_slope, int elem_count) { int elem_id = blockDim.x * blockIdx.x + threadIdx.x; if (elem_id < elem_count) { float4 val = input[elem_id]; if (val.x < 0.0F) val.x *= negative_slope; if ...
21,708
#include "includes.h" __global__ void modify_i_j( int width, int height, int pitch, float *d_array, int i, int j, float change_to ){ //we want to change the [i,j]-th of the 2-dim array int idx = blockIdx.x; //row int idy = threadIdx.x; //column //we can do index by pointer: //if ((idx == i) && (idy == j)){ //float* ro...
21,709
#include <cstdio> #define getPos(a,k) (((a)>>(k-1))&1) extern "C" { __global__ void prefixSum(int * input_T, int * prefix_T, int * prefix_helper_T, int n, int k, int blockPower) { __shared__ int tmp_T[1024]; for(int i = 0; i<blockPower; i++) { if(threadIdx.x + 1024*blockIdx.x + i*1024*gridDim.x >= n...
21,710
#include "includes.h" __global__ void IncrementConnectionAgeKernel( int cell, int *connection, int *age, int maxCells ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blockDim.x*blockIdx.x //blocks preceeding current block + threadIdx.x; if(threadId < maxCells) { if(conne...
21,711
#ifndef _UTIL_CU #define _UTIL_CU template<int N> __device__ void zero(unsigned int *x) { #pragma unroll for(int i = 0; i < N; i++) { x[i] = 0; } } template<int N> __device__ void copy(const unsigned int *a, unsigned int *b) { #pragma unroll for(int i = 0; i < N; i++) { b[i] = a[i]...
21,712
/* CSCI 563 Programming Assignment 2 Part 2 Clayton Kramp */ #include <iostream> #include <fstream> using namespace std; // Device function to transpose matrix __global__ void transpose(int* A, int* B, int row, int col) { int j = blockIdx.x * blockDim.x + threadIdx.x; int i = blockIdx.y * blockDim.y + thr...
21,713
/* * Matrix multiplication based on modified NVIDIA samples code * Copyright (C) 2014 René Oertel (rene.oertel@cs.tu-chemnitz.de) * * 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, eit...
21,714
/* ********************************************** * CS314 Principles of Programming Languages * * Spring 2020 * ********************************************** */ #include <stdio.h> #include <stdlib.h> __global__ void collateSegments_gpu(int * src, int * scanResult, int * output, in...
21,715
#include <stdio.h> #include <vector> #include <string> #include <fstream> #include <cmath> #include <ctime> #include <stack> #include <sstream> #include <cstdlib> #include <iostream> #include <limits> #include <algorithm> #include <climits> #include <bitset> #include <set> #include <sys/time.h> #include <bits/stdc++.h>...
21,716
#include <stdlib.h> #include <time.h> #include <sys/time.h> #include <iostream> typedef unsigned char CELL_DT; #define CUDA_BLOCK_SIZE 32 using namespace std; #define cudaErrchk(ans) cudaAssert((ans), __FILE__, __LINE__) inline void cudaAssert(cudaError_t code, string file, int line){ if (code != cudaSucce...
21,717
// Babak Poursartip // 01/28/2021 // CUDA //topic: #include "cstdio" #include <algorithm> #include <functional> // ================================= __global__ void addCuda( int *a, int *b, int *c) { int i = threadIdx.x; c[i] = a[i] + b[i]; } // ================================= void addIndex( int *a, in...
21,718
#include "includes.h" __global__ void solve(float* mat, float* b, float* x, int rows, int cols) { int n = blockIdx.x*threads1D + threadIdx.x; if (n < rows) //Ensure bounds x[n] = b[n] / mat[n * cols + n]; }
21,719
#include "matrix.cuh" #include <cstring> // memset #define BLOCK_SIZE 1024 #define DIVIDE(A,B) (((A)+(B)-1)/(B)) #define BLOCKS(N) DIVIDE(N,BLOCK_SIZE) #define TILE_DIM 32 // total shared memory usage 32*32 * 2(matrices) * 4(sizeof(float)) = 8kB ///////////////////////////////////////////////////////////////////////...
21,720
#include <cstdlib> #include <iostream> #include <stdlib.h> #include <fstream> #define BIN_COUNT 10 #define N_THREADS 512 #define N_TOTAL 1024 #define RANGE 100 using namespace std; // GPU kernel for computing a histogram __global__ void kernel(int *input, int *bins, int N, int N_bins, int DIV){ // Calculate glob...
21,721
#include "includes.h" using namespace std; struct pixel //to store RGB values { unsigned char r; unsigned char g; unsigned char b; }; __device__ pixel padding(pixel* Pixel_val, int x_coord, int y_coord, int img_width, int img_height) { pixel Px; Px.r=0; Px.g=0; Px.b=0; if(x_coord< img_width && y_coord <img_height &...
21,722
#include "includes.h" __global__ void resized(unsigned char *imgData, int width, float scale_factor, cudaTextureObject_t texObj) { const unsigned int tidX = blockIdx.x * blockDim.x + threadIdx.x; const unsigned int tidY = blockIdx.y * blockDim.y + threadIdx.y; const unsigned idx = tidY * width + tidX; //Read textur...
21,723
// parallel HelloWorld using GPUs // Simple starting example for CUDA program : this only works on arch 2 or higher // Cong Xiao and Senlei Wang, Modified on Sep 2018 #include <stdio.h> #include <stdlib.h> #include <cuda.h> #define N_THRDS 4 // Nr of threads in a block (blockDim) #define N_BLKS 4 // Nr of block...
21,724
#include <stdlib.h> #include <stdio.h> #include <cuda_runtime.h> #include <time.h> //#define __DEBUG #define element_addr(a, m, n, d) (a + ((m) * (d) + n)) #define element(a, m, n, d) (((m >= 0)&&(m < d)&&(n >= 0)&&(n < d))? (a[(m) * (d) + n]) : 0) #define CUDA_CALL(cmd) do { \ if((err = cmd) != cudaSuccess) { \ ...
21,725
#include <stdio.h> #include <cuda_runtime.h> __global__ void kernel() { printf("%d, %d\n", threadIdx.x, blockIdx.x); return; } int main() { // main iteration kernel <<<16, 4, 0>>>(); return 0; } /** * Dans cette démo on appelle 4 threads par block et on appelle 16 blocks. */
21,726
#define t_max 1 #define t 1 /* (u[0][0][0][1][0]=(a*((((u[-3][0][0][0][0]+(u[0][-3][0][0][0]+u[0][0][-3][0][0]))*-2.0)+(((u[-2][0][0][0][0]+(u[0][-2][0][0][0]+u[0][0][-2][0][0]))*15.0)+((u[-1][0][0][0][0]+(u[0][-1][0][0][0]+u[0][0][-1][0][0]))*-60.0)))+((u[0][0][0][0][0]*20.0)+(((u[1][0][0][0][0]+(u[0][1][0][0][0]+u[0...
21,727
#include <iostream> const int image_size = 4096; const int filter_size = 3; __global__ void conv2d(int* A, int* B, int* C, int N, int n) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; const int offset = n / 2; int row_i = threadIdx.y - offset; int col_...
21,728
#include "includes.h" __global__ void cube(double* d_out, double* d_in) { int idx = threadIdx.x; double f = d_in[idx]; d_out[idx] = f*f*f; }
21,729
#include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <cstdlib> #include <iostream> __global__ void DivergencyKernel(float* a, int N) { int x = blockDim.x * blockIdx.x + threadIdx.x; if (!(threadIdx.x % 2)) a[x] = a[x] * (threadIdx.x + 1); else a[x] = a[x] * (threadI...
21,730
/* This is a somewhat naive matrix-multiplication implementation. The most * glaring shortcoming is the lack of shared-memory usage. * * Compile with `nvcc matrix_multiplication.cu`. * * Author: Christopher Mitchell <chrism@lclark.edu> * Date: 2011-07-15 */ #include <stdio.h> #include <stdlib.h> typedef struc...
21,731
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #include <cuda_profiler_api.h> #define ITER 100000 #define THREAD_PER_BLOCK 10 #define PI 3.1415926535 #define RAD(X) X *(PI / 180.0) void calculator(float *sin_arr, float *cos_arr, float *tan_arr)...
21,732
#include <time.h> #include <sys/time.h> #include <stdio.h> #include <stdlib.h> #include <math.h> void loadData( char* fileName , int n , float* x , float* y , float* mass , int* actual ) ; float getVal( char* str , int start , int subLen ) ; __global__ void iter( int n , float* xVel , float* yVel , float* x , floa...
21,733
#include <stdio.h> #define NUM_BLOCKS 1 #define BLOCKS_WIDTH 256 __global__ void hello() { printf("Hello world! I am thread %d\n", threadIdx.x); } int main(int argc, char** argv) { // launch the kernel hello<<<NUM_BLOCKS, BLOCKS_WIDTH>>>(); // force the printf()s to flush cudaDeviceSynchronize(); printf("T...
21,734
#include <stdio.h> #include <assert.h> #include <cuda.h> #include <sys/time.h> #define N 10240000 #define ThreadPerBlock 128 #define NSTREAM 4 __global__ void multiply(double * a, double *b , double * output, int length) { int tid = blockIdx.x * blockDim.x + threadIdx.x; if(tid < length) output[tid] = a[tid] + ...
21,735
#include "includes.h" // CUDA kernel. Each thread takes care of one element of c __global__ void encode(char *encodedText, char *decodedText) { // Get our global thread ID int id = blockIdx.x*blockDim.x+threadIdx.x; int startEncoded = id * 101; int startDecoded = id * 4; int t,finish=startEncoded+100; // Make sure we...
21,736
#include "includes.h" __global__ void initialize_clause_output_predict(int *clause_output, int *all_exclude) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x * gridDim.x; // Initialize clause output for (int j = index; j < CLAUSES; j += stride) { clause_output[j] = 1; all_exclude[j] = 1; } ...
21,737
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,int 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,float va...
21,738
#include "includes.h" const float REAL_VALUE_MAX = 1000000.0f; const int NUM_THREADS = 32; const int SIZE = 10000; const int DIMENSION = 2; __device__ float clamp(float v, float mn = -REAL_VALUE_MAX, float mx = REAL_VALUE_MAX) { return v < mn ? mn : v > mx ? mx : v; } __global__ void updateParticleKernel(float* P, fl...
21,739
#include "includes.h" __global__ void mapPrefixSumToPrisms( const unsigned numberOfPrisms, const unsigned raysPerSample, const unsigned reflectionSlices, const unsigned* raysPerPrism, const unsigned* prefixSum, unsigned *indicesOfPrisms, unsigned *numberOfReflections ){ int id = threadIdx.x + (blockIdx.x * blockDim.x)...
21,740
#include "includes.h" __global__ void simpleMPIKernel(float *input, float *output) { int tid = blockIdx.x * blockDim.x + threadIdx.x; output[tid] = sqrt(input[tid]); }
21,741
//SAXPY - Single-Precision A*X Plus Y #include <stdio.h> #define TPB 256 #define ARRAY_SIZE 10000 /* __device__ float ax(float x, float a){ return a*x; } */ __global__ void saxpyKernel(float *x, float *y, float a){ const int i = blockIdx.x*blockDim.x + threadIdx.x; y[i] += x[i]*a; } __host__ ...
21,742
#include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <stdbool.h> #include <time.h> #include <iostream> #include <cstring> #include <fstream> #include <sstream> using namespace std; #define NO_OF_CHARS 256 #define SHAREDMEMPERBLOCK 32768 #define NUMTHREADSPERBLOCK 1024 //int n_blocks...
21,743
#include "cuda.h" #include <stdio.h> #include <stdlib.h> #include <iostream> #include <sys/time.h> //code that does the main job on GPU __global__ void countNumOfPrimerKernel(int* n_array_d, bool* is_prime_d) { int col = blockIdx.x * blockDim.x + threadIdx.x; int row = blockIdx.y * blockDim.y + threadIdx.y; int i =...
21,744
#include "includes.h" const int Nthreads = 1024, maxFR = 100000, NrankMax = 3, nmaxiter = 500, NchanMax = 32; ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////...
21,745
#include "includes.h" __global__ void cube(float* d_out, float* d_in) { int idx = threadIdx.x; float f = d_in[idx]; d_out[idx] = f * f * f; }
21,746
#include <stdio.h> #include <stdlib.h> __global__ void blur_kernel(int *image_d,float *filter_d,int *blurimage_d,int N1,int N2) { int row = threadIdx.x + blockDim.x*blockIdx.x; int col = threadIdx.y + blockDim.y*blockIdx.y; if(row < N1 && col < N2) { int i,j; float sum = 0,wsum = 0; for(int i=0;i<3;i++) { ...
21,747
/****************************************************** * CUDA Sum Reduction * By: Sairam Krishnan * Date: May 6, 2014 * Compile command: nvcc -arch=sm_20 reduction.cu ******************************************************/ #include <cuda.h> #include <stdio.h> #define N 100 #define NTHRDS 8 #define NBLKS (((N) +...
21,748
// This is a generated file, do not edit it! #pragma once #include <stdint.h> typedef struct DataPoint DataPoint; typedef struct Node Node; typedef struct DecisionLearnerContext { DataPoint *DataPoints; int32_t NumDataPoints; float TotalWeight; int32_t NumAttributeAxes; int32_t NumCategoricalAxes; int32_t *DataPo...
21,749
/* Parallel Best Band Selection Algorithm */ /* Max Bands searched: 45 -> Taking Approximately a Day or so to complete Value returned: 0.094479 Band Returning Max: UNKNOWN author: Michael C Estwanick */ #include <thrust/extrema.h> #include <math.h> #include <stdio.h> #include <time.h> #include <sys/timeb.h> #de...
21,750
#include <stdio.h> #include <stdlib.h> #define N 16384 __global__ void addVecGrande(int *a, int *b, int *c) { int tid=threadIdx.x+blockIdx.x*blockDim.x; if(tid<N) { c[tid]=a[tid]+b[tid]; } } int main (void) { int *dev_a, *dev_b, *dev_c,*a,*b,*c; float elapsedTime; //asignar memoria en la GPU a=(int...
21,751
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> using namespace std; __global__ void depth(int *mat, int *stack, int *index, int start, int n, int *depth) { int id_x = threadIdx.x; int id_y = blockIdx.x; depth[start] = 0; index[start] = start; stack[start] = 1; while(index[id_x]<...
21,752
#include "includes.h" __global__ void counting_sort(int* array, int *temp, int size) { int i, j, count; i = threadIdx.x + (blockIdx.x * blockDim.x); if (i < size) { count = 0; for(j = 0; j < size; j++) { if(array[j] < array[i]) { count++; } else if(array[i] == array[j] && j < i) { count++; } } temp[count] = array[i]; }...
21,753
#include "iostream" __global__ void hello_fromGPU(int n) { int tid = blockIdx.x*blockDim.x + threadIdx.x; printf("Hello World from thread %d-%d\n", n, tid); } void hello_fromCPU() { printf("Hello World from CPU\n"); } int main() { hello_fromGPU<<<2,3>>>(0); hello_fromGPU<<<2,3>>>(1); cudaDevice...
21,754
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> __global__ void add_gpu(int nn, double *a, double *b, double *c) { int tid = blockIdx.x*blockDim.x + threadIdx.x; if (tid < nn) { c[tid] = a[tid] + b[tid]; } } extern "C" void add(int nx, int ny, void *ap, void *bp, void *cp)...
21,755
#include <iostream> #include <fstream> #include <vector> #include <cmath> #define HANDLE_ERROR(err) \ do { if (err != cudaSuccess) { printf("ERROR: %s\n", cudaGetErrorString(err)); exit(0);} } while (0) __constant__ double AVG[32][3]; __constant__ double COV[32][3][3]; __constant__ do...
21,756
#include <stdio.h> #include <cuda_runtime.h> #include <stdint.h> __global__ void kernel() { uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x; uint32_t n = tid; uint32_t sum = 0; uint32_t prod = 1; while(n != 0){ uint32_t digit = n % 10; n /= 10; sum += digit; prod *...
21,757
#include <stdio.h> #include <assert.h> const int DIM = 32; // print GB/s void postprocess(int n, float ms) { printf("%21f\t", n * sizeof(double)*1e-6 / ms ); //can be multiplied by 2 -> once for reading the matrix and the other //for writing. } //Read the ...
21,758
#include <iostream> __global__ void add(int *a, int *b, int *c, int n){ int index = threadIdx.x + blockIdx.x * blockDim.x; if(index < n) c[index] = a[index] + b[index]; } void random_ints(int * a, int N){ for(int i = 0; i < N; ++i){ a[i] = rand(); } } #define N (2048*2048) #define THREADS_PER_BLOCK 512 using...
21,759
#include <cstdio> #include <cstdlib> #include <cuda_runtime.h> #include <time.h> #define random(a, b) (rand() % (b - a) + a) void FillMatrix(float *matrix, int row, int col); void PrintMatrix(float *A, float *B, float *C, int m, int n, int k); __global__ void MatrixMulCUDA(const float *A, const float *B, float *C, int ...
21,760
#include "cuda.h" #include "cuda_runtime.h" #include "cuda_runtime_api.h" #include "device_functions.h" #include "device_launch_parameters.h" #include <chrono> #include <stdio.h>
21,761
// kernels from http://ppc.cs.aalto.fi/ch4 (2018) #include <algorithm> #include <chrono> #include <iomanip> #include <iostream> #include <iostream> #include <limits> #include <numeric> #include <random> #include <cstdio> #include <cuda_runtime.h> inline void check(cudaError_t err, const char* context) { if (err !...
21,762
#include <iostream> using namespace std; __global__ void SomaVetores(int* vetorA, int* vetorB, int* vetorC, int tamanho) { int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < tamanho) vetorC[i] = vetorA[i] + vetorB[i]; } int main() { int tamanho = 100000000; size_t totalBytes = tamanho * s...
21,763
extern "C" __global__ void add_particles(float* x, float* y, float* z, const float* xx, const float* yy, const float* zz, int size) { int i = blockDim.x * blockIdx.x + threadIdx.x; x[i + size] = xx[i]; y[i + size] = yy[i]; z[i + size] = zz[i]; }
21,764
#include<stdio.h> __device__ const char *STR = "Hello World!\n"; const char STR_LENGTH = 12; __global__ void hello(){ printf("%c\n", STR[threadIdx.x % STR_LENGTH]); } int main(void){ hello<<<1, STR_LENGTH>>>(); cudaDeviceSynchronize(); return 0; }
21,765
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <sys/time.h> #include <cuda.h> #include <curand_kernel.h> __global__ void generate_map(curandState* devState, int n_maps, int* grid, int width, int height); __global__ void setup_rnd_kernel (curandState* state, unsigned long seed); __...
21,766
// Copyright (C) 2018 NVIDIA CORPORATION. All rights reserved. // // 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 b...
21,767
#include "Map.cuh" float** generateMap(int width, int height) { float** map; cudaMallocManaged(&map, height*sizeof(float*)); for (int y = 0; y < height; y++) { cudaMallocManaged(&map[y], width * sizeof(float)); } return map; } void freeMap(float** map, int height) { for (int y = 0; y < height; y++) { cudaFr...
21,768
#include <stdlib.h> #include <string.h> #include <sys/time.h> #include <stdio.h> __global__ void sumMatrixOnGPU2D(float *MatA, float *MatB, float *MatC, int nx, int ny){ unsigned int ix = threadIdx.x + blockIdx.x * blockDim.x; unsigned int iy = threadIdx.y + blockIdx.y * blockDim.y; unsigned int idx = iy*n...
21,769
#include <stdio.h> #include <stdlib.h> #define N 512 void random_ints(int * a, int q) { for(int i = 0; i < q; i++) a[i] = rand() % 100; } __global__ void dot( int *a, int *b, int *c ) { __shared__ int temp[N]; temp[threadIdx.x] = a[threadIdx.x] * b[threadIdx.x]; __syncthreads(); if( 0 == threadIdx.x ) { in...
21,770
#include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void matrixMultGPU(int *a, int *b, int *c, int N){ int k, sum = 0; int col = threadIdx.x + blockDim.x * blockIdx.x; int fil = threadIdx.y + blockDim.y * blockIdx.y; if (col < N && fil < N) { for (k = 0; k < N; k++) { sum += a[fil * N + ...
21,771
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <cstdlib> #include <float.h> __global__ void maxpooling_kernel(float *output, float *input, int batch, int channel, int height, int width, int kernel_height, int kernel_width, int pad_height, int pad_width, int stride_height,...
21,772
#include <stdio.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" /*bool InitCUDA(){ int count; cudaGetDeviceCount(&count); if(count == 0){ fprintf(stderr, "There is no device.]n"); return false; } int i; for(i = 0; i < count; i++){ cudaDeviceProp prop; if(cudaGetDeviceProperties(&prop,i...
21,773
#include <stdio.h> #include <stdlib.h> #define IN_SIZE 32 #define TH_X_BLK 32 // It's not work efficient and results must be adjusted by adjusted __global__ void prefixSumNaive(int *in,int *out){ __shared__ int smem[TH_X_BLK]; int x=threadIdx.x+blockIdx.x*blockDim.x; if(x<IN_SIZE) smem[threadId...
21,774
#include "includes.h" __global__ void BaseNeuronSetFloatArray(float *arr, int n_elem, int step, float val) { int array_idx = threadIdx.x + blockIdx.x * blockDim.x; if (array_idx<n_elem) { arr[array_idx*step] = val; } }
21,775
#include <stdio.h> __device__ void MatrixMultiply(void *input) { float* inputIn = (float*)input; int matrixWidth = inputIn[0]; float *matrixA = inputIn+1; float *matrixB = matrixA + matrixWidth*matrixWidth; float *matrixOut = matrixA + 2*matrixWidth*matrixWidth; int warp_size=32; int threa...
21,776
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cstdio> #include <math.h> // this is a function the instructor came up with __global__ void sumSingleBlock(int* d) { int tid = threadIdx.x; // iterate over reduce steps // recall `>>=` does a left bitshift/assignment, so this is a cl...
21,777
#include <iostream> #include <cstdlib> #include <ctime> #define NUM_POINTS 33554432 // 1 GB of 32-bit floats float cpu_dataset[NUM_POINTS]; float cpu2_dataset[NUM_POINTS]; __global__ void hitAtomic(float* where) { atomicAdd(where, 1.0); } __global__ void hitAtomicBy32(float* where) { atomicAdd(&where[threadI...
21,778
/* Simulated Annealing algorithm for Traveling Salesman Problem @@ CUDA version: no parallel optimization, single thread Input: xxx.tsp file Output: optimal value (total distance) & solution route: permutation of {1, 2, ..., N} */ #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> ...
21,779
#include "includes.h" __global__ void findMax(int *m, int *cs, int n) { // your code goes here int colnum = blockDim.x * blockIdx.x + threadIdx.x; int max = m[0]; for (int k = 0; k < n; k++){ if(m [colnum+n*k] > max) max = m [colnum+n*k]; } cs[colnum] = max; }
21,780
//xfail:BOOGIE_ERROR //--blockDim=8 --gridDim=1 --no-inline // The statically given values for A are not preserved when we translate CUDA // since the host is free to change the contents of A. // cf. testsuite/OpenCL/globalarray/pass2 #include <stdio.h> #include <assert.h> #include <cuda.h> #define N 2//8 #define T...
21,781
#include "magma_dsyev_batch_functions.cuh"
21,782
#include <iostream> #include <fstream> #include <string> #include <sstream> #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <assert.h> #define ID(i,j,k) (( i * k ) + j) #define ARG(i,j) <<< dim3(i,j,1), dim3(1,1,1) >>> // computes the sum of matrices: c = (a + b) // a : n-...
21,783
/* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> __global__ void compute(float comp, int var_1,int var_2,int var_3,float var_4,int 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 var_14...
21,784
/** Cで学ぶアルゴリズムとデータ構造 ステップバイステップでN−クイーン問題を最適化 一般社団法人 共同通信社 情報技術局 鈴木 維一郎(suzuki.iichiro@kyodonews.jp) コンパイル $ nvcc CUDA01_N-Queen.cu -o CUDA01_N-Queen 実行 $ ./CUDA01_N-Queen 1. ブルートフォース 力任せ探索  全ての可能性のある解の候補を体系的に数え上げ、それぞれの解候補が問題の解とな るかをチェックする方法 (※)各行に1個の王妃を配置する組み合わせを再帰的に列挙組み合わせを生成するだ けであって8王妃問題を解いて...
21,785
/* icc propagate-toz-test.C -o propagate-toz-test.exe -fopenmp -O3 */ #include "cuda_runtime.h" #include <stdio.h> #include <stdlib.h> #include <math.h> #include <unistd.h> #include <sys/time.h> #include <iostream> #include <chrono> #include <iomanip> //#define DUMP_OUTPUT #define FIXED_RSEED //#define USE_ASYNC #ifnd...
21,786
#include "includes.h" __global__ void TwoNodesDistanceKernel( float *twoNodesDifference, float *twoNodesDistance, int vectorLength ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blockDim.x*blockIdx.x //blocks preceeding current block + threadIdx.x; if(threadId < 1) { fl...
21,787
#include <stdio.h> __global__ void hello(){ printf("Hello from block: %u, thread: %u\n", threadIdx.x, blockIdx.x); } int main(){ hello<<<2,1>>>(); cudaDeviceSynchronize(); }
21,788
#include "includes.h" __global__ void leftUnpackingKernel(double* temperature, double* ghost, int block_size) { int j = blockDim.x * blockIdx.x + threadIdx.x; if (j < block_size) { temperature[(block_size + 2) * (1 + j) + 1] = ghost[j]; } }
21,789
/*** Calculating a derivative with CD ***/ #include <iostream> #include <fstream> #include <cmath> #include <sys/time.h> void checkErrors(char *label) { // we need to synchronise first to catch errors due to // asynchroneous operations that would otherwise // potentially go unnoticed cudaError_t err; err = cudaThreadS...
21,790
#include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> #include <sys/time.h> __global__ void vecMultiply(int *arr, int size){ int tid = blockIdx.x * blockDim.x + threadIdx.x; if(tid<size){ for(int i = 0;i<100000;i++){ *(arr + tid) += 10; } } } int main(int argc, char *ar...
21,791
__global__ void kernel_forward_projection(float *d_a, float *d_b) { int idx = blockDim.x * gridDim.x * blockIdx.y + blockDim.x * blockIdx.x + threadIdx.x; d_b[idx]=d_a[idx]+0.6f; } __global__ void kernel_back_projection(float *d_a, float *d_b) { int idx = blockDim.x * gridDim.x * blockIdx.y + blockDim.x * bl...
21,792
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_runtime.h> #include <cuda_runtime_api.h> #include <time.h> #include <math.h> #include <algorithm> //For the given architecture, we do not require strides in avePooling layer. each N*M matrix is converted into one single value and stored into a me...
21,793
/* SU Project -- Taniya -- Cuda */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <cuda_runtime.h> /* Bounds of the Mandelbrot set */ #define X_MIN -1.78 #define X_MAX 0.78 #define Y_MIN -0.961 #define Y_MAX 0.961 __global__ void pixel_calculation(double dx, double dy, char...
21,794
#include <cstdlib> #include <cstdio> __global__ void kernel(int* arr,int n){ int idx=blockDim.x*blockIdx.x+threadIdx.x; if(idx<n){ arr[idx]=5; } return; } __host__ int main(int argc,char* argv[]){ int* arr=NULL; int* cuArr=NULL; const int n=100; size_t size=n*sizeof(int); arr=(int*)malloc(size); cudaMal...
21,795
__global__ void conv1D(int *arr,int *mask,int *res,int n,int m,int c){ int idi = blockIdx.y*blockDim.y+threadIdx.y; if(idi<n){ res[idi]=0; int a,b; b=idi-c; for(a=0;a<m;a++,b++){ if(b>=0 && b<n){ res[idi]+=mask[a]*arr[b]; } } } } __global__ void conv2D(int *arr,float *mask,float *res,int n1,int n...
21,796
#include "includes.h" __global__ void AddLocalErrorKernel( int s1, float *distance, float *localError ) { int threadId = blockDim.x*blockIdx.y*gridDim.x //rows preceeding current row in grid + blockDim.x*blockIdx.x //blocks preceeding current block + threadIdx.x; if(threadId < 1) { localError[s1] += distance[s1] ...
21,797
#include "includes.h" __global__ void inclusive_scan(const unsigned int *X, unsigned int *Y, int N) { extern __shared__ int XY[]; unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; // load input into __shared__ memory if(i<N) { XY[threadIdx.x] =X[i]; } /*Note here stride <= threadIdx.x, means that everytime the ...
21,798
#include "includes.h" #pragma comment(lib,"cublas.lib") using namespace std; //==============================Function Prototypes================================ double getRand(); __global__ void weightUpdate(float *d_W,float *d_D,float *d_N){ int2 pos; pos.x = blockIdx.x*blockDim.x + threadIdx.x;//row j pos.y = b...
21,799
#include <cuda_runtime.h> #include <cstddef> #include <sys/time.h> #include <iostream> #include <vector> void checkError( cudaError_t err) { if(err != cudaSuccess) { std::cout << cudaGetErrorString(err) << std::endl; exit(-1); } } //global is a kernel: global cannot be called from host, but can be called ...
21,800
#include <bits/stdc++.h> using namespace std; const int MAXX = 1e8; __constant__ int4 avg_dev[32]; __constant__ double cov_inv_dev[32][3][3]; __constant__ double dets_dev[32]; #define CSC(call) \ do { \ cudaError_t res = call; \ if (...