serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
18,801
// Babak Poursartip // 09/29/2020 // section 2: video 24 /* - If each warp is not fully occupant, that would be a waste of resources. - We need to calculate the occupancy of SM which is equal to: occupancy = active warps/max warps * max warps can be obtained from the device manual. * active warps needs to be ...
18,802
/* * Copyright 1993-2015 NVIDIA Corporation. All rights reserved. * * Please refer to the NVIDIA end user license agreement (EULA) associated * with this source code for terms and conditions that govern your use of * this software. Any use, reproduction, disclosure, or distribution of * this software and related...
18,803
#include <stdio.h> #include <cuda_runtime.h> __constant__ int test_arr_d[5]; __constant__ int a; __global__ void print() { int id = threadIdx.x; printf("%d: %d\n", id, test_arr_d[id]); __syncthreads(); } int main() { int test_arr_h[5] = {1, 2, 3, 4, 5}; cudaError_t result = cudaMemcpyToSymbolAsync(test_arr_d, ...
18,804
#include "cudaStepper.cuh" #include <stdio.h> __global__ void stepper( float* d_firingRate, float* d_newFiringRate, float* d_connMatrix, int* d_sampleNeuronIndexes, float* d_biasVec, float* d_samples, float* stepSize, int* numNeurons) { int neurNum = blockIdx.x; float fireSum = 0; int index; for (int i = ...
18,805
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #include <fstream> #include <vector> #include <string> #include <sstream> using namespace std; #define gpuErrchk(ans){gpuAssert((ans), __FILE__, __LINE__);} inline void gpuAssert(cudaError_t code, const char *file, int line, boo...
18,806
#include <cuda.h> #include <chrono> #include <cstdlib> #include <iostream> __global__ void transposeKernel(const double* A, double* AT, int N) { int xIndex = blockDim.x * blockIdx.x + threadIdx.x; int yIndex = blockDim.y * blockIdx.y + threadIdx.y; int index = xIndex + N * yIndex; int T_index = yIndex + N * x...
18,807
#include<iostream> #include <stdint.h> #include<stdio.h> #include<fstream> #include <stdlib.h> #include <malloc.h> #include <string.h> #include <sstream> using namespace std; #define REPEAT 1 #define STRIDE 1 #define CACHELINE 8 #define ALLIGNMENT 64 typedef unsigned long long Dtype; __global__ void VecAdd(Dtype** A,...
18,808
#include "stdio.h" #define COLUMNS 3 #define ROWS 2 __global__ void matadd(int *a, int *b, int *c) { int x = blockIdx.x; int y = blockIdx.y; int i = (COLUMNS*y) + x; c[i] = a[i] + b[i]; } /* ------------- COMPUTATION DONE ON GPU ----------------------------*/ int main() { int a[ROWS][COLUMNS], b[ROWS][COLUMNS], ...
18,809
// nvcc -ccbin "D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin" piCalculate.cu -o piCalculate.exe #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #include <cuda.h> #include <curand.h> #include <curand_kernel.h> #include <cuda_profiler_api.h> #define MAX_CUDA_BLOCKS 65535 #define...
18,810
// simple increment kernel #include <cuda.h> #include <stdio.h> //TODO: increment kernel __global__ void increment(float *val) { *val += 2.0f; } int main(void) { // create host array and initialize float *device_pointer; // print original value float input = 40.0f; printf("Input: %f\n", ...
18,811
#include <iostream> #include <cassert> #include <chrono> using namespace std; // M x K and K x N constexpr long M = 128; constexpr long K = 128; constexpr long N = 128; void MatmulOnCPU(double* mat1, double* mat2, double* result) { for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j){ double sum = 0...
18,812
/* * ===================================================================================== * * Filename: lud.cu * * Description: The main wrapper for the suite * * Version: 1.0 * Created: 10/22/2009 08:40:34 PM * Revision: none * Compiler: gcc * * Author: Li...
18,813
#include "includes.h" __global__ void assisted_activation_kernel(float alpha, float *output, float *gt_gpu, float *a_avg_gpu, int size, int channels, int batches) { int i = blockIdx.x * blockDim.x + threadIdx.x; int xy = i % size; int b = i / size; if (b < batches) { for (int c = 0; c < channels; ++c) { output[xy + si...
18,814
#include "includes.h" __global__ void gArgmax(float* out, const float* data, size_t rows, size_t cols) { size_t row = blockIdx.x; size_t startInd = row * cols; float maxScore = -99999; size_t maxInd; for(size_t col = 0; col < cols; ++col) { size_t ind = startInd + col; float score = data[ind]; if(score > maxScore) { ma...
18,815
#include "includes.h" #define WEIGHTSUM 273 #define BLOCK_SIZE 16 int * heatmap; size_t heatmap_pitch; int * scaled_heatmap; size_t scaled_heatmap_pitch; int * blurred_heatmap; size_t blurred_heatmap_pitch; float* d_desiredPositionX; float* d_desiredPositionY; __global__ void computeHeatmap(float* desiredAgentsX,...
18,816
#include "includes.h" __global__ void addKernel(int *a, int *b, int *c) { // each parallel invocation of add() is referred to as a block. // The set of blocks is referred to as a grid. // Each invocation can refer to its block index using blockIdx.x. // By using blockIdx.x to index into the array, each block handles a ...
18,817
#include <stdlib.h> #include <stdio.h> #include <curand.h> #include <time.h> #include <iostream> #include <string> #include <fstream> using namespace std; #define CURAND_CALL(x) do { if((x)!=CURAND_STATUS_SUCCESS) { \ printf("Error at %s:%d\n",__FILE__,__LINE__);\ return EXIT_FAILURE;}} while(0) int main...
18,818
#include "includes.h" /* TODO: Your code here */ /* all your GPU kernel code, e.g. matrix_softmax_cross_entropy_kernel */ // y = inputs[0], y_ = inputs[1] // np.mean(-np.sum(y_ * np.log(softmax(y)), axis=1), keepdims=True) __global__ void matrix_softmax_cross_entropy_kernel(int nrow, int ncol, const float *input_...
18,819
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <assert.h> #include <time.h> #define R 3 __global__ void oneD_stencil_naive(int *in_arr, int *out_arr) { int in_index = blockIdx.x + threadIdx.x; int out_index = blockIdx.x; // guaranteed to be performed without interference from other thr...
18,820
#include <stdio.h> #include <assert.h> #include <stdlib.h> #include <cuda.h> __global__ void render(char *out, int width, int height) { int index = 3 * (blockIdx.x * blockDim.x + threadIdx.x); int x_dim = (index / 3) % width, y_dim = (index / 3) / width; float x_origin = ((float) x_dim/width)*3.25 - 2; float ...
18,821
#include "includes.h" __global__ void pcr_k(float* a, float* b, float* c, float* y, int n) { // Identifies the thread working within a group int tidx = threadIdx.x % n; // Identifies the data concerned by the computations int Qt = (threadIdx.x - tidx) / n; // The global memory access index int gb_index_x = Qt + blockId...
18,822
#include <iostream> #include <time.h> #include <stdio.h> // For the CUDA runtime routines #include <cuda_runtime.h> //initializing vectors with random numbers void initVec(float *a, int N) { for(int i = 0; i < N; ++i) { a[i] = rand()%100; } } //initializing vector with appointed number(probably u...
18,823
#include<stdio.h> #include "cuda_runtime.h" int main() { int deviceCount; cudaGetDeviceCount(&deviceCount); printf("device count is: %d\n", deviceCount); for (int dev = 0; dev < deviceCount; dev++) { cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); printf("\n...
18,824
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> __global__ void setMax(long* d_adj, int n){ int x = threadIdx.x; int y = threadIdx.y; int pos = (x * n) + y; if(x == y) d_adj[pos] = 0; //Diagonal elements else d_adj[pos] = __IN...
18,825
#include <stdio.h> #include <cuda_runtime.h> #define CHECK(call) { \ const cudaError_t error = call; \ if (error != cudaSuccess) { \ printf("Error: %s:%d, ", __FI...
18,826
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void sumArrayOnHost(float *A, float *B, float *C, const int N) { for (int idx=0; idx<N; idx++) { C[idx] = A[idx] + B[idx]; } } void initialData(float *ip, int size) { // Generate different seed for random number. time_t t; srand((u...
18,827
/* Compute potential energy for a system of particles Miguel Aragon Calvo Apr/2010 "This software contains source code provided by NVIDIA Corporation." "Glue c code based on galaxy collision demo" History: - 10/05/2010 First working implementation - 01/06/2010 Add softening */ /* * Copyright 1993-2006 ...
18,828
#include <stdio.h> #include <stdlib.h> #include <cuda.h> #define MAX_LEN 256 /* Lab 7: Programs on strings * Q1: Write a CUDA program to count the number of times * a given word is repeated in a sentence. (Use atomic function) */ __constant__ int len_sentence; __constant__ int len_word; __global__ void countWor...
18,829
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <stdio.h> __global__ void reduce1(int *g_idata, int *g_odata) { extern __shared__ int sdata[]; unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; sdata[tid] = g_idata[i]; ...
18,830
#include "includes.h" __global__ void convn_same_kernel(float *output, float *data, float *kernel, const int H, const int W, const int kH, const int kW) { // Matrix index const int x = blockIdx.x*blockDim.x + threadIdx.x; const int y = blockIdx.y*blockDim.y + threadIdx.y; if (x >= H || y >= W) return; const int i0 =...
18,831
// GPU with parallelization version // Parallelization is implemented with CUDA #include <iostream> #include <cstdlib> #include <ctime> #include <cmath> #include <cuda.h> using namespace std; // __global__ means the function runs on GPU, and called from CPU (in this case the function is called by main(), which runs o...
18,832
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <cuda.h> __global__ void findMaxKernel(unsigned int *array, unsigned int *max, int *mutex, unsigned int n) { unsigned int index = threadIdx.x + blockIdx.x*blockDim.x; unsigned int stride = gridDim.x*blockDim.x; unsigned int offset = 0; __shared__ u...
18,833
// Listing 5.1: dd_1d_global/main.cpp #include <iostream> #include <fstream> #include <cuda_runtime.h> #define TPB 64 // thread per block __global__ void ddKernel(float *d_out, const float *d_in, int size, float h) { // on device, and hence do not have access to CPU memory int i = blockIdx.x * blockDim.x ...
18,834
#include "includes.h" __global__ void gPasteCols(float* out, const float* in, size_t rows, size_t colsOut, const size_t* targetColIdx, size_t colsIn) { for(int bid = 0; bid < rows; bid += gridDim.x) { int j = bid + blockIdx.x; if(j < rows) { const float* rowIn = in + j * colsIn; float* rowOut = out + j * colsOut; for(...
18,835
// #include "RayMarchSampler.h" // #include <crt/host_defines.h> // #include "float3Extension.h" // #include "math.h" // #include <vector_functions.hpp> // #include "float4x4.h" // // // #include "Ray.h" // // #include "Camera.h" // // #include "float3Extension.h" // // #include <curand_discrete2.h> // // #include <dev...
18,836
#define THREADS_PER_BLOCK 128 #include <cmath> #include <chrono> #include <cstring> #include <fstream> #include <iostream> #include <stdexcept> #include "tiffio.h" // saves TIFF file from data in `raster` void save_tiff(const char *fname, uint32 *raster, uint32 w, uint32 h) { TIFF *tif = TIFFOpen(fname, "w"); ...
18,837
#include "includes.h" __global__ void matrixMultiply(float *A, float *B, float *C, int numARows, int numAColumns, int numBRows, int numBColumns, int numCRows, int numCColumns) { //@@ Insert code to implement matrix multiplication here }
18,838
/* Copyright (c) 2013-2015, Gregory P. Meyer University of Illinois Board of Trustees All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must re...
18,839
__global__ void SoftMaxLossForward(const float* bottom_data, const int* bs, const float* label, const float* label_weight, const int* ls, const float threshold, const int label_start, bool hasLabel_weight, float* loss) { // bs = bottomSize int index = blockIdx.x * blockDim.x + threadIdx.x; if (index >...
18,840
//pass //--gridDim=[4,1,1] --blockDim=[512,1,1] __global__ void initValue(float *od, float value) { // position of write into global memory unsigned int index = (blockIdx.x * blockDim.x) + threadIdx.x; od[index] = value; // sync after each decomposition step __syncthreads(); }
18,841
#include <stdio.h> #define SIZE 1024 __global__ void VectorAdd( int * a, int *b, int* c, int n) { int i = threadIdx.x; if(i < n) c[i] = a[i] + b[i]; } int main() { int *a, *b , * c; int *d_a, *d_b, *d_c; //allocate space for all gpu and cpu data a = (int *)malloc(SIZE * sizeof(int));...
18,842
#include "includes.h" __global__ void run_reduction(bool *con, bool *blockCon,int* ActiveList, int nActiveBlock, int* blockSizes) { int list_idx = blockIdx.y*gridDim.x + blockIdx.x; int maxblocksize = blockDim.x; int tx = threadIdx.x; int block_idx = ActiveList[list_idx]; int blocksize = blockSizes[block_idx]; __shar...
18,843
/* * CUDA Peer to Peer Example */ #include<cuda.h> #include<stdio.h> #include<sys/time.h> #define SIZE 1048576 #define THREADS_PER_BLOCK 256 #define FLOAT(t) ((float)(t).tv_sec+((float)(t).tv_usec)/1000000) #define CHECK_RUN( errorDescription ) { cudaError_t cerror; \ if( (cerror = cudaGetLastError()) != cu...
18,844
/* This version is "NO Streaming" version. 12/16 Try streaming! */ #include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <cuda_profiler_api.h> #include <time.h> // #define TIME // #define CUDA_NVPROF const int BLOCKING_FACTOR = 32; // 32, 16, 8, 4, 2 const int INF = ((1 << 30) - 1); // Global var st...
18,845
#include "assignmentHPC1.cuh" #include <iostream> #include <cstdlib> using namespace std; int main() { unsigned int N = 1024*1024*512; double *arr_host = (double *)malloc(N * sizeof(double)); for(unsigned int i = 0; i < N; i++) { arr_host[i] = 1 ;//rand()%(1024*1024) + 10; } cout<<"\...
18,846
#include <new> struct Foo { int value = 0x1234; }; __global__ void kernel_independent(Foo* storage, Foo** initialized) { Foo* start = storage + threadIdx.x * 2; initialized[threadIdx.x] = new (start) Foo; new (start + 1) Foo; }
18,847
#include <iostream> #include <math.h> int add(int n, float *x, float *y) { for (int i = 0; i < n; i++) y[i] = x[i] + y[i]; } int main(void) { int N = 1<<20; float *x = new float[N]; float *y = new float[N]; //init x, y arrs on host for (int i = 0; i < N ; i++ ) { x[i] = 1...
18,848
/* Faz a soma dos elementos de dois vetores Exemplifica o uso de cudaMallocHost() para alocar memoria paginada no host e o uso de cudaFreeHost para desalocar() Para compilar: nvcc 01-soma-vet-pinned.cu -o 01-soma-vet-pinned Para executar: ./01-soma-vet-pinned OBS: os valores de tamanho do vetor e o conteudo do veto...
18,849
#include "includes.h" __global__ void block_sum_kernel(int *arr, int size, int *block_sums) { int num_threads = blockDim.x * gridDim.x; int tid = threadIdx.x + blockIdx.x * blockDim.x; // Each thread finds local sum of its assigned area int my_sum = 0; __shared__ int smem[128]; while (tid < size) { my_sum += arr[tid];...
18,850
#include <iostream> #include <stdlib.h> #include <math.h> #include <algorithm> #include <stdio.h> #include <fcntl.h> #include <time.h> #define NS_PER_SEC (1000*1000*1000) using namespace std; int base[12]; int base7[21]; int base8[24]; int base11[33]; int base12[36]; int base13[39]; int base14[42]; inline unsigned lo...
18,851
#include "includes.h" // Include files // Parameters #define N_ATOMS 343 #define MASS_ATOM 1.0f #define time_step 0.01f #define L 10.5f #define T 0.728f #define NUM_STEPS 10000 const int BLOCK_SIZE = 1024; //const int L = ; const int scheme = 1; // 0 for explicit, 1 for implicit /**********************************...
18,852
#include "includes.h" __global__ void glcm_calculation_270(int *A,int *glcm, const int nx, const int ny,int max){ int ix = threadIdx.x + blockIdx.x* blockDim.x; int iy = threadIdx.y + blockIdx.y* blockDim.y; unsigned int idx =iy*nx+ix; int i; int k=0; for(i=0;i<nx-1;i++){ if(idx>=i*nx && idx<((i+1) *nx)){ k=max*A[idx]+...
18,853
#include <iostream> __global__ void vectorAdd(int *a, int *b, int *c, int n){ int i = blockIdx.x*blockDim.x+threadIdx.x; if(i<n) for(int j=0;j<100;j++) c[i] = a[i] + b[i]; } int main(void){ int * a, * b; int * r1, * r2, *r3; int * temp; const int n = 1<<24; const int n_s = 3; cudaStream_t streams[n_s]; ...
18,854
/* * ARQUITECTURA DE COMPUTADORES * 2º Grado en Ingenieria Informatica * * PRACTICA 2: "Suma De Matrices Paralela" * >> Arreglar for en __global__ * >> Pasar numElem como argumento * * AUTOR: Ivanes */ /////////////////////////////////////////////////////////////////////////// // Includes #include <stdio.h> #include <...
18,855
/* This is the function you need to implement. Quick reference: - input rows: 0 <= y < ny - input columns: 0 <= x < nx - element at row y and column x is stored in data[x + y*nx] - correlation between rows i and row j has to be stored in result[i + j*ny] - only parts with 0 <= j <= i < ny need to be filled */ //#includ...
18,856
#include "stdio.h" #include <stdlib.h> #define N 10 __global__ void add( int *a, int *b, int *c ) { int tid = 0; while (tid < N) { c[tid] = a[tid] + b[tid]; tid += 1; } } int main( void ) { size_t size = N* sizeof(int); int* h_a = (int*)malloc(size); int* h_b = (int*)malloc...
18,857
extern "C" __global__ void backwardDropoutKernel (int numberEntries, float* chain, float* mask, float* result) { int index = blockIdx.x * blockDim.x + threadIdx.x; if(index < numberEntries) { result[index] = chain[index] * mask[index]; } }
18,858
#include <cuda_runtime.h> #include <device_launch_parameters.h> #include <stdio.h> #include <time.h> #include<sys/time.h> //don't forget the time double cpuSecond() { //#ifdef LINUX_IMP struct timeval tp; gettimeofday(&tp,NULL); return ((double)tp.tv_sec + (double)tp.tv_usec*1.e-6); //#endif } __global_...
18,859
#include<iostream> using namespace std; int n = 100; __host__ __device__ bool read(int n) { return n != 0; } __host__ __device__ bool read0(int n) { return n == 0; } __global__ void test(int n) { if(read0(n)) { printf("true\n"); } else if(read(n)){ printf("false\n"); } } int main() { dim3 block(...
18,860
#include <cuda.h> #include <curand.h> #include <curand_kernel.h> #include <stdio.h> #include <ctime> __global__ void setup_random_kernel(curandState *state, int length, int offset) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < length) { curand_init((unsigned long long) clock(), idx, 0, &...
18,861
/* Now we make the matrix much bigger g++ -pg seq_matrix_big_mul.c -o seq_matrix_big_mul */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #define N_THREADS 20 int num_rows_A = 2000; int num_rows_B = 2000; int num_rows_C = 2000; int num_cols_A = 2000; int num_cols_B = 600; int num_co...
18,862
#include "includes.h" __global__ void kernel_test5_init(char* _ptr, char* end_ptr) { unsigned int i; unsigned int* ptr = (unsigned int*) (_ptr + blockIdx.x*BLOCKSIZE); if (ptr >= (unsigned int*) end_ptr) { return; } unsigned int p1 = 1; for (i = 0;i < BLOCKSIZE/sizeof(unsigned int); i+=16){ unsigned int p2 = ~p1; pt...
18,863
#include <iostream> #include <math.h> #include <unistd.h> //#include <memory> #include <algorithm> #include <vector> const std::size_t N = 1 << 20; __device__ // can only be called from within a kernel, not from the host void vec_inc(float* const c, const std::size_t n) { for (std::size_t i = threadIdx.x + (blo...
18,864
#include <stdio.h> #include <chrono> __global__ void multiplyCell(int N, int * a, int * b, int * c){ // We get the index of the current data unsigned int threadx = blockDim.x * blockIdx.x + threadIdx.x; unsigned int thready = threadIdx.y + blockIdx.y * blockDim.y; unsigned int threadxy = thready * N...
18,865
extern "C" __global__ void initDbIndexKernel(int totalVars, int totalPreds, int *d_varDomainSizes, int *d_predBaseIdx, int *d_predVarMat, int *d_dbIndex, long totalGroundings) { long idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < totalGroun...
18,866
#include<stdio.h> #include<cuda.h> __global__ void sumRandC(int* A, int* B, int m, int n, int p, int q, int k) { int id=blockIdx.x*blockDim.x + threadIdx.x,idx; if(id<((m*n)/k)) { for(int i=0;i<k;i++) { idx = id+i*((m*n)/k); B[idx+(idx/n)] = A[idx]; atomicAdd(&B[(((idx/n)+1)*n)+(idx/n)],A[idx]); ...
18,867
/* * ECE 5720 Parallel Computing final project * Substring matching with CUDA * Shicong Li sl3295 * Siyu Liu sl3282 * Cornell University * * Compile : /usr/local/cuda-10.1/bin/nvcc -arch=compute_52 -o KMP_cuda KMP_cuda.cu * Run : ./KMP_cuda */ #include "cuda_profiler_api.h" #include <cuda.h> #include <cud...
18,868
#include <stdio.h> #include <cuda.h> #include <time.h> __global__ void add_vectors(float *a, float *b, float *c, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < N) { c[idx] = a[idx] + b[idx]; } } int main(void) { float *a_h, *a_d, *b_h, *b_d, *c_h, *c_d; const int N = 10; size_t si...
18,869
#include <stdio.h> void CPUFunction() { printf("Hello world from the CPU.\n"); } __global__ void GPUFunction() { printf("Hello world from the GPU.\n"); } int main() { // function to run on the cpu CPUFunction(); // function to run on the gpu GPUFunction<<<1, 1>>>(); // kernel execution is asynchron...
18,870
/* ============================================================================ Filename : algorithm.c Author : Arthur Vernet, Simon Maulini SCIPER : 245828, 248115 ============================================================================ */ #include <iostream> #include <iomanip> #include <sys/time.h> ...
18,871
#include <stdio.h> #include <cuda.h> #include <assert.h> #define N 2//64 __device__ int* bar(int* p) { return p; } __global__ void foo(int* p) { int* q = bar(p); q[threadIdx.x] = 0; //printf(" %d; ", q[threadIdx.x]); }
18,872
#include <stdio.h> int main() { int count = 0; if (cudaSuccess != cudaGetDeviceCount(&count)){return -1;} if (count == 0) {return -1;} for (int device = 0; device < count; ++device) { cudaDeviceProp prop; if (cudaSuccess != cudaGetDeviceProperties(&prop, device)){ continue;} ...
18,873
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/sort.h> #include <iostream> int main(){ // H has storage for 4 integers thrust::host_vector<int> H(1000); for(int c = 0; c < 1000; c++){ H[c] = 1000-c; } for(int c = 0; c < 10; c++){ std::cout << H[c] ...
18,874
#include "includes.h" //============================================================================= // FILE: mytoy.cu // AUTHORS: Raul Segura & Manuel Ujaldon (copyright 2014) // Look for the string "MU" whenever Manuel suggests you to introduce changes // Feel free to change some other parts of the code too (at yo...
18,875
#include "kernel.cuh" #define N 5 __global__ void gpuSquareKernel(float* d_in, float* d_out) { int tid = threadIdx.x; float temp = d_in[tid]; d_out[tid] = temp * temp; } void gpuSquare(float* h_in, float* h_out) { float *d_in, *d_out; cudaMalloc((void**)&d_in, N * sizeof(float)); cudaMalloc(...
18,876
// based on https://gist.github.com/dpiponi/1502434 #include <stdio.h> #define N 256 // 0x1d710 // 65536 // 4096 //1024 #define h2d(h,d,n) cudaMemcpy(d,h,sizeof(int)*n, cudaMemcpyHostToDevice) #define d2h(d,h,n) cudaMemcpy(h,d,sizeof(int)*n, cudaMemcpyDeviceToHost) #define I(n) for(int i=0;i<n;++i) __global__ void ...
18,877
#include <stdio.h> #include <string.h> const int N = 8; const int BLOCKSIZE = 8; const int GRIDSIZE = 1; // ---------------------------------------------- KERNELS --------------------------------------------------------------- __global__ void gpu_inclusive_scan (int *in, int *out) { extern __shared__ int cache[];...
18,878
//nvcc -ptx electron_transport.cu -ccbin "F:Visual Studio\VC\Tools\MSVC\14.12.25827\bin\Hostx64\x64" #include "curand_kernel.h" __device__ void EM1(double *x, double *y, double *z, double *vx, double *vy, double *v...
18,879
#include<cmath> #include<cstdio> //#define BLOCKSIZE 1 __global__ void dotproduct(int* A,int*B,int*C,int M,int N,int K) { printf("%d %d\n", A[0],A[1]); printf("%d %d\n", B[0],B[1]); printf("%d %d\n", C[0],C[1]); int I=blockIdx.x*blockDim.x+threadIdx.x; int J=blockIdx.y*blockDim.y+threadIdx.y; int temp =0; if( ...
18,880
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <iostream> #include <fstream> #include <string> #include <vector> #include <cassert> using namespace std; __global__ void global_reduce_kernel(int* d_out, int* d_in, int size) { //indices int myId = threadIdx.x + block...
18,881
#include <stdio.h> struct StringData { char str[11]; }; unsigned int *devDataInput; StringData *devStringDataOutput; unsigned int dataCount; template< typename T > void check(T result, char const *const func, const char *const file, int const line) { if (result) { fprintf(stderr, "CUDA error at %s:%...
18,882
/* * Author: * Yixin Li, Email: liyixin@mit.edu * convert the image from RGB to LAB */ __global__ void rgb_to_lab( double * img, const int nPts) { // getting the index of the pixel const int t = threadIdx.x + blockIdx.x * blockDim.x; if (t>=nPts) return; double sR = img[3*t]; double sG = img[3*t+1]; double sB ...
18,883
#include <cuda.h> #include <stdio.h> __global__ void gTest(float* a) { a[threadIdx.x + blockDim.x * blockIdx.x] = (float) (threadIdx.x + blockDim.x * blockIdx.x); } __global__ void gSGEVV(float* a, float* b, float* c) { c[threadIdx.x + blockDim.x * blockIdx.x] = a[threadIdx.x + blockDim.x * blockIdx.x] + b[th...
18,884
#include <stdio.h> #include "cuda.h" #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define ceil(a,b) ((a) % (b) == 0 ? (a) / (b) : ((a) / (b)) + 1) void check_error (const char* message) { cudaError_t error = cudaGetLastError (); if (error != cudaSuccess) { printf ("CUDA error :...
18,885
#include <algorithm> #include <fstream> #include <iostream> #include <sstream> #include <vector> // Error check----- #define gpuErrchk(ans) \ { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, ...
18,886
#include "includes.h" __global__ void setPriorAtLast ( const int dim, const int nwl, const float *lst, float *prr ) { int i = threadIdx.x + blockDim.x * blockIdx.x; if ( i < nwl ) { prr[i] = lst[dim+3+i*(dim+1+1+1+1)]; } }
18,887
#include<stdlib.h> #include<stdio.h> #include<time.h> #define n 1024 __global__ void mul_mat(int *a, int *b, int *c) { int myx, myy, i; myx = blockIdx.x * blockDim.x + threadIdx.x; myy = blockIdx.y * blockDim.y + threadIdx.y; int local; for (i = 0; i < n; i++) local += a[myx+n*i] * b[n*i+myy]; c[myx*n+myy]...
18,888
/** size of A = 640 size of B = 600 gridDim = 60 blockDim = 64 k= 10000 x = 10 **/ __global__ void MultiplyVectors(const float* A, const float* B, float* C, int x, int k) { int B_start_index = (blockIdx.x*gridDim.y + blockIdx.y)*x; int A_start_index = (threadIdx.x*blockDim.y + threadIdx.y)*x; in...
18,889
#include <stdio.h> #include <stdlib.h> #include <string.h> // For the CUDA runtime routines (prefixed with "cuda_") #include <cuda_runtime.h> int M=0, N=0, M_final, N_final; int J=0, K=0; long pos; double A[10000][10000], H[10][10]; /*-------------------------------- Reading from the input matrix file => A of si...
18,890
#include "includes.h" __global__ void square_array(float *a, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx<N) a[idx] = a[idx] * a[idx]; }
18,891
////3.5ܹ֧֡˺ú˺ //#include <stdio.h> // // // //__global__ void childKernel(int i) //{ // int tid = blockIdx.x*blockDim.x+threadIdx.x; // printf("parent:%d,child:%d\n",i,tid); // for(int j=i;j<i+10;j++) // { // printf(",%d",j); // } // printf("\n"); //} // //__global__ void kernel() //{ // // int tid = blockIdx.x*blockD...
18,892
#include <stdio.h> #define BLOCK_SIZE 512 __global__ void spmv_csr_kernel(unsigned int dim, unsigned int *csrRowPtr, unsigned int *csrColIdx, float *csrData, float *inVector, float *outVector) { // INSERT KERNEL CODE HERE int row = blockDim.x*blockIdx.x+threadIdx.x; if (row < dim){ float dot = 0; in...
18,893
#include <cuda.h> #include <stdio.h> #include <time.h> #define SIZE 10 __global__ void max(int *a , int *c) // kernel function definition { int i = threadIdx.x; // initialize i to thread ID *c = a[0]; //printf("a[i] is %d \n",a[i]); atomicMin(c,a[i]); //printf("max is %d \n",*c); } int main() { int i; srand(...
18,894
#include <sys/time.h> #include <stdio.h> #include <stdlib.h> #define THREAD_PER_BLOCK 16 // on fixe le nombre de colonnes à 16 #define COLUMNS 16 //fct gpu __global__ void multiplication_matrix_GPU(int *a, int *b, int*c) { int idx = blockIdx.x * THREAD_PER_BLOCK + threadIdx.x; int sum = 0; __shared__ i...
18,895
#include <cuda.h> #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #define N 1920; #define M 1080; #define CHANNELS 3; void colorTogrey(int *, int *,int,int,int); // we have 3 channels corresponding to RGB // The input image is encoded as unsigned characters [0, 255] __global__ void ...
18,896
#include "includes.h" __constant__ float *c_Kernel; __global__ void convolutionRowsKernel_v1( float *d_Dst, float *d_Src, int imageW, int filter_Rad, int Halo_steps ) { extern __shared__ float s_Data[]; //Offset to the left halo edge const int baseX = (blockIdx.x * ROWS_RESULT_STEPS - Halo_steps) * ROWS_BLOCKDIM_X +...
18,897
__global__ void neg_kernel(int n, const float *x, float *z) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < n) z[i] = -x[i]; } void neg(int n, const float *x, float *z) { neg_kernel<<<(n+255)/256, 256>>>(n, x, z); }
18,898
#include <cuda.h> #include <iostream> using namespace std; /* 2D thread block version of addOne kernel */ __global__ void addOne(double *data) { int b = blockIdx.x; int tx = threadIdx.x; int ty = threadIdx.y; // 2D threads are mapped to 1D memory int i = b * (blockDim.x * blockDim.y) + (ty * blockDim.x + tx)...
18,899
#include "kronmult.cuh" #include <device_launch_parameters.h> #include <type_traits> /* * computes number^power for integers * does not care about performances * does not use std::pow as it does an implicit float conversion * that could lead to rounding errors for large numbers */ __host__ int pow_int(int const n...
18,900
#include <stdio.h> __global__ void kernel(int *num1, int *num2, int *result) { *result = *num1 + *num2; } int main(void) { // host copies int num1, num2, result; // device copies int *p_num1, *p_num2, *p_result; // allocate space on device cudaMalloc(&p_num1, sizeof(int)); cudaMalloc...