serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
4,801
#include <stdio.h> __global__ void add(int *a, int *b, int *c) { // note that add has no variables in its scope, instead it reads and // modifies variables that live elsewhere. *c = *a + *b; } int main(void) { // declare three integers in the host's memory space int h_a; int h_b; int...
4,802
/* The code generates a 3D image of a stack of images. For each image (matrix) calculate the variance at all points, and then create a topography matrix (relief matrix) with the position (number in the stack) of the image that had the largest variance in a pixel. The same with the color of the image (RGB matrices). */...
4,803
#include <stdlib.h> #include <stdio.h> #include <math.h> // P = max power of 2 to test up to // i.e., test for N = 2^0, 2^1, 2^2... 2^P #define P 15 #define TILE_WIDTH 1 #define ThreadsPerBlock (1<<10) #define BlocksPerGrid ((1<<16)-1) #define RANDRANGE 5 #define VERBOSE 0 __global__ void dot(float* a, float* b, fl...
4,804
#include "includes.h" __device__ float fitness_function(float x[]) { float y,yp; float res=0; float y1=1+(x[0]-1)/4; float yn=1+(x[NUM_OF_DIMENSIONS-1]-1)/4; res+=pow(sin(phi*y1),2)+pow(yn-1,2); for(int i=0;i<NUM_OF_DIMENSIONS-1;i++) { y=1+(x[i]-1)/4; yp=1+(x[i+1]-1)/4; res+=pow(y-1,2)*(1+10*pow(sin(phi*yp),2)); }...
4,805
__global__ void getLineFromAccum(unsigned int* accum, int w_accum, int h_accum, int* dev_points, int* max) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; int tid = y * w_accum + x; if (x >= w_accum || y >= h_accum) return; int temp_max; if (max[0] == (int)accu...
4,806
#include <stdio.h> #include <stdlib.h> #include <math.h> #define BLOCKSIZE 4 // Number of threads in each thread block /* * CUDA kernel to find a global max, each thread process * one element. * @param values input of an array of integers in which we search a max number * @param max output of this kernel, the ...
4,807
__global__ void init_i32 (int* vector, int value, int len) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < len) { vector[idx] = value; } } extern "C" { void VectorPacked_init_i32 (int* vector, int value, int len, cudaStream_t stream) { dim3 gridDim; dim3 blockDim; blockDim.x = 1024; gridDim.x =...
4,808
// CudafyByExample.ripple_gpu extern "C" __global__ void thekernel( unsigned char* ptr, int ptrLen0, int ticks); // CudafyByExample.ripple_gpu extern "C" __global__ void thekernel( unsigned char* ptr, int ptrLen0, int ticks) { int num = threadIdx.x + blockIdx.x * blockDim.x; int num2 = threadIdx.y + blockIdx.y * ...
4,809
#include <thrust/device_vector.h> #include <thrust/host_vector.h> #include <iostream> #include <chrono> #include <thrust/count.h> #include <thrust/functional.h> #include <thrust/iterator/constant_iterator.h> struct maior_que_zero{ __host__ __device__ bool operator()(const double &x){ return x > 0; ...
4,810
// Copyright (c) 2019-2020, 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 o...
4,811
#include "stdio.h" #define N 128 __global__ void add(int *A, int *B, int *C) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if (i < N && j < N) { C[i * N + j] = A[i * N + j] + B[i * N + j]; } } int main( void ) { int a[N * N], b[N * N...
4,812
#ifndef uint32_t #define uint32_t unsigned int #endif #define H0 0x67452301 #define H1 0xEFCDAB89 #define H2 0x98BADCFE #define H3 0x10325476 #define H4 0xC3D2E1F0 __device__ uint32_t rotl(uint32_t x, uint32_t n) { return (x >> (32 - n)) | (x << n); } __device__ uint32_t get_global_id() { uint32_t blockId, thre...
4,813
#include "includes.h" using namespace std; #define D 3 #define N 200 #define K 512 #define Nt 20 #define Rt 0.1f #define c 0.001f #define ct 0.0001f __global__ void NextQTur(float* Qt, float* Pt) { int i = threadIdx.x; Qt[i + 0] += Pt[i + 0] * ct; Qt[i + 1] += Pt[i + 1] * ct; Qt[i + 2] += Pt[i + 2] * ct; }
4,814
#include "includes.h" __global__ void multiplyNumbersGPU(float *pDataA, float *pDataB, float *pResult) { int tid = (blockIdx.y * 128 * 256) + blockIdx.x * 256 + threadIdx.x; pResult[tid] = sqrt(pDataA[tid] * pDataB[tid] / 12.34567) * sin(pDataA[tid]); }
4,815
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define M 20 // RED = 0, BLACK = 1 enum nodeColor { RED, BLACK }; enum result { Failure, Success, FirstInsert }; enum caseFlag { NOOP, DID_CASE1, DID_CASE3 }; struct par_rbNode { int key, color; in...
4,816
#include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> #include<cuda.h> #include<cuda_runtime.h> #define NXPROB 288 /* x dimension of problem grid */ #define NYPROB 288 /* y dimension of problem g...
4,817
#include "cuda_runtime.h" #include "math.h" __device__ int diff(int a, int b) { return (((16711680 & a) - (16711680 & b)) >> 16) * (((16711680 & a) - (16711680 & b)) >> 16) + (((65280 & a) - (65280 & b)) >> 8) * (((65280 & a) - (65280 & b)) >> 8) + ((255 & a) - (255 & b)) * ((255 & a) - (255 & b)); } __device__ ...
4,818
__global__ void matmul(int n, const float *A, const float *B, float *C){ int tx = threadIdx.x; int ty = threadIdx.y; int bx = blockIdx.x; int by = blockIdx.y; int row = by*blockDim.y + ty; int col = bx*blockDim.x + tx; if(row < n && col < n){ float val = 0.0; for(int i=0; i<n; ++i){ val ...
4,819
#include "stdio.h" __global__ void MyKernel(int *array, int arrayCount) { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < arrayCount) { array[idx] *= array[idx]; } } int main (void) { int arrayCount = 1024*1024; int *array = (int*)malloc(sizeof(int)*arrayCount); int blockSize; ...
4,820
#include <stdio.h> #include <stdlib.h> #include <cuda.h> __global__ void vecMulKernel(float* a, float* b, float* c, int n) { int i = threadIdx.x + blockDim.x * blockIdx.x; if(i<n) c[i] = a[i] * b[0]; } int main(void) { int N = 24; int i; float *A, *B, *C, *d_A, *d_B, *d_C; int size = N * sizeof(float); A=(flo...
4,821
#include <cassert> #include <iostream> #include <vector> // Here you can set the device ID that was assigned to you #define MYDEVICE 1 // Simple utility function to check for CUDA runtime errors void checkCUDAError(const char* msg); // Part 3 of 5: implement the kernel __global__ void myFirstKernel(int* d_a, int num...
4,822
#include <iostream> #include <fstream> #include <string> #include <sstream> #include <vector> #include <utility> #include <cstdlib> __constant__ unsigned int d_lookup[256]; int get_one(unsigned int value); struct MyBitMap { unsigned int *bits; int x,y; unsigned long long int size; MyBitMap(int row, int col) { ...
4,823
#include "includes.h" __global__ void add_img(float *image_padded, float *ave1, float *ave2, int nx, int ny, int nima) { // Block index int bx = blockIdx.x; // Thread index int tx = threadIdx.x; float sum1 = 0.0; float sum2 = 0.0; int index = tx+bx*nx; int index2 = tx+(nx>>1)+(bx+(ny>>1))*(nx*2+2); for (int i=0; i<...
4,824
#include "includes.h" __global__ void Match5(float *d_pts1, float *d_pts2, float *d_score, int *d_index) { __shared__ float4 buffer1[M5W*(NDIM/4 + 1)]; __shared__ float4 buffer2[M5H*NDIM/4]; __shared__ float scores[M5W*M5H]; int tx = threadIdx.x; int ty = threadIdx.y; int bp1 = M5W*blockIdx.x; if (ty<M5W) for (int d=tx...
4,825
#include<stdio.h> #include<math.h> #define abs(x) (x > 0 ? x : -(x)) #define MAX(a,b) (a > b ? a : b) #define MIN(a,b) (a < b ? a : b) #define PI 3.1415926 #define GRIDDIM 32 #define BLOCKDIM 1024 //32*32 extern "C" void TOF_filter(float *filter_v, const int nx, const int ny, const float tof_sigma); __device__ voi...
4,826
/** * @file pctdemo_processMandelbrotElement.cu * * CUDA code to calculate the Mandelbrot Set on a GPU. * * Copyright 2011 The MathWorks, Inc. */ /** Work out which piece of the global array this thread should operate on */ __device__ size_t calculateGlobalIndex() { // Which block are we? size_t const...
4,827
#include "includes.h" __global__ void transposeUnroll4Col(float *out, float *in, const int nx, const int ny) { unsigned int ix = blockDim.x * blockIdx.x * 4 + threadIdx.x; unsigned int iy = blockDim.y * blockIdx.y + threadIdx.y; unsigned int ti = iy * nx + ix; // access in rows unsigned int to = ix * ny + iy; // acces...
4,828
#include<iostream> using namespace std; __global__ void sum(int *input){ int tid = threadIdx.x; int step =1; int number_of_threads = blockDim.x; while(number_of_threads>0){ if(tid<number_of_threads){ int fst = tid * step * 2; int snd = fst + step; printf("%d\\n",input[fst]+input[snd]); input[fst]+...
4,829
extern "C" __global__ void mul(double* A, double* B, double* C, int size) { int i = blockIdx.x * blockDim.x + threadIdx.x; if(i < size) { // compute a column for(int j=0; j < size; j++) { double sum = 0.0; for(int k=0; k < size; k++) { sum += A[ (i*size)+k ] * B[ (k*size)+j ]; } ...
4,830
#include "includes.h" __global__ void KerCalcRidp(unsigned n,unsigned ini,unsigned idini,unsigned idfin,const unsigned *idp,unsigned *ridp) { unsigned p=blockIdx.x*blockDim.x + threadIdx.x; //-Number of particle. if(p<n){ p+=ini; const unsigned id=idp[p]; if(idini<=id && id<idfin)ridp[id-idini]=p; } }
4,831
// Gregory Paton // 322:451 // CUDA Mandelbrot #include <stdio.h> #include <string.h> #include <math.h> #define X_RESN 800 /* x resolution */ #define Y_RESN 800 /* y resolution */ typedef struct complextype { float real, imag; } Complex; __global__ void work(int *id, int tb_x, int tb_y, int gr_x, ...
4,832
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* File: wtime.c */ /* Description: a timer that reports the current wall time */ /* */ ...
4,833
#include <cstdio> #include <cuda_runtime.h> #include "print_kernel.cuh" __global__ void cudaKernelFunc() { int index = threadIdx.x + blockIdx.x * blockDim.x; printf("Index: %d; thread: %d; block: %d; blockDim: %d\n", index, threadIdx.x, blockIdx.x, blockDim.x); } void cudaCallKernel() { cudaKernelFunc<<<10,...
4,834
#pragma once #include <stdio.h> #include <time.h> //#include <helper_cuda.h> #define MAX_LEVELS 300 int getSPcores(cudaDeviceProp devProp) { int cores = 0; int mp = devProp.multiProcessorCount; switch (devProp.major){ case 2: // Fermi if (devProp.minor == 1) cores = mp * 48; else cores...
4,835
#include <iostream> #include <cuda.h> #include <cstdio> #include "scan_kernels.cuh" using namespace std; int main() { // params: int size = 1024*1024; // allocate host: int *data_host = NULL; data_host = new int[size]; // allocate device: int *data_device = NULL; cudaMalloc((void**) &data_device, size *...
4,836
#include <iostream> #include "cuda_runtime.h" #include "device_launch_parameters.h" using namespace std; __global__ void kernel(int *a, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < n) { a[idx] *= 3; } } int main() { cout << "main() begin" << endl; int N = 100000; int size = N * sizeof(...
4,837
#include <stdio.h> #include <cuda.h> // Kernel wykonywane na "CUDA device" __host__ __device__ float f(float x){ return exp(x*x)*cos(x); } __global__ void oblicz_fx(float h, float a, float *w) { // rozmiar bloku równy 64 __shared__ float y[64]; int i = blockIdx.x * blockDim.x + threadIdx.x; y[thr...
4,838
#include <iostream> #include <cstdlib> #include <cassert> #include <zlib.h> #include <png.h> #define MASK_N 2 #define MASK_X 5 #define MASK_Y 5 #define SCALE 8 unsigned char *host_s = NULL; // source image array unsigned char *host_t = NULL; // target image array FILE *fp_s = NULL; // sou...
4,839
#include<stdio.h> const int MATRIX_WIDTH = 400; const int MATRIX_BYTES = MATRIX_WIDTH * MATRIX_WIDTH * sizeof(float); const int MAX_NO_THREADS = 512; __global__ void matrix_add(float *d_in1, float *d_in2, float *d_out){ int index = threadIdx.x + blockIdx.x*blockDim.x ; *(d_out+index) = *(d_in1+index) + *(d_in...
4,840
/* This code will multiply two vectors and check the result. */ #include <cuda.h> #include <iostream> /* Fill in your dotProduct kernel here... */ #define THREADS_PER_BLOCK 256 __device__ float result; __global__ void calcDotProductKern(float *x, float *y, int N) { __shared__ float product[THREADS_PER_BLOCK]; ...
4,841
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #define N 1000 #define BLOCK_SIZE 10 __global__ void scaMult_g (int *a, int *b, int *c, int *sum, int n) { int tid = threadIdx.x; if (tid > n- 1) return; { c[tid] = a[tid] * b[tid]; atomicAdd(sum, c[tid]); } } int main() { ...
4,842
#include <iostream> #include <cuda.h> #include <random> #define N 4096 #define THREAD 256 #define BLOCK 18 #define HANDLE_ERROR(x) checkCudaError(x, __LINE__) void checkCudaError(cudaError_t msg, int x) { if (msg != cudaSuccess) { fprintf(stderr, "line: %d %s\n", x, cudaGetErrorString(msg)); exit(1); } ...
4,843
// Copyright (c) 2015 Patrick Diehl // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) extern "C" __global__ void logn(size_t* count, float* in, float* out) { for (int i = blockDim.x * blockIdx.x + thread...
4,844
#include "includes.h" /* Start Header ***************************************************************** / /*! \file knn-kernel.cu \author Koh Wen Lin \brief Contains the implementation for kmeans clustering on the gpu. */ /* End Header *******************************************************************/ #define KMEAN_B...
4,845
extern "C" __global__ void setValue_kernel(int *vals) { int N = 1e6; int idx = blockIdx.x * blockDim.x + threadIdx.x; if(idx < N) vals[idx] = idx; }
4,846
#include <stdio.h> #include <stdlib.h> const int N = 2048; __global__ void add(const float *a, float *c, int n){ int idx = threadIdx.x + blockIdx.x*blockDim.x; if (idx < n) c[idx]=a[idx]; } int main(){ float *h_a, *h_c, *d_a, *d_c; const size_t ds = N*sizeof(float); h_a = (float *)mallo...
4,847
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #include <cuda.h> #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(stder...
4,848
#include <iostream> #include <cuda.h> #include <cuda_runtime.h> using namespace std; /// With k20m and k40m GPUs banks are organized in sets of 8 bytes, /// for this reason, conflicts happen when accesses to doubles fall on the /// same bank __global__ void MyKernelHomogeneos(unsigned long long * time) { const u...
4,849
#include "includes.h" __global__ void kernel_vec_equals_vec1_plus_alpha_times_vec2(double *vec, double *vec1, double alpha, double *d_a1, double *vec2, int numElements) { int iam = threadIdx.x; int bid = blockIdx.x; int threads_in_block = blockDim.x; int gid = bid*threads_in_block + iam; if (...
4,850
#include <stdio.h> #include <cuda.h> #include <stdlib.h> #include <time.h> #ifndef Size #define Size 1000 #endif #define b 4 void metric_mul_gold(int A[Size][Size], int B[Size][Size], int C[Size][Size]) { int i,j,k; for(i=0; i<Size; i++) for(j=0; j<Size; j++) for(k=0; k<Size; k++) C[i][j] += A[i][k]*B[...
4,851
/* * */ #include <stdio.h> #include <time.h> #include <cuda_runtime.h> #include <cassert> #include <cstdlib> #include <functional> #include <iostream> #include <algorithm> #include <vector> using std::cout; using std::generate; using std::vector; #define CUDA_CALL(x) do { if((x)!=cudaSuccess) { \ printf("Err...
4,852
#include "GpuUtils.cuh" #include "GpuFocalProcessing.cuh" #include "GpuProjectionProcessing.cuh" #include "GpuTimer.cuh" #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void addKernelGpu(double* res, const double* a, const double* b) { int i = threadIdx.x; res[i] = a[i] ...
4,853
#include <cstdio> #include <cstdlib> #include <cmath> #include <cuda_runtime_api.h> #define BASE_TYPE float #define BLOCK_SIZE 10 __global__ void mult(const BASE_TYPE *A, const BASE_TYPE *B, BASE_TYPE *C, const int N, const int M) { int aBegin = N * blockDim.y * blockIdx.y; int aEnd = aBegin + N - 1; int ...
4,854
#include "includes.h" __global__ void get_mi(int nbins, int nsamples, int nx, float * x_bin_scores, int pitch_x_bin_scores, float * entropies_x, int ny, float * y_bin_scores, int pitch_y_bin_scores, float * entropies_y, float * mis, int pitch_mis) { int col_x = blockDim.x * blockIdx.x + threadIdx.x, col_y = blockDim.y ...
4,855
/******************************************************************************* This program uses two libraries from the CUDA toolkit "cuFFT" and "cuRand" executeCudaRNG() routine generates a normally distributed random number arrays executeCudaFFT() routine gives an example on how to use the cuFFT library to get t...
4,856
#include <stdlib.h> #include <stdio.h> __global__ void mallocTest() { size_t size = 123; char* ptr = (char*)malloc(size); memset(ptr, 0, size); ptr[0] = 9; printf("Thread %d got pointer: %p: %d\n", threadIdx.x, ptr, ptr[0]); free(ptr); } // int main() // { // // Set a heap size of 128 mega...
4,857
/* Sequencial real 1m11.421s user 1m10.983s sys 0m0.232s Paralelo real 0m40.724s user 2m33.424s sys 0m3.183s Paralelo - GPU - OpenMP real 0m4.863s user 0m3.624s sys 0m1.211s Paralelo - GPU - CUDA real 0m0.442s user 0m0.174s sys 0m0.264s =======================================...
4,858
/* 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,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 var...
4,859
#include "includes.h" __global__ void convdw_gpu_kernel(float *dw, float *dy, float *x, const int S,const int outSize, const int inSize){ int row = blockIdx.y*blockDim.y+threadIdx.y; int col = blockIdx.x*blockDim.x+threadIdx.x; if(row < inSize && col < outSize){ // printf("row %d, col %d, bias[col] %.2f\n", row, col,b...
4,860
/* This file is part of the Marching Cubes GPU based algorithm based on * Paul Bourke's tabulation approach to marching cubes * http://paulbourke.net/geometry/polygonise/ * * * We model cubes with 8 vertices labelled as below * * * 4--------(4)---------5 * /| /| * ...
4,861
// On Maverick2: sbatch mvk2GPUMatMul // nvcc BrodayWalker1B.cu -o BrodayWalker1B.exe //*************************************************************************** // Name: Broday Walker // Instructor: Dr. Colmenares // Class: CMPS 5433 // Date: March 2, 2020 //*****************************************************...
4,862
#include "includes.h" __global__ void sumArrays(float *A, float *B, float *C, const int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < N) { for (int i = 0; i < N; ++i) { C[idx] = A[idx] + B[idx]; } } }
4,863
/*************************************************************************** *cr *cr (C) Copyright 2007 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr ********************************************************************...
4,864
#include <chrono> #include <cuda.h> #include <cuda_runtime_api.h> #include <iostream> #include <string.h> #include <string> #include <vector> #include <fstream> long avgTime(std::vector<long> times) { long long total = 0; for (double t : times) { total += t; } return total / times.size(); } std::vector<in...
4,865
#include <stdio.h> #include <iostream> #include <vector> #include <time.h> #include <math.h> #define CUDA_CHECK(condition) \ /* Code block avoids redefinition of cudaError_t error */ \ do { \ cudaError_t error = condition; \ if (error != cudaSuccess) { \ std::cout << cudaGetErrorString(error) << std:...
4,866
#include "includes.h" __global__ void mini1(int *a,int *b,int n) { int block=256*blockIdx.x; int mini=7888888; for(int i=block;i<min(256+block,n);i++) { if(mini>a[i]) { mini=a[i]; } } b[blockIdx.x]=mini; }
4,867
#include <iostream> #include <fstream> #include <string.h> #include <sys/time.h> #include <math.h> // CUDA runtime //#include <cuda_runtime.h> // helper functions and utilities to work with CUDA //#include <helper_functions.h> //#include <helper_cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> ...
4,868
/** * * Matrix Multiplication - CUDA for GPUs * * CS3210 * **/ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <assert.h> #include <math.h> int size, paddedSize; #define BLOCKSIZE 32 typedef struct { float ** element; } matrix; long long wall_clock_time() { #ifdef __li...
4,869
#include <stdio.h> __global__ void rev(char *a,int *len) { int id=threadIdx.x; int val=a[id]; int k=1; int sum=0; while(val>0) { int rem=val%2; rem*=k; k*=10; val/=2; sum+=rem; } printf("%c\t%d\n",a[id],sum); } int main() { char a[20]; int *d_m; char *d_a; printf("Enter String:"); scanf("%s",a...
4,870
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <arpa/inet.h> #include <math.h> #include "cs_dbg.h" #include "cs_cuda.h" #include "cs_helper.h" #include "cs_perm_selection.h" // #define CUDA_DBG // #define CUDA_DBG1 ...
4,871
#include "device_launch_parameters.h" #include <iostream> #include <string> int main() { int device_count; cudaGetDeviceCount(&device_count); for (int i = 0; i < device_count; i++) { //cuda存放设备信息的结构体 cudaDeviceProp device_prop; cudaGetDeviceProperties(&device_prop, i); std:...
4,872
#include <stdio.h> #include <math.h> __global__ void VecAdd(int n, const float *A, const float *B, float* C) { /******************************************************************** * * Compute C = A + B * where A is a (1 * n) vector * where B is a (1 * n) vector * where C is a (1 * ...
4,873
#include <assert.h> #include <stdio.h> #include <stdio.h> #include <cuda.h> __global__ void matrix_multipy(float *M, float *I, float *R, int w){ int x = threadIdx.x; int y = threadIdx.y; float Rvalue = 0; for(int i = 0; i< w;i++){ Rvalue += M[y*w + i] * I[i*w + x]; } R[y*w + x] = Rvalue; } int main(void) { ...
4,874
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <math.h> typedef unsigned long ulint; typedef unsigned long long ulint64; int banyakdata = 1024; int dimensigrid = 8; int dimensiblok = 128; void modexp(ulint a, ulint...
4,875
#include "cuda_runtime.h" #include <stdio.h> __global__ void kernel(void) { } int main(void) { kernel<<<1,1>>> (); printf("Hello Cuda!\n"); return 0; }
4,876
#include <cuComplex.h> #include <cuda.h> #include <cuda_runtime.h> __global__ void multiply_kernel_ccc(cuFloatComplex *in1, cuFloatComplex *in2, cuFloatComplex *out, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { float re, im; re = in1[i].x * in2[i]...
4,877
#include <cstdio> #define N 200 __global__ void add(int* a, int* b, int* c) { int idx = threadIdx.x + blockIdx.x*blockDim.x; if (idx < N) { c[idx] = a[idx] + b[idx]; } } int main() { int a[N], b[N], c[N]; int *dev_a, *dev_b, *dev_c; for (int i = 0; i < N; i++) { a[i]...
4,878
#include "includes.h" __global__ void Thumbnail_uchar(cudaTextureObject_t uchar_tex, int *histogram, int src_width, int src_height) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if (y < src_height && x < src_width) { unsigned char pixel = tex2D<unsigned char>(uchar_tex,...
4,879
#include <cuda_runtime.h> #include <stdio.h> #define CHECK(call) \ { \ const cudaError_t error = call; \ if (error != cudaSuccess) ...
4,880
#include "includes.h" __global__ void backward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride_x, int stride_y, int size, int pad, float *delta, float *prev_delta, int *indexes) { int h = (in_h + pad - size) / stride_y + 1; int w = (in_w + pad - size) / stride_x + 1; int c = in_c; int area_x = (siz...
4,881
#include "CudaProcess.cuh" #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> using namespace std; __global__ void kernel(int* pSrc1, int* pSrc2, int* pResult, int length) { int idx = blockDim.x * blockIdx.x + threadIdx.x; if (idx >= length) { return; } pResult[idx] = pSrc1[id...
4,882
#include <stdio.h> #include <stdlib.h> #include <cublas.h> #include <math.h> #include "cudamat_kernels.cuh" #include "cudamat.cuh" extern "C" { /* ------------------------------ CUBLAS init/shutdown ------------------------------ */ inline bool check_cublas_error() { cublasStatus status = cublasGetError(); r...
4,883
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include <cuda_runtime.h> //#include <cutil_inline.h> using namespace std; #define SUBMATRIX_SIZE 10000 #define NUM_BIN 500 #define HIST_MIN 0.0 #define HIST_MAX 3.5 //////////////////////////////////////////////////////////////////////// __g...
4,884
#include "pq.cuh" #include <stdlib.h> #include <stdio.h> #include <string.h> //typedef struct pqueue { // int max_size; // int num_elems; // int* elems; // kdtree indicies // double* dists; // distances from kdtree point to query point //} pqueue; // has_left_child(pqueue* q, int index) { return index*2 + 1 < q->num...
4,885
// Inspired from // https://developer.nvidia.com/thrust #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <cstdlib> #include <iostream> int main(void) { // generate 32M random numbers on the host thrust::host_vec...
4,886
#include "includes.h" extern "C" { } __global__ void vsquare(const double *a, double *c) { int i = threadIdx.x + blockIdx.x * blockDim.x; c[i] = a[i] * a[i]; }
4,887
// GPU kernel __global__ void summation_kernel(int data_size, float * data_out) { // Get the id of this thread in the whole thread group unsigned int id = blockIdx.x * blockDim.x + threadIdx.x; // Get the total number of threads in the whole thread group unsigned int nb_threads_total = blockDim.x * gridDim.x; /...
4,888
#include <cstdio> int main() { //host-side const int WIDTH = 5; int a[WIDTH][WIDTH]; int b[WIDTH][WIDTH]; int c[WIDTH][WIDTH] = {0}; //make a,b matrices for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < WIDTH; y++) { a[x][y] = x * 10 + y; b[x][y] = (x * 10 + x) * 100; c[x][y] = a[x][y] + b[x][y]...
4,889
#include <iostream> #include <math.h> #include <time.h> #include <stdlib.h> #include <random> #include <vector> #include <chrono> #include <deque> #include <algorithm> #include <iterator> #define BLOCK_SIZE 32 __global__ void swap(int *arr, const int skip, const int oflag, const int order, const int n) { int i = ...
4,890
#include "includes.h" float *A,*L,*U,*input; void arrayInit(int n); void verifyLU(int n); void updateLU(int n); void freemem(int n); /* */ __global__ void reduce( float *a, int size, int c) { int tid = blockIdx.x; //Handle the data at the index int thid = threadIdx.x; int index=c,j=0;//size=b int numthreads = block...
4,891
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <cuda.h> #include <curand_kernel.h> #define IL_BLOKOW 256 #define IL_WATKOW 256 #define IL_WEWN_TESTOW 1024 #define PI 3.14159265358979323846 // przyblizenie liczby pi do 20 miejsc po przecinku // Cudowna wersja metody Monte Carlo __...
4,892
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> __global__ void flops( float* floats , int n , int m ) { int idx = threadIdx.x + blockIdx.x * blockDim.x ; if( idx >= m ) return ; float temp = 3.14159 * idx ; int i ; for( i = 0 ; i < n ; i++ ) temp = temp + temp/2.0 ; f...
4,893
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <math.h> #include <cuda.h> #define COMMENT "Histogram_GPU" #define RGB_COMPONENT_COLOR 255 //Tamanhos dos blocos das threads #define BLOCK_SIZE 32 typedef struct { unsigned char red, green, blue; } PPMPixel; typedef struct { int x, y; PPMPixel...
4,894
#include<stdio.h> #include<stdlib.h> #include<sys/time.h> #include<math.h> #define NUM 10000000 #define CUDA_ERROR_EXIT(str) do{\ cudaError err = cudaGetLastError();\ if( err != cudaSuccess){\ printf("Cu...
4,895
#include <cuda.h> #include <cuda_runtime_api.h> #include <iostream> #include <time.h> #define TILE_SIZE 4 #define WINDOW_SIZE (3) template<class IMG_TYPE> __global__ void kernelMedian( const IMG_TYPE * __restrict__ in, IMG_TYPE *output, int j_dim, int pitch) { int row = blockIdx.y * blockDim.y + threadIdx.y; int co...
4,896
#include <stdio.h> #include <time.h> #define MWIDTH 4096 #define MTILE 16 #define BWIDTH 16 __global__ void gpu_matrixMul(int *a, int *b, int *c, int Width, int tile_width){ int start_row = (blockDim.y*blockIdx.y + threadIdx.y)*tile_width; int end_row = start_row + tile_width; int start_col = (blockDim.x*blockI...
4,897
void is_a_thrust_bug(); int main(int argc, char** argv) { is_a_thrust_bug(); return 0; }
4,898
#include <stdio.h> __global__ void square( int *d_num_steps, unsigned long long *d_fact, double *d_out){ int idx = threadIdx.x; int num_steps = *d_num_steps; for(int k=idx+1; k< num_steps; k+=blockDim.x){ d_out[idx] += (double) k*0.5/ (double) d_fact[k-1]; } } int main(int argc, char ** argv){ int h_nu...
4,899
#include <stdio.h> __global__ void VecAdd(int* ret, int a, int b) { ret[threadIdx.x] = a + b + threadIdx.x; } int main(void) { int a = 10; int b = 100; int* ret = NULL; // results of addition cudaMallocManaged(&ret, 1000 * sizeof(int)); VecAdd<<< 1...
4,900
#include "includes.h" // Hello Cuda World Program // /* * Author: Malhar Bhatt * Subject : High Performance Computing * */ /** * Empty Function named Kernel() qualified with __global__ * */ __global__ void kernel (void) { }