serial_no
int64
1
24.2k
cuda_source
stringlengths
11
9.01M
9,901
#include "includes.h" /// ================================================================ /// /// Disclaimer: IMPORTANT: This software was developed at theNT /// National Institute of Standards and Technology by employees of the /// Federal Government in the course of their official duties. /// Pursuant to title 17 Section 105 of the United States Code this /// software is not subject to copyright protection and is in the /// public domain. This is an experimental system. NIST assumes no /// responsibility whatsoever for its use by other parties, and makes /// no guarantees, expressed or implied, about its quality, /// reliability, or any other characteristic. We would appreciate /// acknowledgement if the software is used. This software can be /// redistributed and/or modified freely provided that any derivative /// works bear some notice that they are derived from it, and any /// modified versions bear some notice that they have been modified. /// /// ================================================================ // ================================================================ // // Author: Timothy Blattner // Date: Wed Nov 30 12:36:40 2011 EScufftDoubleComplex // // Functions that execute on the graphics card for doing // Vector computation. // // ================================================================ #define THREADS_PER_BLOCK 256 #define MIN_DISTANCE 1.0 // ================================================================ __device__ bool checkDistance(volatile int *maxesRow, volatile int *maxesCol, int nMax, int curIdx, int width) { int row = curIdx / width; int col = curIdx % width; int j; //double dist; for (j = 0; j < nMax; j++) { if (maxesRow[j] == row && maxesCol[j] == col) return false; // dist = distance(maxesRow[j], row, maxesCol[j], col); // if (dist < MIN_DISTANCE) // return false; } return true; } __device__ bool checkDistance(int *maxesRow, int *maxesCol, int nMax, int curIdx, int width) { int row = curIdx / width; int col = curIdx % width; int j; //double dist; for (j = 0; j < nMax; j++) { if (maxesRow[j] == row && maxesCol[j] == col) return false; //dist = distance(maxesRow[j], row, maxesCol[j], col); //if (dist < MIN_DISTANCE) // return false; } return true; } __device__ double distance(int x1, int x2, int y1, int y2) { return ((double(x1-x2))*(double(x1-x2)))+ ((double(y1-y2))*(double(y1-y2))); } __global__ void reduce_max_filter_main(double *g_idata, double *g_odata, int * max_idx, unsigned int width, unsigned int height, int blockSize, int *maxes, int nMax) { __shared__ int smaxesRow[10]; __shared__ int smaxesCol[10]; __shared__ int smaxesVal[10]; __shared__ double sdata[THREADS_PER_BLOCK]; __shared__ int idxData[THREADS_PER_BLOCK]; unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x*(blockSize) + tid; unsigned int gridSize = blockSize*gridDim.x; if (tid < nMax) { smaxesVal[tid] = maxes[tid]; smaxesRow[tid] = smaxesVal[tid] / width; smaxesCol[tid] = smaxesVal[tid] % width; } __syncthreads(); double myMax = -INFINITY; int myMaxIndex; double val; while (i < width * height) { val = g_idata[i]; if (myMax < val) { // compute distance . . . if (checkDistance(smaxesRow, smaxesCol, nMax, i, width)) { myMax = val; myMaxIndex = i; } } if (i+blockSize < width * height) { val = g_idata[i+blockSize]; if (myMax < val) { if (checkDistance(smaxesRow, smaxesCol, nMax, i+blockSize, width)) { myMax = val; myMaxIndex = i+blockSize; } } } i += gridSize; } sdata[tid] = myMax; idxData[tid] = myMaxIndex; __syncthreads(); if (blockSize >= 512) { if (tid < 256) { if (myMax < sdata[tid + 256]) { if (checkDistance(smaxesRow, smaxesCol, nMax, idxData[tid+256], width)) { sdata[tid] = myMax = sdata[tid+256]; idxData[tid] = idxData[tid+256]; } } } __syncthreads(); } if (blockSize >= 256) { if (tid < 128) { if (myMax < sdata[tid + 128]) { if (checkDistance(smaxesRow, smaxesCol, nMax, idxData[tid+128], width)) { sdata[tid] = myMax = sdata[tid+128]; idxData[tid] = idxData[tid+128]; } } } __syncthreads(); } if (blockSize >= 128) { if (tid < 64) { if(myMax < sdata[tid + 64]) { if (checkDistance(smaxesRow, smaxesCol, nMax, idxData[tid+64], width)) { sdata[tid] = myMax = sdata[tid+64]; idxData[tid] = idxData[tid+64]; } } } __syncthreads(); } volatile double *vdata = sdata; volatile int *vidxData = idxData; volatile int *vsmaxesRow = smaxesRow; volatile int *vsmaxesCol = smaxesCol; if (tid < 32) { if (blockSize >= 64) if (myMax < vdata[tid + 32]) { if (checkDistance(vsmaxesRow, vsmaxesCol, nMax, vidxData[tid+32], width)) { vdata[tid] = myMax = vdata[tid+32]; vidxData[tid] = vidxData[tid+32]; } } if (blockSize >= 32) if (myMax < vdata[tid + 16]) { if (checkDistance(vsmaxesRow, vsmaxesCol, nMax, vidxData[tid+16], width)) { vdata[tid] = myMax = vdata[tid+16]; vidxData[tid] = vidxData[tid+16]; } } if (blockSize >= 16) if (myMax < vdata[tid + 8]) { if (checkDistance(vsmaxesRow, vsmaxesCol, nMax, vidxData[tid+8], width)) { vdata[tid] = myMax = vdata[tid+8]; vidxData[tid] = vidxData[tid+8]; } } if (blockSize >= 8) if (myMax < vdata[tid + 4]) { if (checkDistance(vsmaxesRow, vsmaxesCol, nMax, vidxData[tid+4], width)) { vdata[tid] = myMax = vdata[tid+4]; vidxData[tid] = vidxData[tid+4]; } } if (blockSize >= 4) if (myMax < vdata[tid+2]) { if (checkDistance(vsmaxesRow, vsmaxesCol, nMax, vidxData[tid+2], width)) { vdata[tid] = myMax = vdata[tid+2]; vidxData[tid] = vidxData[tid+2]; } } if (blockSize >= 2) if (myMax < vdata[tid + 1]) { if (checkDistance(vsmaxesRow, vsmaxesCol, nMax, vidxData[tid+1], width)) { vdata[tid] = myMax = vdata[tid+1]; vidxData[tid] = vidxData[tid+1]; } } __syncthreads(); } if (tid == 0) { g_odata[blockIdx.x] = sdata[0]; max_idx[blockIdx.x] = idxData[0]; if (gridDim.x == 1) maxes[nMax] = idxData[0]; } }
9,902
#include <stdio.h> #include <stdlib.h> void init(float *x, int s){ int i=0; for(i=0; i<s; i++){ x[i]=1.0f * (float)i; } } __global__ void compute(float *x, float *y, int s){ int i=0; for(i=0; i<s; i++){ y[i]= x[i]*x[i]; } } int main(){ int N = 1<<20; float *x;// = malloc(sizeof(float)*N); float *y;// = malloc(sizeof(float)*N); cudaMallocManaged(&x, sizeof(float)*N); cudaMallocManaged(&y, sizeof(float)*N); init(x, N); init(y, N); int i=0; compute<<<1,1>>>(x, y, N); cudaDeviceSynchronize(); for(i=0; i<N; i++){ printf("%d %f %f\n", i, x[i], y[i]); } }
9,903
/* Mary Barker Homework 2 Vector addition on GPU that allows for more than 1024 elements In particular, it can do 2 different parallel memory setups: (1) each element in the vector assigned a thread, and the number of blocks assigned accordingly, (2) 2 blocks, 1024 threads each, and the algorithm iterates until each element in the vector has been reached to compile: nvcc BarkerHW2.cu OUTPUTS: with more than 2 blocks: Time in milliseconds= 0.068000000000000 Last Values are A[4999] = 9998.000000000000000 B[4999] = 4999.000000000000000 C[4999] = 14997.000000000000000 with only 2 blocks: Time in milliseconds= 0.073000000000000 Last Values are A[4999] = 9998.000000000000000 B[4999] = 4999.000000000000000 C[4999] = 14997.000000000000000 */ #include <sys/time.h> #include <stdio.h> //Length of vectors to be added. #define N 5000 bool two_blocks = true; int num_iters; dim3 dimBlock, dimGrid; float *A_CPU, *B_CPU, *C_CPU; //CPU pointers float *A_GPU, *B_GPU, *C_GPU; //GPU pointers void SetupCudaDevices() { dimBlock.x = 1024; dimBlock.y = 1; dimBlock.z = 1; if (two_blocks) { dimGrid.x = 2; dimGrid.y = 1; dimGrid.z = 1; num_iters = (N - 1) / (dimGrid.x * dimBlock.x) + 1; } else { num_iters = 1; dimGrid.x = (N - 1) / dimBlock.x + 1; dimGrid.y = 1; dimGrid.z = 1; } } void AllocateMemory() { //Allocate Device (GPU) Memory, & allocates the value of the specific pointer/array cudaMalloc(&A_GPU,N*sizeof(float)); cudaMalloc(&B_GPU,N*sizeof(float)); cudaMalloc(&C_GPU,N*sizeof(float)); //Allocate Host (CPU) Memory A_CPU = (float*)malloc(N*sizeof(float)); B_CPU = (float*)malloc(N*sizeof(float)); C_CPU = (float*)malloc(N*sizeof(float)); } //Loads values into vectors that we will add. void Innitialize() { int i; for(i = 0; i < N; i++) { A_CPU[i] = (float)2*i; B_CPU[i] = (float)i; } } //Cleaning up memory after we are finished. void CleanUp(float *A_CPU,float *B_CPU,float *C_CPU,float *A_GPU,float *B_GPU,float *C_GPU) //free { free(A_CPU); free(B_CPU); free(C_CPU); cudaFree(A_GPU); cudaFree(B_GPU); cudaFree(C_GPU); } //This is the kernel. It is the function that will run on the GPU. //It adds vectors A and B then stores result in vector C __global__ void Addition(float *A, float *B, float *C, int n, int num_iterations_over_blocks) { int id; for(int i = 0; i < num_iterations_over_blocks; i++) { id = i * (blockDim.x * gridDim.x) + blockDim.x * blockIdx.x + threadIdx.x; if(id < n) C[id] = A[id] + B[id]; } } int main() { int i; timeval start, end; //setup parallel structure SetupCudaDevices(); //Partitioning off the memory that you will be using. AllocateMemory(); //Loading up values to be added. Innitialize(); //Starting the timer gettimeofday(&start, NULL); //Copy Memory from CPU to GPU cudaMemcpyAsync(A_GPU, A_CPU, N*sizeof(float), cudaMemcpyHostToDevice); cudaMemcpyAsync(B_GPU, B_CPU, N*sizeof(float), cudaMemcpyHostToDevice); //Calling the Kernel (GPU) function. Addition<<<dimGrid, dimBlock>>>(A_GPU, B_GPU, C_GPU, N, num_iters); //Copy Memory from GPU to CPU cudaMemcpyAsync(C_CPU, C_GPU, N*sizeof(float), cudaMemcpyDeviceToHost); //Stopping the timer gettimeofday(&end, NULL); //Calculating the total time used in the addition and converting it to milliseconds. float time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec); //Displaying the time printf("Time in milliseconds= %.15f\n", (time/1000.0)); // Displaying vector info you will want to comment out the vector print line when your //vector becomes big. This is just to make sure everything is running correctly. for(i = 0; i < N; i++) { //printf("A[%d] = %.15f B[%d] = %.15f C[%d] = %.15f\n", i, A_CPU[i], i, B_CPU[i], i, C_CPU[i]); } //Displaying the last value of the addition for a check when all vector display has been commented out. printf("Last Values are A[%d] = %.15f B[%d] = %.15f C[%d] = %.15f\n", N-1, A_CPU[N-1], N-1, B_CPU[N-1], N-1, C_CPU[N-1]); //You're done so cleanup your mess. CleanUp(A_CPU,B_CPU,C_CPU,A_GPU,B_GPU,C_GPU); return(0); }
9,904
#include <cuda.h> #define IDXV(x, y, ld) ((x) + (y) * (ld)) #define block 128 #define grid 256 __global__ static void pack_matrix(double* __restrict__ device_cube, double* __restrict__ tmp_matrix, const int n, const int index) { // for(int z=0; z<n; z++) // for(int x=0; x<n; x++) // tmp_matrix[z][x] = device_cube[z][index][x]; // tmp_matrix[z*n+x] = device_cube[z*n*n+index*n+x]; int ivx = IDXV(threadIdx.x, blockIdx.x, blockDim.x); while(ivx < n*n){ int z = ivx / n; int x = ivx - z * n; tmp_matrix[ivx] = device_cube[z*n*n+index*n+x]; ivx += blockDim.x * gridDim.x; } } __global__ static void unpack_matrix(double* __restrict__ tmp_matrix, double* __restrict__ device_cube, const int n, const int index) { // for(int z=0; z<n; z++) // for(int x=0; x<n; x++) // device_cube[z][index][x] = tmp_matrix[z][x]; // device_cube[z*n*n+index*n+x] = tmp_matrix[z*n+x]; int ivx = IDXV(threadIdx.x, blockIdx.x, blockDim.x); while(ivx < n*n){ int z = ivx / n; int x = ivx - z * n; device_cube[z*n*n+index*n+x] = tmp_matrix[ivx]; ivx += blockDim.x * gridDim.x; } } extern "C" void call_pack(double* __restrict__ device_cube, double* __restrict__ tmp_matrix, const int n, const int index) { pack_matrix <<< grid, block >>> (device_cube, tmp_matrix, n, index); cudaDeviceSynchronize(); } extern "C" void call_unpack(double* __restrict__ tmp_matrix, double* __restrict__ device_cube, const int n, const int index) { unpack_matrix <<< grid, block >>> (tmp_matrix, device_cube, n, index); cudaDeviceSynchronize(); }
9,905
__global__ void localMemoryDemo1( ) { unsigned int data[3]; } __global__ void localMemoryDemo2( ) { unsigned int data[3] = {1, 2, 3}; } __global__ void localMemoryDemo3( ) { unsigned int data1, data2, data3; }
9,906
#include "Cuda_XGraph.cuh" /////////////////////////////////////////////////////// template<class X> void CCudaXGraph<X>::Init() { }
9,907
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdlib.h> #include <iostream> #define N 32 #define THREADS_PER_BLOCK 16 // use N threads One block __global__ void dot_kernel(int *d_c, int *d_a, int *d_b) { // terminology: A block of threads shares memory called... shared memory // extremely fast, on-chip memory (user-managed memory) // and is declared with the CUDA __shared__ keyword // each thread computes a pairwaise product __shared__ int temp[N]; temp[threadIdx.x] = d_a[threadIdx.x] * d_b[threadIdx.x]; // * NEED THREADS TO SYNCHRONIZE HERE * // No thread can advance until all threads // have reached this point in the code // for avoid read-before-writing hazard __syncthreads(); // threads are synchronized within a block // thread 0 sum the pairwaise producs if (0 == threadIdx.x) { int sum = 0; for (int i = 0; i < N; i++) { sum += temp[i]; } *d_c = sum; *d_c = 3; } } // use N/THREADS_PER_BLOCK blocks and N threads // read this for undestand cuda capabilities https://stackoverflow.com/questions/4391162/cuda-determining-threads-per-block-blocks-per-grid // study more about achieved occupancy https://docs.nvidia.com/gameworks/content/developertools/desktop/analysis/report/cudaexperiments/kernellevel/achievedoccupancy.htm __global__ void multiblock_dot_kernel(int *r, int *a, int *b) { __shared__ int temp[THREADS_PER_BLOCK]; int index = threadIdx.x + blockIdx.x * blockDim.x; temp[index] = a[index] * b[index]; __syncthreads(); if (0 == threadIdx.x) { int sum = 0; for (int i = 0; i < THREADS_PER_BLOCK; i++) { // no problem here beacase threads were synchronized sum += temp[index]; } // ADD EACH BLOCK RESULT TO VALUE AT ADDRESS r // 1. read value at addres r (read) // 2. add sum to value (modify) // 3. write result to address r (write) //*r += sum; race condition no atomic operation atomicAdd(r, sum); // "read-modify-write" uninterrumpible when atomic } } void set_ints(int *arr, int const SIZE); void print_vectors(char *name, int *arr, int const SIZE); int main() { int *a, *b, c = 0; // host variables int *d_a, *d_b, *d_c; // device variables int size = N * sizeof(int); // for memory allocation // allocate host memory a = (int*)malloc(size); b = (int*)malloc(size); // init host memory set_ints(a, N); set_ints(b, N); // tell cuda what variables are for device (GPU) memory cudaMalloc((void**)&d_a, size); cudaMalloc((void**)&d_b, size); cudaMalloc((void**)&d_c, sizeof(int)); // init device memory cudaMemcpy(d_a, a, size, cudaMemcpyKind::cudaMemcpyHostToDevice); cudaMemcpy(d_b, b, size, cudaMemcpyKind::cudaMemcpyHostToDevice); // launch kernel //dot_kernel<<<1, N>>>(d_c, d_a, d_b); multiblock_dot_kernel<<<N/THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(d_c, d_a, d_b); // copy result from device to host cudaMemcpy(&c, d_c, sizeof(int), cudaMemcpyKind::cudaMemcpyDeviceToHost); print_vectors("a", a, N); print_vectors("b", b, N); std::cout << "\nResult: " << c << "\n\n"; system("pause"); free(a); free(b); cudaFree(d_a); cudaFree(d_b); cudaFree(d_c); return 0; } void print_vectors(char *name, int *arr, int const SIZE) { std::cout << name << ": "; for (int i = 0; i < N; i++) { std::cout << " " << arr[i]; } std::cout << "\n\n"; } void set_ints(int *arr, int const SIZE) { for (int i = 0; i < SIZE; i++) { arr[i] = 3; } }
9,908
#include <cstdio> using namespace std; __global__ void vector_addition(int *A, int *B, size_t n) { A[threadIdx.x] += B[threadIdx.x]; } int main() { const int n = 128; int A[n] = {0}; int B[n] = {0}; for (int i = 0; i < n; ++i) A[i] = i, B[i] = n - i; int *Ad, *Bd; cudaMalloc((void **)&Ad, sizeof(int)*n); cudaMalloc((void **)&Bd, sizeof(int)*n); cudaMemcpy(Ad, A, sizeof(int)*n, cudaMemcpyHostToDevice); cudaMemcpy(Bd, B, sizeof(int)*n, cudaMemcpyHostToDevice); vector_addition<<<1, n>>>(Ad, Bd, n); cudaMemcpy(A, Ad, sizeof(int)*n, cudaMemcpyDeviceToHost); for (int i = 0; i < n; ++i) printf("%2d ", A[i]); printf("\n"); cudaFree(Ad); cudaFree(Bd); return 0; }
9,909
#include <stdio.h> #define CUDA_CALL(...) \ do { \ cudaError_t err = __VA_ARGS__; \ if (err != cudaSuccess) \ { \ printf("CUDA ERROR: %s: %s\n", \ cudaGetErrorName(err), cudaGetErrorString(err)); \ return err; \ } \ } while (false) int main() { int selected_device; CUDA_CALL(cudaGetDevice(&selected_device)); cudaDeviceProp device_prop; CUDA_CALL(cudaGetDeviceProperties(&device_prop, selected_device)); FILE * output = fopen("sm", "w"); fprintf(output, "%d%d\n", device_prop.major, device_prop.minor); fclose(output); }
9,910
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> __global__ void add2(double *c, const double *a, const double *b) { c[0] = a[0] + b[0]; } int main(void) { double *a, *b, *c; float t; cudaEvent_t start, stop; cudaMalloc( (void **)&a, sizeof(double) ); cudaMalloc( (void **)&b, sizeof(double) ) ; cudaMalloc( (void **)&c, sizeof(double) ) ; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); add2<<<1,1>>>(c, a, b); cudaEventRecord(stop, 0); cudaEventSynchronize(stop); cudaEventElapsedTime(&t, start, stop); printf("cudaEventElapsedTime(%.6f)\n", t / 1000.0f); cudaFree(c); cudaFree(b); cudaFree(a); return 0; }
9,911
#include "includes.h" __global__ void computeCost(const double *Params, const float *uproj, const float *mu, const float *W, const int *ioff, const bool *iW, float *cmax){ int tid, bid, Nspikes, Nfeatures, NfeatW, Nthreads, k; float xsum = 0.0f, Ci, lam; Nspikes = (int) Params[0]; Nfeatures = (int) Params[1]; NfeatW = (int) Params[4]; Nthreads = blockDim.x; lam = (float) Params[5]; tid = threadIdx.x; bid = blockIdx.x; while(tid<Nspikes){ if (iW[tid + bid*Nspikes]){ xsum = 0.0f; for (k=0;k<Nfeatures;k++) xsum += uproj[k + Nfeatures * tid] * W[k + ioff[tid] + NfeatW * bid]; Ci = max(0.0f, xsum) + lam/mu[bid]; cmax[tid + bid*Nspikes] = Ci * Ci / (1.0f + lam/(mu[bid] * mu[bid])) - lam; } tid+= Nthreads; } }
9,912
#include <stdio.h> #include <stdint.h> #define CHECK(call) \ { \ const cudaError_t error = call; \ if (error != cudaSuccess) \ { \ fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__); \ fprintf(stderr, "code: %d, reason: %s\n", error, \ cudaGetErrorString(error)); \ exit(EXIT_FAILURE); \ } \ } struct GpuTimer { cudaEvent_t start; cudaEvent_t stop; GpuTimer() { cudaEventCreate(&start); cudaEventCreate(&stop); } ~GpuTimer() { cudaEventDestroy(start); cudaEventDestroy(stop); } void Start() { cudaEventRecord(start, 0); } void Stop() { cudaEventRecord(stop, 0); } float Elapsed() { float elapsed; cudaEventSynchronize(stop); cudaEventElapsedTime(&elapsed, start, stop); return elapsed; } }; void readPnm(char * fileName, int &width, int &height, uchar3 * &pixels) { FILE * f = fopen(fileName, "r"); if (f == NULL) { printf("Cannot read %s\n", fileName); exit(EXIT_FAILURE); } char type[3]; fscanf(f, "%s", type); if (strcmp(type, "P3") != 0) // In this exercise, we don't touch other types { fclose(f); printf("Cannot read %s\n", fileName); exit(EXIT_FAILURE); } fscanf(f, "%i", &width); fscanf(f, "%i", &height); int max_val; fscanf(f, "%i", &max_val); if (max_val > 255) // In this exercise, we assume 1 byte per value { fclose(f); printf("Cannot read %s\n", fileName); exit(EXIT_FAILURE); } pixels = (uchar3 *)malloc(width * height * sizeof(uchar3)); for (int i = 0; i < width * height; i++) fscanf(f, "%hhu%hhu%hhu", &pixels[i].x, &pixels[i].y, &pixels[i].z); fclose(f); } void writePnm(uchar3 * pixels, int width, int height, char * fileName) { FILE * f = fopen(fileName, "w"); if (f == NULL) { printf("Cannot write %s\n", fileName); exit(EXIT_FAILURE); } fprintf(f, "P3\n%i\n%i\n255\n", width, height); for (int i = 0; i < width * height; i++) fprintf(f, "%hhu\n%hhu\n%hhu\n", pixels[i].x, pixels[i].y, pixels[i].z); fclose(f); } __global__ void blurImgKernel(uchar3 * inPixels, int width, int height, float * filter, int filterWidth, uchar3 * outPixels) { // TODO int iy = blockDim.y*blockIdx.y + threadIdx.y; int ix = blockDim.x*blockIdx.x + threadIdx.x; int pos = iy* width + ix; if (ix < width && iy < height); { float x = 0; float y = 0; float z = 0; for (int h=0 ; h<filterWidth ; h++) { for (int w=0 ; w<filterWidth ; w++) { int imagex = ix - filterWidth/2 + w; int imagey = iy - filterWidth/2 + h; if (h*filterWidth + w < 0 || h*filterWidth + w >= filterWidth*filterWidth) printf("%d-",h*filterWidth + w); if ( 0 <= imagex && imagex < width && 0 <= imagey && imagey < height){ x += filter[h*filterWidth + w]*inPixels[imagey*width + imagex].x; y += filter[h*filterWidth + w]*inPixels[imagey*width + imagex].y; z += filter[h*filterWidth + w]* inPixels[imagey*width + imagex].z; } } } outPixels[pos].x = x; outPixels[pos].y = y; outPixels[pos].z = z; } } void blurImg(uchar3 * inPixels, int width, int height, float * filter, int filterWidth, uchar3 * outPixels, bool useDevice=false, dim3 blockSize=dim3(1, 1)) { GpuTimer timer; timer.Start(); if (useDevice == false) { // TODO for (int i=0 ; i<height ; i++) { for (int j=0 ; j<width ; j++) { float x = 0; float y = 0; float z = 0; for (int h=0 ; h<filterWidth ; h++) { for (int w=0 ; w<filterWidth ; w++) { if (i -filterWidth/2 + h >= 0 && i -filterWidth/2 + h < height && j -filterWidth/2 + w >= 0 && j -filterWidth/2 + w <width) { x += filter[h*filterWidth + w]*inPixels[(i-filterWidth/2 + h)*width + (j - filterWidth/2 + w)].x; y += filter[h*filterWidth + w]*inPixels[(i-filterWidth/2 + h)*width + (j - filterWidth/2 + w)].y; z += filter[h*filterWidth + w]*inPixels[(i-filterWidth/2 + h)*width + (j - filterWidth/2 + w)].z; } } } outPixels[i*width+j].x = x; outPixels[i*width+j].y = y; outPixels[i*width+j].z = z; } } } else // Use device { cudaDeviceProp devProp; cudaGetDeviceProperties(&devProp, 0); printf("GPU name: %s\n", devProp.name); printf("GPU compute capability: %d.%d\n", devProp.major, devProp.minor); // TODO uchar3 * d_inPixels, * d_outPixels; float *d_filter; CHECK(cudaMalloc(&d_inPixels, width*height*sizeof(uchar3))); CHECK(cudaMalloc(&d_outPixels, width*height*sizeof(uchar3))); CHECK(cudaMalloc(&d_filter, filterWidth*filterWidth*sizeof(float))); CHECK(cudaMemcpy(d_inPixels,inPixels,width*height*sizeof(uchar3),cudaMemcpyHostToDevice)); CHECK(cudaMemcpy(d_filter,filter,filterWidth*filterWidth*sizeof(float),cudaMemcpyHostToDevice)); dim3 gridSize((width-1)/blockSize.x +1,(height-1)/blockSize.y +1 ); blurImgKernel<<<gridSize,blockSize>>>(d_inPixels,width,height,d_filter,filterWidth,d_outPixels); cudaDeviceSynchronize(); CHECK(cudaGetLastError()); CHECK(cudaMemcpy(outPixels,d_outPixels,width*height*sizeof(uchar3),cudaMemcpyDeviceToHost)); cudaFree(d_outPixels); cudaFree(d_inPixels); cudaFree(d_filter); } timer.Stop(); float time = timer.Elapsed(); printf("Processing time (%s): %f ms\n", useDevice == true? "use device" : "use host", time); } float computeError(uchar3 * a1, uchar3 * a2, int n) { float err = 0; for (int i = 0; i < n; i++) { // printf() err += abs((int)a1[i].x - (int)a2[i].x); err += abs((int)a1[i].y - (int)a2[i].y); err += abs((int)a1[i].z - (int)a2[i].z); } err /= (n * 3); return err; } char * concatStr(const char * s1, const char * s2) { char * result = (char *)malloc(strlen(s1) + strlen(s2) + 1); strcpy(result, s1); strcat(result, s2); return result; } int main(int argc, char ** argv) { if (argc != 4 && argc != 6) { printf("The number of arguments is invalid\n"); return EXIT_FAILURE; } // Read input image file int width, height; uchar3 * inPixels; readPnm(argv[1], width, height, inPixels); printf("Image size (width x height): %i x %i\n\n", width, height); // Read correct output image file int correctWidth, correctHeight; uchar3 * correctOutPixels; readPnm(argv[3], correctWidth, correctHeight, correctOutPixels); if (correctWidth != width || correctHeight != height) { printf("The shape of the correct output image is invalid\n"); return EXIT_FAILURE; } // Set up a simple filter with blurring effect int filterWidth = 9; float * filter = (float *)malloc(filterWidth * filterWidth * sizeof(float)); for (int filterR = 0; filterR < filterWidth; filterR++) { for (int filterC = 0; filterC < filterWidth; filterC++) { filter[filterR * filterWidth + filterC] = 1. / (filterWidth*filterWidth); } } // Blur input image using host uchar3 * hostOutPixels = (uchar3 *)malloc(width * height * sizeof(uchar3)); blurImg(inPixels, width, height, filter, filterWidth, hostOutPixels); // Compute mean absolute error between host result and correct result float hostErr = computeError(hostOutPixels, correctOutPixels, width * height); printf("Error: %f\n\n", hostErr); // Blur input image using device uchar3 * deviceOutPixels = (uchar3 *)malloc(width * height * sizeof(uchar3)); dim3 blockSize(32, 32); // Default if (argc == 6) { blockSize.x = atoi(argv[4]); blockSize.y = atoi(argv[5]); } blurImg(inPixels, width, height, filter, filterWidth, deviceOutPixels, true, blockSize); // Compute mean absolute error between device result and correct result float deviceErr = computeError(deviceOutPixels, correctOutPixels, width * height); printf("Error: %f\n\n", deviceErr); // Write results to files char * outFileNameBase = strtok(argv[2], "."); // Get rid of extension writePnm(hostOutPixels, width, height, concatStr(outFileNameBase, "_host.pnm")); writePnm(deviceOutPixels, width, height, concatStr(outFileNameBase, "_device.pnm")); // Free memories free(inPixels); free(correctOutPixels); free(hostOutPixels); free(deviceOutPixels); free(filter); }
9,913
#include <iostream> #include <cmath> #define CUDA_CHECK_RETURN(value) {\ cudaError_t _m_cudaStat = value;\ if (_m_cudaStat != cudaSuccess) {\ fprintf(stderr, "Error %s at line %d in file %s\n", cudaGetErrorString(_m_cudaStat), __LINE__, __FILE__);\ exit(1);\ }\ } __global__ void vectors_add(float arr1[], float arr2[]) { arr1[threadIdx.x + blockDim.x * blockIdx.x] += arr2[threadIdx.x + blockDim.x * blockIdx.x]; } int main(int argc, char *argv[]) { float *arr1, *arr2, *res, *devarr1, *devarr2; for (int threads_per_block = 1; threads_per_block <= 1024; threads_per_block *= 2) { std::cout << "threads per block:" << threads_per_block << std::endl; for (int N = pow(2, 28), i = 0; i < 19; N /= 2, i++) { int num_of_blocks = N / threads_per_block; arr1 = new float[N]; arr2 = new float[N]; res = new float[N]; for (int i = 0; i < N; i++) { arr1[i] = (float) rand() / RAND_MAX; arr2[i] = (float) rand() / RAND_MAX; } CUDA_CHECK_RETURN(cudaMalloc((void **) &devarr1, N * sizeof(float))); CUDA_CHECK_RETURN(cudaMalloc((void **) &devarr2, N * sizeof(float))); CUDA_CHECK_RETURN(cudaMemcpy(devarr1, arr1, N * sizeof(float), cudaMemcpyHostToDevice)); CUDA_CHECK_RETURN(cudaMemcpy(devarr2, arr2, N * sizeof(float), cudaMemcpyHostToDevice)); cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); vectors_add<<<dim3(num_of_blocks), dim3(threads_per_block)>>>(devarr1, devarr2); cudaEventRecord(stop, 0); cudaEventSynchronize(stop); CUDA_CHECK_RETURN(cudaGetLastError()); float elapsedTime; cudaEventElapsedTime(&elapsedTime, start, stop); std::cout << static_cast<int>(elapsedTime * 1000) << std::endl; CUDA_CHECK_RETURN(cudaMemcpy(res, devarr1, N * sizeof(float), cudaMemcpyDeviceToHost)); //for(int i = 0; i < 100; i++) // std::cout << res[i] << '\n'; for (int i = 0; i < N; i++) { if (res[i] != arr1[i] + arr2[i]) { std::cout << "Error" << std::endl; return 0; } } CUDA_CHECK_RETURN(cudaFree(devarr1)); CUDA_CHECK_RETURN(cudaFree(devarr2)); delete[] arr1; delete[] arr2; delete[] res; } } }
9,914
#include <stdio.h> #define TILE_WIDTH 16 //calculate similarity matrix using global memory __global__ void calculateSimilarityMatrixGlobal(float *M,float *P,int width,int height,float *avgArray,float *norm_val) { //thread indices and block indices int tx = threadIdx.x; int ty = threadIdx.y; int bx = blockIdx.x; int by = blockIdx.y; //row and column indices of element of P being calculated int row = by * blockDim.y + ty; int column = bx * blockDim.x + tx; float val = 0.0; float num,denom; for(int i=0;i<width;i++) { if(row<height && column<height && M[row*width+i]>0.0f && M[column*width+i]>0.0f) val += (M[row*width+i]-avgArray[row])*(M[column*width+i]-avgArray[column]); } if(row<height && column<height && norm_val[row]>0.0f && norm_val[column]>0.0f) denom = (float)sqrt(norm_val[row])*sqrt(norm_val[column]); if(row<height && column< height) { if(denom>0.0f) P[row*height+column] = val/denom; else P[row*height+column] = 0.0f; } } // Matrix multiplication kernel thread specification __global__ void calculateSimilarityMatrixNoTranspose(float *M,float *N,float *P,int width, int height,float *avgArray, float* norm_val) { //variables declared in shared memory __shared__ float Ms[TILE_WIDTH][TILE_WIDTH]; __shared__ float Ns[TILE_WIDTH][TILE_WIDTH]; //thread indices and block indices int tx = threadIdx.x; int ty = threadIdx.y; int bx = blockIdx.x; int by = blockIdx.y; //row and column indices of element of P being calculated int row = by * TILE_WIDTH + ty; int column = bx * TILE_WIDTH + tx; float p_Val = 0; float numer, denom; // compute target element value for(int i=0;i<ceilf(width/(float)TILE_WIDTH);i++){ if(row < height && (i*TILE_WIDTH + tx)<width) Ms[ty][tx] = M[row*width + i*TILE_WIDTH + tx]; else Ms[ty][tx] = 0.0; //if(i*TILE_WIDTH+threadIdx.y <height && column<width) // Ns[threadIdx.y][threadIdx.x] = N[(i*TILE_WIDTH+threadIdx.y)*width+column]; //else // Ns[threadIdx.y][threadIdx.x] = 0.0; //ensure that all values of the tile is available __syncthreads(); for(int j=0;j<TILE_WIDTH;j++){ if(row < height && column < height && Ms[ty][j] > 0.0f && Ns[j][tx] > 0.0f){ p_Val += (Ms[ty][j]-avgArray[row]) * (Ns[j][tx]-avgArray[column]); //p_Val += (Ms[ty][j]) * (Ms[tx][j]); } } __syncthreads(); if(column < height && row < height && norm_val[row] > 0.0f && norm_val[column] > 0.0f){ denom = (float) sqrt(norm_val[row]) * sqrt(norm_val[column]); } //ensure that all values of the tile are used __syncthreads(); } //check the boundary condition if(row < height && column < height) { if(denom>0.0f) P[row*height+column] = p_Val/denom; else P[row*height+column] = 0.0f; } } // Matrix multiplication kernel thread specification __global__ void calculateSimilarityMatrix(float *M,float *N,float *P,int width, int height,float *avgArray, float* norm_val) { //variables declared in shared memory __shared__ float Ms[TILE_WIDTH][TILE_WIDTH]; __shared__ float Ns[TILE_WIDTH][TILE_WIDTH]; //thread indices and block indices int tx = threadIdx.x; int ty = threadIdx.y; int bx = blockIdx.x; int by = blockIdx.y; //row and column indices of element of P being calculated int row = by * TILE_WIDTH + ty; int column = bx * TILE_WIDTH + tx; float p_Val = 0; float numer, denom; // compute target element value for(int i=0;i<ceilf(width/(float)TILE_WIDTH);i++){ if(row < height && (i*TILE_WIDTH + tx)<width) Ms[ty][tx] = M[row*width + i*TILE_WIDTH + tx]; else Ms[ty][tx] = 0.0; if(i*TILE_WIDTH+threadIdx.y <width && column<height) Ns[threadIdx.y][threadIdx.x] = N[(i*TILE_WIDTH+threadIdx.y)*height+column]; else Ns[threadIdx.y][threadIdx.x] = 0.0; //ensure that all values of the tile is available __syncthreads(); for(int j=0;j<TILE_WIDTH;j++){ if(row < height && column < height && Ms[ty][j] > 0.0f && Ns[j][tx] > 0.0f){ p_Val += (Ms[ty][j]-avgArray[row]) * (Ns[j][tx]-avgArray[column]); //p_Val += (Ms[ty][j]) * (Ms[tx][j]); } } __syncthreads(); if(column < height && row < height && norm_val[row] > 0.0f && norm_val[column] > 0.0f){ denom = (float) sqrt(norm_val[row]) * sqrt(norm_val[column]); } //ensure that all values of the tile are used __syncthreads(); } //check the boundary condition if(row < height && column < height) { if(denom>0.0f) P[row*height+column] = p_Val/denom; else P[row*height+column] = 0.0f; } }
9,915
// test2.cu // Author: Nick Ulle #include <stdio.h> #include <math.h> #include <curand_kernel.h> #define MAX_ITER 100 __device__ float tail_normal( float mean, float sd, float a, curandState_t *rng_state) { a = (a - mean) / sd; float tail = 1; // The algorithm samples right tail N(0, 1), so negate everything if left // tail samples are needed. if (a < 0) tail = -1; a *= tail; float z = 0; for (int i = 0; i < MAX_ITER; i++) { // Generate z ~ EXP(alpha) + a. float alpha = (a + sqrtf(powf(a, 2) + 4)) / 2; float u = curand_uniform(rng_state); z = -logf(1 - u) / alpha + a; // Compute g(z). float gz = expf(-powf(z - alpha, 2) / 2); // Generate u and test acceptance. u = curand_uniform(rng_state); if (u <= gz) break; } return sd * tail * z + mean; } __global__ void gpu_trunc_normal( int n, float *mean, float *sd, float *a, float *b, float *result) { // Get block and thread numbers. int block = blockIdx.x + blockIdx.y * gridDim.x; int thread = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * (blockDim.y * blockDim.x); int block_size = blockDim.x * blockDim.y * blockDim.z; int idx = thread + block * block_size; // Only compute if the index is less than the result length. if (idx < n) { // Initialize the RNG. This could be done in a separate kernel. curandState_t rng_state; curand_init(109 + 126*block, thread, 0, &rng_state); // Get truncated normal value. Use C. Robert's algorithm if possible. float draw; if (!isfinite(a[idx]) && b[idx] <= mean[idx]) { // printf("Left tail code in thread %i.\n", idx); draw = tail_normal(mean[idx], sd[idx], b[idx], &rng_state); } else if (!isfinite(b[idx]) && a[idx] >= mean[idx]) { // printf("Right tail code in thread %i.\n", idx); draw = tail_normal(mean[idx], sd[idx], a[idx], &rng_state); } else { // printf("Generic code in thread %i.\n", idx); for (int i = 0; i < MAX_ITER; i++) { draw = sd[idx] * curand_normal(&rng_state) + mean[idx]; if (a[idx] <= draw && draw <= b[idx]) break; } } // end if result[idx] = draw; } } int main() { int n = 3; // desired number of samples float mean[] = {0, 0, 0}; float sd[] = {0, 1, 1}; float a[] = {-INFINITY, 20, -INFINITY}; float b[] = {INFINITY, INFINITY, -20}; float res[n]; // Initialize GPU memory. float *d_mean, *d_sd, *d_a, *d_b, *d_res; cudaMalloc(&d_mean, sizeof(mean)); cudaMalloc(&d_sd, sizeof(sd)); cudaMalloc(&d_a, sizeof(a)); cudaMalloc(&d_b, sizeof(b)); cudaMalloc(&d_res, sizeof(res)); // Copy to GPU memory. cudaMemcpy(d_mean, mean, sizeof(mean), cudaMemcpyHostToDevice); cudaMemcpy(d_sd, sd, sizeof(sd), cudaMemcpyHostToDevice); cudaMemcpy(d_a, a, sizeof(a), cudaMemcpyHostToDevice); cudaMemcpy(d_b, b, sizeof(b), cudaMemcpyHostToDevice); // Run the kernel. gpu_trunc_normal<<<1, 16>>>(n, d_mean, d_sd, d_a, d_b, d_res); cudaDeviceSynchronize(); // Copy back to host memory. printf("Size of res is %zu\n", sizeof(res)); cudaMemcpy(res, d_res, sizeof(res), cudaMemcpyDeviceToHost); // Print the result. puts("The results are in!"); for (int i = 0; i < n; i++) { printf(" %f", res[i]); if (i == 4) { puts(""); } } puts(""); }
9,916
// // From: https://developer.nvidia.com/blog/how-implement-performance-metrics-cuda-cc/ // by Mark Harris // #include <algorithm> #include <cmath> #include <stdio.h> template<typename T, typename U> constexpr T ceildiv(T t, U u) { return (t + u - 1) / u; } __global__ void saxpy(int n, float a, float* x, float* y) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { y[i] = a * x[i] + y[i]; } } int main() { constexpr int N = 1 << 20; float *x, *y, *d_x, *d_y; x = (float*)malloc(N * sizeof(float)); y = (float*)malloc(N * sizeof(float)); cudaMalloc(&d_x, N * sizeof(float)); cudaMalloc(&d_y, N * sizeof(float)); for (int i = 0; i < N; i++) { x[i] = 1.0f; y[i] = 2.0f; } cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaMemcpy(d_x, x, N * sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy(d_y, y, N * sizeof(float), cudaMemcpyHostToDevice); constexpr int blockSize = 256; constexpr int nBlocks = ceildiv(N, blockSize); cudaEventRecord(start); saxpy<<<nBlocks, blockSize>>>(N, 2.0f, d_x, d_y); cudaEventRecord(stop); cudaMemcpy(y, d_y, N * sizeof(float), cudaMemcpyDeviceToHost); cudaEventSynchronize(stop); float millis = 0.0f; cudaEventElapsedTime(&millis, start, stop); float maxError = 0.0f; for (int i = 0; i < N; i++) { maxError = std::max(maxError, std::abs(y[i] - 4.0f)); } printf("max error: %f\n", maxError); printf("duration (ms): %f\n", millis); printf("effective bandwidth (gb/s): %f\n", (float)N * sizeof(float) * 3 / millis / 1e6); cudaFree(d_x); cudaFree(d_y); free(x); free(y); return 0; }
9,917
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> __global__ void mem_trs_test(int* input) { int grid = blockIdx.x * blockDim.x + threadIdx.x; printf("tid : %d, gid : %d, value : %d \n", threadIdx.x, grid, input[grid]); } int main(void) { int size = 128; int byte_size = size * sizeof(int); int* h_input = (int*)malloc(byte_size); time_t t; srand((unsigned)time(&t)); for ( int i = 0;i < size;i++ ) { h_input[i] = (int)(rand() & 0xff); } int* d_input; cudaMalloc((void**)&d_input, byte_size); cudaMemcpy(d_input, h_input, byte_size, cudaMemcpyHostToDevice); dim3 block(64); dim3 grid(2); mem_trs_test<<<grid, block>>>(d_input); cudaDeviceSynchronize(); cudaFree(d_input); free(h_input); cudaDeviceReset(); return 0; }
9,918
#pragma unmanaged #include <iostream> #include <cuda_runtime.h> // Define this to turn on error checking //#define CUDA_ERROR_CHECK #define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__, deviceID ) #define CudaCheckError() __cudaCheckError( __FILE__, __LINE__, deviceID ) __host__ inline void __cudaSafeCall(cudaError err, const char *file, const int line, int deviceID) { #ifdef CUDA_ERROR_CHECK if (cudaSuccess != err) { std::cerr << "\nCUDA device ID: " << deviceID << " encountered an error in file '" << file << "' in line " << line << " : " << cudaGetErrorString(err) << ".\n"; exit(EXIT_FAILURE); } #endif return; } __host__ inline void __cudaCheckError(const char *file, const int line, int deviceID) { #ifdef CUDA_ERROR_CHECK cudaError err = cudaGetLastError(); if (cudaSuccess != err) { std::cerr << "\nCUDA device ID: " << deviceID << " encountered an error in file '" << file << "' in line " << line << " : " << cudaGetErrorString(err) << ".\n"; exit(EXIT_FAILURE); } // More careful checking. However, this will affect performance. // Comment away if needed. err = cudaDeviceSynchronize(); if (cudaSuccess != err) { std::cerr << "\nCUDA device ID: " << deviceID << " encountered an error after sync in file '" << file << "' in line " << line << " : " << cudaGetErrorString(err) << ".\n"; exit(EXIT_FAILURE); } #endif return; }
9,919
#include <cuda.h> #include <stdlib.h> #include <stdio.h> __global__ void solve(){ __shared__ int going; int id = threadIdx.x; going = -1; while (going < 0){ if (id==7){ going = id; return; } } } int main(){ solve<<<1, 32>>>(); return 0; }
9,920
// SDSC Summer Institute 2018 // Andreas Goetz (agoetz@sdsc.edu) // CUDA program to add two integer numbers on the GPU // #include<stdio.h> // // CUDA device function that adds two integer numbers // __global__ void add(int *a, int *b, int *c){ *c = *a + *b; } // // main program // int main(void) { int h_a, h_b, h_c; // host copies int *d_a, *d_b, *d_c; // device copies int size = sizeof(int); // allocate device memory cudaMalloc((void **)&d_a, size); cudaMalloc((void **)&d_b, size); cudaMalloc((void **)&d_c, size); // setup input data h_a = 5; h_b = 7; // copy input data to device cudaMemcpy(d_a, &h_a, size, cudaMemcpyHostToDevice); cudaMemcpy(d_b, &h_b, size, cudaMemcpyHostToDevice); // launch kernel add<<<1,1>>>(d_a, d_b, d_c); // copy results back to host cudaMemcpy(&h_c, d_c, size, cudaMemcpyDeviceToHost); // deallocate memory cudaFree(d_a); cudaFree(d_b); cudaFree(d_c); // print results printf("\n Addition on CPU: %d + %d = %d\n", h_a, h_b, h_a + h_b); printf("\n Addition on GPU: %d + %d = %d\n\n",h_a, h_b, h_c); return 0; }
9,921
#include "simulator.cuh" __device__ void Simulator::run() { //kernel_run<<<THREADS_PER_BLOCK,BLOCKS_PER_GRID>>>(); } __device__ void Simulator::stop() { _duration = _cycle + 1; }
9,922
//Download CImg.h and put it on the same folder. //in Linux, compile with: // g++ main.cpp -o imageViewer -lX11 -pthreads #include <iostream> __global__ void kernel(int x, int y, int s, float *img) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < (x*y*s)) img[i] = (img[i] > 125) ? 255 : 0; } float* t (float *f, int x, int y, int s) { //for error checking cudaError_t lerror = cudaSuccess; //Number of pixels int imgSize = x*y*s; int imgSizeOnMem = imgSize*sizeof(float); //Image on device float *d_img; //Alloc memory on device lerror = cudaMalloc(&d_img, imgSizeOnMem); //transfer from host to device: lerror = cudaMemcpy(d_img, f, imgSizeOnMem, cudaMemcpyHostToDevice); kernel<<<(imgSize+255)/256, 256>>>(x, y, s, d_img); //Image on host float *img = new float[imgSize]; //Alloc memory on host //img = (float*)malloc(imgSizeOnMem); //transfer from device to host lerror = cudaMemcpy(img, d_img, imgSizeOnMem, cudaMemcpyDeviceToHost); return img; }
9,923
#include <stdio.h> #include <assert.h> #include <cuda_runtime.h> #define SIZE 3 #define BLOCKSIZE 512 __global__ void minvec(int *idata, int size){ __shared__ int sdata[BLOCKSIZE]; int s; int tid = threadIdx.x; int i = blockIdx.x*blockDim.x + threadIdx.x; int pseudoIf = i < size; /* if (i < size) sdata[tid] = idata[i]; else{ sdata[tid] = idata[0]; }*/ sdata[tid] = pseudoIf * idata[i] + (1-pseudoIf) * idata[0]; __syncthreads(); /*printf(" sdata = %d\n", sdata[tid]);*/ for (s = blockDim.x/2; s > 0; s >>= 1){ if (tid < s){ if (sdata[tid] > sdata[tid+s]){ sdata[tid] = sdata[tid+s]; } } __syncthreads(); } if (tid == 0){ idata[blockIdx.x] = sdata[0]; /*printf("min = %d Id = %d\n",sdata[0], i);*/ } } int main (int argc, char* argv[]){ int iQnt, i, *m, devID = 0, *mv, min; char ignore[100]; cudaError_t error; cudaDeviceProp deviceProp; FILE* f; if (argc != 2){ printf("Usage: %s <caminho_lista>\n", argv[0]); return 2; } /*printf("vector reduction using CUDA\n");*/ /* Boring CUDA stuff */ error = cudaGetDevice(&devID); if (error != cudaSuccess){ printf("cudaGetDevice returned error %s (code %d), line(%d)\n", cudaGetErrorString(error), error, __LINE__); } error = cudaGetDeviceProperties(&deviceProp,devID); if (deviceProp.computeMode == cudaComputeModeProhibited){ fprintf(stderr, "Error: device is running in <Compute Mode Prohibited>, no threads can use ::cudaSetDevice().\n"); exit(EXIT_SUCCESS); } if (error != cudaSuccess){ printf("cudaGetDeviceProperties returned error %s (code %d), line(%d)\n", cudaGetErrorString(error), error, __LINE__); } else{ printf("GPU Device %d: \"%s\" with compute capability %d.%d\n\n", devID, deviceProp.name, deviceProp.major, deviceProp.minor); } /* Open file */ f = fopen(argv[1], "r"); /* Read amount of matrices */ fscanf(f, "%d", &iQnt); /* Allocate matrix on host*/ m = (int *) malloc(sizeof(int)*iQnt); /* Allocate matrix on device */ error = cudaMalloc(&mv, sizeof(int)*iQnt); if (error != cudaSuccess){ printf("cudaMalloc returned error %s (code %d), line(%d) \n", cudaGetErrorString(error), error, __LINE__); } fgets(ignore, 100, f); /* Get values from file */ for (i = 0; i < iQnt; ++i){ /*throw first line*/ fgets(ignore, 100, f); fscanf(f, "%d \n", &m[i]); /*printf("%d\n", m[i]);*/ } /*printf("m[0] = %d\n", m[0]);*/ error = cudaMemcpy(mv, m, sizeof(int)*iQnt, cudaMemcpyHostToDevice); if (error != cudaSuccess){ printf("cudaMemcpy returned error %s (code %d), line(%d) \n", cudaGetErrorString(error), error, __LINE__); } for (i = iQnt; i > 1; i = 1+(i/BLOCKSIZE)){ printf("Size of reduction = %d\n", i); minvec<<<(1+(iQnt/BLOCKSIZE)), BLOCKSIZE>>>(mv, i); cudaDeviceSynchronize(); } /*error = cudaMemcpy(m, mv, (sizeof(int)*(1+(iQnt/BLOCKSIZE))), cudaMemcpyDeviceToHost);*/ error = cudaMemcpy(&min, &mv[0], sizeof(int), cudaMemcpyDeviceToHost); if (error != cudaSuccess){ printf("cudaMemcpy returned error %s (code %d), line(%d) \n", cudaGetErrorString(error), error, __LINE__); } printf("CABO! - THE MIN IS %d \n", min); free(m); cudaFree(mv); }
9,924
#include "includes.h" __global__ void set_grid_array_to_value(float *arr, float value, int N_grid){ int i = blockIdx.x*blockDim.x + threadIdx.x; int j = blockIdx.y*blockDim.y + threadIdx.y; int k = blockIdx.z*blockDim.z + threadIdx.z; int index = k*N_grid*N_grid + j*N_grid + i; if((i<N_grid) && (j<N_grid) && (k<N_grid)){ arr[index] = value; } }
9,925
/**** File: findRedsDriver.cu Date: 5/3/2018 By: Bill Hsu ****/ /* * How to compile and execute: * source ~whsu/lees.bash_profile * nvcc findRedsGPU.cu -o frgpu -lm -Wno-deprecated-gpu-targets * ./frgpu * Submission by: Jonas Vinter-Jensen, 912941515 */ #include <stdio.h> #include <math.h> #include <stdlib.h> #include <cuda.h> #define NUMPARTICLES 1024 #define NEIGHBORHOOD .05 #define THREADSPERBLOCK 4 void initPos(float*); float findDistance(float*, int, int); __device__ float findDistanceGPU(float*, int, int); void dumpResults(int index[]); __global__ void findRedsGPU(float* p, int* numI); int main(int argc, const char* argv[]) { cudaEvent_t start, stop; float time; float* pos; float* dpos; int* numReds; int* dnumReds; pos = (float*) malloc(NUMPARTICLES * 4 * sizeof(float)); numReds = (int*) malloc(NUMPARTICLES * sizeof(int)); initPos(pos); // your code to allocate device arrays for pos and numReds go here cudaMalloc((void**) &dpos, NUMPARTICLES * 4 * sizeof(float)); cudaMalloc((void**) &dnumReds, NUMPARTICLES * sizeof(int)); cudaMemcpy(dpos, pos, NUMPARTICLES * 4 * sizeof(float), cudaMemcpyHostToDevice); //dpos = copy(pos) // create timer events cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); //(event, stream) /* invoke kernel findRedsGPU here */ findRedsGPU<<<NUMPARTICLES/THREADSPERBLOCK, THREADSPERBLOCK>>>(dpos, dnumReds); cudaThreadSynchronize(); // your code to copy results to numReds[] go here cudaMemcpy(numReds, dnumReds, NUMPARTICLES * sizeof(int), cudaMemcpyDeviceToHost); //numReds = copy(dnumReds) cudaEventRecord(stop, 0); cudaEventSynchronize(stop); //waits for record event to complete cudaEventElapsedTime(&time, start, stop); printf("Elapsed time = %f\n", time); dumpResults(numReds); free(pos); cudaFree(dpos); free(numReds); cudaFree(dnumReds); return 0; } void initPos(float* p) { // your code for initializing pos goes here int i; for (i = 0; i < NUMPARTICLES; i++) { p[i * 4] = rand() / (float) RAND_MAX; //p.x p[i * 4 + 1] = rand() / (float) RAND_MAX; //p.y p[i * 4 + 2] = rand() / (float) RAND_MAX; //p.z int colorChoice; colorChoice = random() % 3; if (colorChoice == 0) { p[i * 4 + 3] = 0xff0000; //p.color = red } else if (colorChoice == 1) { p[i * 4 + 3] = 0x00ff00; //p.color = green } else { p[i * 4 + 3] = 0x0000ff; //p.color = blue } } } __device__ float findDistanceGPU(float* p, int i, int j) { // your code for calculating distance for particle i and j float dx, dy, dz; dx = p[i * 4] - p[j * 4]; //x2-x1 dy = p[i * 4 + 1] - p[j * 4 + 1]; //y2-y1 dz = p[i * 4 + 2] - p[j * 4 + 2]; //z2-z1 return (sqrt(dx * dx + dy * dy + dz * dz)); } __global__ void findRedsGPU(float* p, int* numI) { // your code for counting red particles goes here int k; float distance; int p2_num = blockDim.x*blockIdx.x + threadIdx.x; for (k = 0; k < NUMPARTICLES; k++) { /*Every time a new (blockId, threadId) permutation occurs, initialize number of red particles near particle * k to 0 for every first k-loop iteration of the pairs.*/ if(k==0) { numI[p2_num] = 0; } if (k != p2_num) { /* calculate distance between particles k, p2_num */ distance = findDistanceGPU(p, k, p2_num); /* if distance < r and color is red, increment count */ if (distance < NEIGHBORHOOD && p[p2_num * 4 + 3] == 0xff0000) { numI[k]++; } } } } void dumpResults(int index[]) { int i; FILE* fp; fp = fopen("./dump.out", "w"); for (i = 0; i < NUMPARTICLES; i++) { fprintf(fp, "%d %d\n", i, index[i]); } fclose(fp); }
9,926
#include <stdint.h> #define uint uint32_t #define WST 8 #define WSU 8 #define WSV 8 #define WS (WST*WSU*WSV) #define CELL_LENGTH 3 #define CELL_SIZE (CELL_LENGTH*CELL_LENGTH*CELL_LENGTH) #define BLOCK_SIZE (WS*CELL_SIZE) #define WLT (WST*CELL_LENGTH) #define WLU (WSU*CELL_LENGTH) #define WLV (WSV*CELL_LENGTH) #define WS_MASK (WS-1) #define TID_MASK (WST-1) #define UID_MASK (WSU-1) #define VID_MASK (WSV-1) #include <stdint.h> #define uint uint32_t __device__ uint Rng4(uint4* state){ uint b; b = ((((*state).x << 6)^(*state).x) >> 13); (*state).x = ((((*state).x & 4294967294) << 18) ^b); b = ((((*state).y << 2)^(*state).y) >> 27); (*state).y = ((((*state).y & 4294967288) << 2) ^b); b = ((((*state).z << 13)^(*state).z) >> 21); (*state).z = ((((*state).z & 4294967280) << 7) ^b); b = ((((*state).w << 3)^(*state).w) >> 12); (*state).w = ((((*state).w & 4294967168) << 13)^b); return ((*state).x^(*state).y^(*state).z^(*state).w); } __device__ int TUVToIndex(int t, int u, int v){ int index=0; index += (t%3)<<9; index += ((u%3)*3)<<9; index += ((v%3)*9)<<9; index += (t/3)+(u/3)*WST+(v/3)*WST*WSU; return index; } __device__ int AddUnitToIndex(int unit, int index, int& OOB){ int dw = (unit>>3)&0x1; int dt = ((unit>>0)&0x1)-dw; int du = ((unit>>1)&0x1)-dw; int dv = ((unit>>2)&0x1)-dw; int tr=(index>>9)%3; int ur=((index>>9)/3)%3; int vr=((index>>9)/9); tr += dt; ur += du; vr += dv; // And now for a new bag of tricks! The idea is to find out whether it is out of bounds after // adding a combination of +/- t,u,v. We don't check for overflow, since that is actually useful for // the subtraction itself (without the out-of-bounds). We know that we either go // from 111 -> 000 or 111 -> 000 in case of out-of bounds. int mask = (tr+1)/4*(0x001); //+t mask += (3-tr)/4*(0x007); //-t mask += (ur+1)/4*(0x008); //+u mask += (3-ur)/4*(0x038); //-u mask += (vr+1)/4*(0x040); //+v mask += (3-vr)/4*(0x1c0); //-v int newIndex = ((index&WS_MASK)+mask)&WS_MASK; int oldIndex = index&WS_MASK; int a = oldIndex|(oldIndex>>1)|(oldIndex>>2); int b = newIndex|(newIndex>>1)|(newIndex>>2); int c = oldIndex&(oldIndex>>1)&(oldIndex>>2); int d = newIndex&(newIndex>>1)&(newIndex>>2); OOB= (((~a)&d)|((~b)&c))&0x49; newIndex += (tr+ur*3+vr*9)*WS; return newIndex; } __device__ uint GPUValidateAddUnitVectors(int a, int b, int& c){ int valid; if((a|b) != 0xf && (a&b)) return 0; c = (((a|b)==0xf)?(a&b):(a|b)); valid = (c==0x3||c==0xc)?0:1; return valid; } __device__ uint GPUAddUnitVectors(uint a, uint b){ return (((a|b)==0xf)?(a&b):(a|b)); } __device__ void TransForw(char* lattice, int index, uint* trans, uint4* rngState){ int OOB; int latSiteComplete = lattice[index]; if(!latSiteComplete) return; int next = latSiteComplete&0xf; int label = latSiteComplete&0x30; int sl = latSiteComplete&0x40; int newIndex = AddUnitToIndex(next, index, OOB); if(OOB) return; int newSiteComp = lattice[newIndex]; int newSl=newSiteComp&0x40; if(sl+newSl==0) return; uint rand = Rng4(rngState); int newBond1 = (trans[next/4]>>(4*(2*next%4)+(next&0x1)))&0xf; int newBond2 = GPUAddUnitVectors((~newBond1)&0xf, next); int temp = newBond1; newBond1 = (rand&0x2)?newBond1:newBond2; newBond2 = (rand&0x2)?newBond2:temp; int destIndex = AddUnitToIndex(index,newBond1,OOB); if(OOB) return; int destSiteComp = lattice[destIndex]; if(destSiteComp) return; int moveFirst; if(sl+newSl==0x80){ moveFirst = (rand&0x4)>>2; } else if(sl) moveFirst = 1; else moveFirst = 0; destSiteComp = newBond2; if(moveFirst){ latSiteComplete = newBond1|((label>>1)&0x10); destSiteComp |= label&0x10; } else{ latSiteComplete = newBond1|label|sl; destSiteComp |= (newSiteComp&0x20)>>1; newSiteComp = newSiteComp&0x5f; } lattice[index] = latSiteComplete; lattice[destIndex] = destSiteComp; if(!moveFirst) lattice[newIndex] = newSiteComp; } __device__ void TransBack(char* lattice, int index, uint* trans, uint4* rngState){ int OOB; int latSiteComplete = lattice[index]; int next = latSiteComplete&0xf; int label = latSiteComplete&0x30; int sl = latSiteComplete&0x40; if(!latSiteComplete) return; int srcIndex = AddUnitToIndex(next, index, OOB); if(OOB) return; int srcSiteComp = lattice[srcIndex]; int srcNext = srcSiteComp&0xf; int srcLabel= srcSiteComp&0x30; int srcSl = srcSiteComp&0x40; int newNext; if(srcSl) return; if(!GPUValidateAddUnitVectors(next, srcNext, newNext)) return; int newIndex = AddUnitToIndex(newNext, index, OOB); if(OOB) return; int newSiteComp = lattice[newIndex]; int newSiteSl = newSiteComp&0x40; if(sl+newSiteSl == 0x80) return; uint rand = Rng4(rngState); int moveFirst; if(sl+newSiteSl == 0x0){ moveFirst = rand&0x1; } else if(sl == 0x40) moveFirst = 0; else moveFirst = 1; if(moveFirst){ latSiteComplete = newNext|(label<<1)|0x40; } else{ latSiteComplete = newNext|label|sl; newSiteComp = (newSiteComp&0x3f)|(srcLabel<<1)|0x40; } lattice[srcIndex]=0; lattice[index] = latSiteComplete; lattice[newIndex] = newSiteComp; } __device__ void DiffuseSL(char* lattice, int index){ int OOB; int latSiteComplete = lattice[index]; int next = latSiteComplete&0xf; int label = latSiteComplete&0x30; int sl = latSiteComplete&0x40; if(!latSiteComplete) return; int newIndex = AddUnitToIndex(next, index, OOB); int newSiteComp = lattice[newIndex]; int newSiteLabel = newSiteComp&0x30; int newSiteSl = newSiteComp&0x40; if(OOB) return; if(newSiteSl + sl != 0x40) return; if(sl){ newSiteComp = newSiteComp | ((label&0x10)<<1) | 0x40; latSiteComplete = next|((label>>1)&0x10); } else{ latSiteComplete = next|(label<<1)|((newSiteLabel>>1)&0x10)|0x40; newSiteComp = newSiteComp&0x1f; } lattice[index] = latSiteComplete; lattice[newIndex] = newSiteComp; } __global__ void polmove(int nStep, uint4* seeds, char* srcLattice, char* dstLattice, uint* gTrans, int dtuv, int dtuv_next, uint NWT, uint NWU, uint NWV){ __shared__ char lattice[BLOCK_SIZE]; uint trans[4]; int lid = threadIdx.x; int wid = blockIdx.x; int gid = wid * blockDim.x + lid; uint4 rngl; uint4 rngp; uint site; int dt = dtuv%WLT; int du = (dtuv/WLT)%(WLU); int dv = dtuv/(WLT*WLU); int p=0; int pSwitchNext=dt*du*dv; int dtBlock=dt; int duBlock=du; int dvBlock=dv; int memOffSet=0; for(int src=wid*BLOCK_SIZE+lid*4; src<(wid+1)*BLOCK_SIZE; src += 4*WS){ for(int i=0; i<4 && i+src<4*WS; i++){ while(i+src>=pSwitchNext){ memOffSet += pSwitchNext; dtBlock = (p&0x1)?(WLT-dt):dt; duBlock = (p&0x2)?(WLU-du):du; dvBlock = (p&0x4)?(WLV-dv):dv; pSwitchNext += dtBlock*duBlock*dvBlock; p++; } int offSet = src+i-memOffSet; int t = ((p&0x1)?dt:0) + (offSet%dtBlock); int u = ((p&0x2)?du:0) + ((offSet/dtBlock)%duBlock); int v = ((p&0x4)?dv:0) + (offSet/(dtBlock*duBlock)); int index = TUVToIndex(t,u,v); lattice[index]=srcLattice[src+i]; } } for(int i=0; i<4; i++) trans[i] = gTrans[i]; int indexStart = ((lid&0x1f)<<2)|((lid&0x60)>>5)|(lid&0x180); rngp = seeds[gid*2]; rngl = seeds[gid*2+1]; __syncthreads(); for(int i=0; i<nStep; i++){ site = indexStart | ((Rng4(&rngl)%27)<<9); DiffuseSL(lattice, site); __syncthreads(); site = indexStart | ((Rng4(&rngl)%27)<<9); TransForw(lattice, site, trans, &rngp); __syncthreads(); site = indexStart | ((Rng4(&rngl)%27)<<9); DiffuseSL(lattice, site); __syncthreads(); site = indexStart | ((Rng4(&rngl)%27)<<9); TransBack(lattice, site, trans, &rngp); __syncthreads(); } dt = dtuv_next%WLT; du = (dtuv_next/WLT)%(WLU); dv = dtuv_next/(WLT*WLU); memOffSet=0; for(int p=0; p<8; p++){ int dtBlock = (p^0x1)?(WLT-dt):dt; int duBlock = (p^0x2)?(WLU-du):du; int dvBlock = (p^0x4)?(WLV-dv):dv; int dstWid = ((wid%NWT)+NWT-(((p>>0)&0x1)^0x1))%NWT; dstWid += (((wid%NWU)+NWU-(((p>>1)&0x1)^0x1))%NWU)*NWT; dstWid += (((wid%NWU)+NWU-(((p>>2)&0x1)^0x1))%NWU)*NWT*NWU; for(int i=lid; i<dtBlock*duBlock*dvBlock; i+=WS){ int t = i%dtBlock; int u = (i/dtBlock)%duBlock; int v = (i/(dtBlock*duBlock)); int dst = dstWid*BLOCK_SIZE+memOffSet+i; int index = TUVToIndex(t, u, v); dstLattice[dst] = lattice[index]; } memOffSet += dtBlock*duBlock*dvBlock; } __syncthreads(); }
9,927
#include "includes.h" //define the multithread action //start main activity __global__ void cube(float * d_out, float * d_in){ int idx = threadIdx.x; float f = d_in[idx]; d_out[idx] = f*f*f; }
9,928
#include "includes.h" __device__ int2 devInt2[10]; __global__ void regOperation() { int2 f = devInt2[1]; devInt2[0] = f; } __global__ void regOperation2() { int2 f = devInt2[1]; devInt2[0].x = f.x; devInt2[0].y = f.y; }
9,929
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void mykernel() { int i = blockIdx.x; int j = threadIdx.x; printf("Hello world from Kernel\tBlock id: %d\tThread id: %d\n", i, j); } int main() { printf("Hello world from CPU\n"); mykernel<<<4,5>>>(); cudaDeviceReset(); while(1); return 0; }
9,930
#include <stdio.h> #include <stdlib.h> #include <cuda_runtime.h> int main(){ printf("hello world!\n"); }
9,931
#include "includes.h" // filename: vmult!.cu // a simple CUDA kernel to element multiply two vectors C=alpha*A.*B extern "C" // ensure function name to be exactly "vmult!" { } __global__ void vabs(const int n, const double *a, double *b) { int i = threadIdx.x + blockIdx.x * blockDim.x; if (i<n) {b[i]=fabs(a[i]);} }
9,932
#include <stdio.h> #include <stdlib.h> #include <algorithm> #include <cfloat> #include <chrono> #include <fstream> #include <iostream> #include <random> #include <sstream> #include <stdexcept> #include <vector> #include <chrono> #include <time.h> float gpu_time_used; #define I(row, col, ncols) (row * ncols + col) #define CUDA_CALL(x) {if((x) != cudaSuccess){ \ printf("CUDA error at %s:%d\n",__FILE__,__LINE__); \ printf(" %s\n", cudaGetErrorString(cudaGetLastError())); \ exit(EXIT_FAILURE);}} //f = number of features (from argv[1]) __global__ void get_dst(float *dst, float *x, float *mu_x, int f){ int i = blockIdx.x; int j = threadIdx.x; //updated (in loop): dst[I(i, j, blockDim.x)] = (x[i*f] - mu_x[j*f]) * (x[i*f] - mu_x[j*f]); for(int l = 1 ; l<f ; l++) { dst[I(i, j, blockDim.x)] += (x[i*f +l] - mu_x[j*f + l]) * (x[i*f +l] - mu_x[j*f + l]); } //printf("%d %d %f \n",i,j,dst[I(i, j, blockDim.x)]); } __global__ void regroup(int *group, float *dst, int k){ int i = blockIdx.x; int j; float min_dst; min_dst = dst[I(i, 0, k)]; group[i] = 1; for(j = 1; j < k; ++j){ if(dst[I(i, j, k)] < min_dst){ min_dst = dst[I(i, j, k)]; group[i] = j + 1; } } } //updated __global__ void clear(float *sum_x, int *nx, int f){ int j = threadIdx.x; for(int l = 0 ; l<f ; l++) { sum_x[j*f + l] = 0; nx[j*f + l] = 0; } } //changes : need 2d array for sum and nx also, f: number of features __global__ void recenter_step1(float *sum_x, int *nx, float *x, int *group, int n, int f){ int i; int j = threadIdx.x; for(i = 0; i < n; ++i){ if(group[i] == (j + 1)){ //loop through entire sum and n for(int l = 0 ; l<f ; l++) { sum_x[j*f + l] += x[i*f +l]; nx[j*f + l]++; } } } } __global__ void recenter_step2(float *mu_x, float *sum_x, int *nx, int f){ int j = threadIdx.x; // added loop for(int l = 0 ; l<f ; l++) { mu_x[j*f + l] = sum_x[j*f +l]/nx[j*f + l]; } } void kmeans(int nreps, int n, int k, float *x_d, float *mu_x_d, int *group_d, int *nx_d, float *sum_x_d, float *dst_d, int f){ int i; for(i = 0; i < nreps; ++i){ get_dst<<<n,k>>>(dst_d, x_d, mu_x_d, f); regroup<<<n,1>>>(group_d, dst_d, k); clear<<<1,k>>>(sum_x_d, nx_d, f); recenter_step1<<<1,k>>>(sum_x_d, nx_d, x_d, group_d, n,f); recenter_step2<<<1,k>>>(mu_x_d, sum_x_d, nx_d,f); } } void read_data(float *x, float *mu_x, int *n, int *k,char* arg, int no_feature, int no_data); void print_results(int *group, float *mu_x, int n, int k,char* arg,int no_feature); int main(int argc,char* argv[]){ //Argv 1: No of Features //Argv 2: Input path //Argv 3: No of datapoints //Argv 4: No of cluster /* cpu variables */ int n=atoi(argv[3]); /* number of points */ int k=atoi(argv[4]); /* number of clusters */ int f=atoi(argv[1]); /*number of Features */ int *group; float *x = NULL, *mu_x = NULL; x = (float*) malloc(atoi(argv[3])*atoi(argv[1])*sizeof(float)); mu_x = (float*) malloc(atoi(argv[3])*atoi(argv[1])*sizeof(float)); /* gpu variables */ int *group_d, *nx_d; float *x_d, *mu_x_d, *sum_x_d, *dst_d; /* read data from files on cpu */ read_data(x, mu_x, &n, &k,argv[2], atoi(argv[1]), atoi(argv[3])); /* allocate cpu memory */ group = (int*) malloc(n*sizeof(int)); /* allocate gpu memory */ CUDA_CALL(cudaMalloc((void**) &group_d,n*sizeof(int))); CUDA_CALL(cudaMalloc((void**) &nx_d, f*k*sizeof(int))); CUDA_CALL(cudaMalloc((void**) &x_d, f*n*sizeof(float))); CUDA_CALL(cudaMalloc((void**) &mu_x_d, f*k*sizeof(float))); CUDA_CALL(cudaMalloc((void**) &sum_x_d, f*k*sizeof(float))); CUDA_CALL(cudaMalloc((void**) &dst_d, n*k*sizeof(float))); /* write data to gpu */ CUDA_CALL(cudaMemcpy(x_d, x, f*n*sizeof(float), cudaMemcpyHostToDevice)); CUDA_CALL(cudaMemcpy(mu_x_d, mu_x, f*k*sizeof(float), cudaMemcpyHostToDevice)); /* perform kmeans */ kmeans(200, n, k, x_d, mu_x_d, group_d, nx_d, sum_x_d, dst_d, atoi(argv[1])); /* read back data from gpu */ CUDA_CALL(cudaMemcpy(group, group_d, n*sizeof(int), cudaMemcpyDeviceToHost)); CUDA_CALL(cudaMemcpy(mu_x, mu_x_d, f*k*sizeof(float), cudaMemcpyDeviceToHost)); //CUDA_CALL(cudaMemcpy(mu_y, mu_y_d, k*sizeof(float), cudaMemcpyDeviceToHost)); /* print results and clean up */ print_results(group, mu_x, n, k,argv[3],atoi(argv[1])); free(x); free(mu_x); free(group); CUDA_CALL(cudaFree(x_d)); CUDA_CALL(cudaFree(mu_x_d)); CUDA_CALL(cudaFree(group_d)); CUDA_CALL(cudaFree(nx_d)); CUDA_CALL(cudaFree(sum_x_d)); CUDA_CALL(cudaFree(dst_d)); return 0; } void read_data(float *x, float *mu_x, int *n, int *k,char* arg, int no_feature, int no_data){ FILE *fp; int i,j; fp = fopen(arg, "r"); for(i = 0; i < no_data; i++) { for(j = 0; j < no_feature; j++) { fscanf(fp," %f", &x[i*no_feature+j]); } } fp = fopen("input/initCoord.txt", "r"); for(i = 0; i < *k; i++) { for(j = 0; j < no_feature; j++) { fscanf(fp," %f", &mu_x[i*no_feature+j]); } } fclose(fp); } void print_results(int *group, float *mu_x, int n, int k,char* arg,int no_feature){ FILE *fp; int i,j; std::string str(arg),str1,str2; str = "output/" ; str1 = str + "group_members.txt"; fp = fopen(str1.c_str(), "w"); for(i = 0; i < n; ++i){ fprintf(fp, "%d\n", group[i]); } fclose(fp); str2 = str + "centroids.txt"; fp = fopen(str2.c_str(), "w"); for(i=0;i < k; ++i){ for(j = 0; j < no_feature; ++j){ fprintf(fp, "%0.6f ", mu_x[i*no_feature+j]); } fprintf(fp, "\n"); } fclose(fp); }
9,933
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "hist-equ.cuh" // Device code __global__ void construct_histogram_gpu(int * hist_out, unsigned char * img_in, int * img_size) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < *img_size) { atomicAdd(&hist_out[img_in[i]], 1); } } // Host code void histogram_gpu(int * hist_out, unsigned char * img_in, int img_size, int nbr_bin) { int i; for(i = 0; i < nbr_bin; i++) { hist_out[i] = 0; } // Allocate vectors in device memory int* hist_out_gpu; cudaMalloc(&hist_out_gpu, nbr_bin*(sizeof(int))); unsigned char* img_in_gpu; cudaMalloc(&img_in_gpu, img_size*(sizeof(unsigned char))); int* img_size_gpu; cudaMalloc(&img_size_gpu, sizeof(int)); // Copy vectors from host memory to device memory cudaMemcpy(hist_out_gpu, hist_out, nbr_bin*(sizeof(int)), cudaMemcpyHostToDevice); cudaMemcpy(img_in_gpu, img_in, img_size*(sizeof(unsigned char)), cudaMemcpyHostToDevice); cudaMemcpy(img_size_gpu, &img_size, sizeof(int), cudaMemcpyHostToDevice); // Invoke kernel int blocksPerGrid = (img_size + nbr_bin - 1) / nbr_bin; construct_histogram_gpu<<<blocksPerGrid, nbr_bin>>> (hist_out_gpu, img_in_gpu, img_size_gpu); // Copy result from device memory to host memory cudaMemcpy(hist_out, hist_out_gpu, nbr_bin*(sizeof(int)), cudaMemcpyDeviceToHost); // Free device memory cudaFree(hist_out_gpu); cudaFree(img_in_gpu); cudaFree(img_size_gpu); } // Device code __global__ void construct_lut_gpu(int * cdf, int * lut, int * hist_in, int * min, int * d) { int i = blockIdx.x * blockDim.x + threadIdx.x; __shared__ int lut_temp[256]; lut_temp[i] = (int)(((float)(cdf[i]) - (*min))*255/(*d) + 0.5); if(lut_temp[i] < 0) { lut_temp[i] = 0; } __syncthreads(); lut[i] = lut_temp[i]; } // Device code __global__ void get_result_image_gpu(int * lut, unsigned char * img_out, unsigned char * img_in, int * img_size) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < *img_size) { if(lut[img_in[i]] > 255) { img_out[i] = 255; } else { img_out[i] = (unsigned char)lut[img_in[i]]; } } } // Host code void histogram_equalization_gpu(unsigned char * img_out, unsigned char * img_in, int * hist_in, int img_size, int nbr_bin) { int* lut = (int*)malloc(sizeof(int)*nbr_bin); int* cdf = (int*)malloc(sizeof(int)*nbr_bin); int i, min, d; min = 0; i = 0; while (min == 0) { min = hist_in[i++]; } cdf[0] = hist_in[0]; for(i = 1; i < nbr_bin; i++) { cdf[i] = cdf[i-1] + hist_in[i]; } d = img_size - min; // Allocate vectors in device memory int* lut_gpu; cudaMalloc(&lut_gpu, nbr_bin*(sizeof(int))); int* cdf_gpu; cudaMalloc(&cdf_gpu, nbr_bin*(sizeof(int))); unsigned char* img_out_gpu; cudaMalloc(&img_out_gpu, img_size*(sizeof(unsigned char))); unsigned char* img_in_gpu; cudaMalloc(&img_in_gpu, img_size*(sizeof(unsigned char))); int* hist_in_gpu; cudaMalloc(&hist_in_gpu, nbr_bin*(sizeof(int))); int* img_size_gpu; cudaMalloc(&img_size_gpu, sizeof(int)); int* min_gpu; cudaMalloc(&min_gpu, sizeof(int)); int* d_gpu; cudaMalloc(&d_gpu, sizeof(int)); // Copy vectors from host memory to device memory cudaMemcpy(lut_gpu, lut, nbr_bin*(sizeof(int)), cudaMemcpyHostToDevice); cudaMemcpy(cdf_gpu, cdf, nbr_bin*(sizeof(int)), cudaMemcpyHostToDevice); cudaMemcpy(img_out_gpu, img_out, img_size*(sizeof(unsigned char)), cudaMemcpyHostToDevice); cudaMemcpy(img_in_gpu, img_in, img_size*(sizeof(unsigned char)), cudaMemcpyHostToDevice); cudaMemcpy(img_size_gpu, &img_size, sizeof(int), cudaMemcpyHostToDevice); cudaMemcpy(min_gpu, &min, sizeof(int), cudaMemcpyHostToDevice); cudaMemcpy(d_gpu, &d, sizeof(int), cudaMemcpyHostToDevice); // Invoke kernel construct_lut_gpu<<<1, nbr_bin>>> (cdf_gpu, lut_gpu, hist_in_gpu, min_gpu, d_gpu); // Copy result from device memory to host memory cudaMemcpy(lut, lut_gpu, nbr_bin*(sizeof(int)), cudaMemcpyDeviceToHost); // Copy vectors from host memory to device memory cudaMemcpy(lut_gpu, lut, nbr_bin*(sizeof(int)), cudaMemcpyHostToDevice); // Invoke kernel int blocksPerGrid = (img_size + nbr_bin - 1) / nbr_bin; get_result_image_gpu<<<blocksPerGrid, nbr_bin>>> (lut_gpu, img_out_gpu, img_in_gpu, img_size_gpu); // Copy vectors from device memory to host memory cudaMemcpy(img_out, img_out_gpu, img_size*(sizeof(unsigned char)), cudaMemcpyDeviceToHost); // Free device memory cudaFree(lut_gpu); cudaFree(cdf_gpu); cudaFree(img_out_gpu); cudaFree(img_in_gpu); cudaFree(hist_in_gpu); cudaFree(img_size_gpu); cudaFree(min_gpu); cudaFree(d_gpu); }
9,934
#define TILE_DIM 1024 template<typename T> __device__ void sum(const T* matrix, T* result, const int rows, const int cols) { __shared__ T tile[TILE_DIM]; int index = threadIdx.x; int length = rows * cols; int partLength = (length + TILE_DIM - 1) / TILE_DIM; T sum = 0; for (int i = 0; i < partLength; i++) { int valueIndex = i * TILE_DIM + index; if (valueIndex < length) { T value = matrix[valueIndex]; sum += value; } } tile[index] = sum; for (int d = 1; d < TILE_DIM && d < length; d <<= 1) { __syncthreads(); if (index % (d << 1) == 0) { int valueIndex = index + d; if (valueIndex < TILE_DIM) { T value = tile[valueIndex]; sum += value; tile[index] = sum; } } } if (index == 0) { result[0] = sum; } }
9,935
/** File name: bfs_cpu_stl.cu Author: Yuede Ji Last update: 18:25 10-02-2015 Description: Using array to implent CPU version of bfs. Calculate the shortest distance from 0 to others **/ #include <stdio.h> #include <queue> #include <stdlib.h> #include <string.h> using namespace std; #define N 1025 // vertex number //Using arrays to implement queue char filein[] = "/home/yuede/dataset/kron_10_4.dat"; char fileout[] = "/home/yuede/dataset/kron_10_4.result"; //Using arrays to implement queue int q[N]; int edge[N][N]; int visit[N]; int dist[N]; int bfs(int root) { memset(dist, 0, sizeof(int) * N); q[0] = root; int l = 1; // record the size of the queue int front = 0; // identify the front element int end = 0; // identify the end element while(l>0) { int cur = q[front]; ++front; --l; if(front >= N) front %= N; for(int i=0; edge[cur][i]!=0; ++i) { int v = edge[cur][i]; if(visit[v]) continue; dist[v] = dist[cur] + 1; ++end; if(end >= N) end %= N; q[end] = v; visit[v] = 1; ++l; } } return 0; } int main() { FILE *fp_in = fopen(filein, "r"); int v, e; int num_v=0; memset(edge, 0, N*N*sizeof(int)); memset(visit, 0, N*sizeof(int)); while(fscanf(fp_in, "%d %d", &v, &e)!=EOF) { ++num_v; for(int i=0; i<e; ++i) { int v1; fscanf(fp_in, "%d", &v1); edge[v][i] = v1;//v->v1 } } fclose(fp_in); bfs(0); FILE *fp_out = fopen(fileout, "w"); //fprintf("num_v = %d\n", num_v); for(int i=0; i<num_v; ++i) fprintf(fp_out, "distance[0][%d] = %d\n", i, dist[i]); fclose(fp_out); printf("Finished!\n"); return 0; }
9,936
///***************************************************************************************** // posvis.c // // Fill in the portion of a plane-of-sky image due to a particular model component: Assign // each relevant POS pixel a z-value in observer coordinates (distance from the origin // towards Earth) and a value of cos(scattering angle). // // Return 1 if any portion of this component lies outside the specified POS window, // 0 otherwise. // // If the "src" argument is true, the "observer" is the Sun rather than Earth, and // "plane-of-sky" becomes "projection as viewed from the Sun." // // Modified 2014 February 20 by CM: // Allow facets that partly project outside the POS frame to contribute to the POS frame // (thus avoiding see-through "holes" in the model at the edge of a POS image) // // Modified 2010 May 18 by CM: // Bug fix: When checking if a POS pixel hasn't already been assigned // values during a previous call to posvis for a different component, // check for fac[i][j] < 0 rather than cosa[i][j] == 0.0, since for // bistatic situations the latter condition will also be true for // pixels centered on Earth-facing facets that don't face the Sun // // Modified 2009 July 2 by CM: // Eliminate the check that facets are "active": this term is now being // interpreted to mean "not lying interior to the model," so the // check is unnecessary and the determination of active vs. inactive // status is inaccurate for half-exposed facets at the intersections // between model components // // Modified 2009 April 3 by CM: // Compute the "posbnd_logfactor" parameter: if the model extends beyond // the POS frame, posbnd_logfactor is set to the logarithm of the // ratio of the area that would have been required to "contain" the // entire model divided by the area of the actual POS frame // Work with floating-point pixel numbers (imin_dbl, etc.), at least // initially, in case the sky rendering for a model with illegal // parameters would involve huge pixel numbers that exceed the // limits for valid integers // // Modified 2007 August 4 by CM: // Add "orbit_offset" and "body" parameters and remove "facet" parameter // Add body, bodyill, comp, and compill matrices for POS frames // // Modified 2006 June 21 by CM: // For POS renderings, change res to km_per_pixel // // Modified 2005 September 19 by CM: // Allow for roundoff error when determining which POS pixels project // onto each model facet // // Modified 2005 June 27 by CM: // Renamed "round" function to "iround" to avoid conflicts // // Modified 2005 June 22 by CM: // Slightly modified some comments // // Modified 2005 January 25 by CM: // Take care of unused and uninitialized variables // // Modified 2004 December 19 by CM: // Added more comments // Put update of rectangular POS area into "POSrect" routine and applied it // even to facets which lie outside the POS frame // // Modified 2004 Feb 11 by CM: // Added comments // // Modified 2003 May 5 by CM: // Removed redundant coordinate transformation of the unit normal n // for the no-pvs_smoothing case // *****************************************************************************************/ //extern "C" { //#include "../shape/head.h" //#include <limits.h> //} // //#define maxbins 100 //__device__ int posvis_tiled_outbnd, posvis_tiled_smooth; // ///* Note that the following custom atomic functions must be declared in each // * file it is needed (consequence of being a static device function) */ //__device__ static float atomicMaxf(float* address, float val) { // int* address_as_i = (int*) address; // int old = *address_as_i, assumed; // do { // assumed = old; // old = ::atomicCAS(address_as_i, assumed, // __float_as_int(::fmaxf(val, __int_as_float(assumed)))); // } while (assumed != old); // return __int_as_float(old); //} //__device__ static float atomicMax64(double* address, double val) //{ // unsigned long long* address_as_i = (unsigned long long*) address; // unsigned long long old = *address_as_i, assumed; // do { // assumed = old; // old = ::atomicCAS(address_as_i, assumed, // __double_as_longlong(::fmaxf(val, __longlong_as_double(assumed)))); // } while (assumed != old); // return __longlong_as_double(old); //} // //__global__ void posvis_tiled_init_krnl64( // struct par_t *dpar, // struct pos_t **pos, // double4 *ijminmax_overall, // double3 *oa, // double3 *usrc, // int *outbndarr, // int c, // int start, // int src, // int size, // int set, // int src_override) { // // /* nfrm_alloc-threaded */ // int f = blockIdx.x * blockDim.x + threadIdx.x + start; // // if (f < size) { // if (f == start) { // posvis_tiled_outbnd = 0; // posvis_tiled_smooth = dpar->pos_smooth; // if (src_override) posvis_tiled_smooth = 0; // } // ijminmax_overall[f].w = ijminmax_overall[f].y = HUGENUMBER; // ijminmax_overall[f].x = ijminmax_overall[f].z = -HUGENUMBER; // pos[f]->posbnd_logfactor = 0.0; // // dev_mtrnsps2(oa, pos[f]->ae, f); // if (src) { // /* We're viewing the model from the sun: at the center of each pixel // * in the projected view, we want cos(incidence angle), distance from // * the COM towards the sun, and the facet number. */ // dev_mmmul2(oa, pos[f]->se, oa, f); /* oa takes ast into sun coords */ // } else { // /* We're viewing the model from Earth: at the center of each POS pixel // * we want cos(scattering angle), distance from the COM towards Earth, // * and the facet number. For bistatic situations (lightcurves) we also // want cos(incidence angle) and the unit vector towards the source. */ // dev_mmmul2(oa, pos[f]->oe, oa, f); /* oa takes ast into obs coords */ // if (pos[f]->bistatic) { // usrc[f].x = usrc[f].y = 0.0; /* unit vector towards source */ // usrc[f].z = 1.0; // dev_cotrans1(&usrc[f], pos[f]->se, usrc[f], -1); // dev_cotrans1(&usrc[f], pos[f]->oe, usrc[f], 1); /* in observer coordinates */ // } // } // outbndarr[f] = 0; // } //} // //__global__ void transform_facet_normals_krnl64a( // struct mod_t *dmod, // struct pos_t **pos, // struct vertices_t **verts, // double4 *ijminmax_overall, // double3 orbit_offs, // double3 *oa, // double3 *usrc, // int *outbndarr, // int nf, // int frm, // int src, // int blockSize) //{ // /* This kernel launches 256 threads, performs a grid-stride loop through // * all model facets and transforms each facet normal with oa[frm] and stores // * the result back to dmod if n.z > 0.0. It also determines and stores the // * facet and global model bounding box via i1,i2,j1,j2 and xlim/ylim. // * These quantities are stored in pos_facet_t structures inside each frame's // * pos. */ // // /* Declare kernel variables */ // __shared__ int pn; // __shared__ double kmpxl; // int imin, jmin, imax, jmax, i1, i2, j1, j2; // int3 fidx; // double imin_dbl, jmin_dbl, imax_dbl, jmax_dbl; // double3 n, v0, v1, v2; // // /* Initialize the shared variables (accessed by every thread) */ // if (threadIdx.x==0) { // pn = pos[frm]->n; // kmpxl = pos[frm]->km_per_pixel; // } // __syncthreads(); // // /* Do a grid-stride loop on all facets */ // for (int f=threadIdx.x; f<nf; f+=blockSize) { // /* Get vertex indices of the three vertices making up the facet */ // fidx.x = verts[0]->f[f].v[0]; fidx.y = verts[0]->f[f].v[1]; // fidx.z = verts[0]->f[f].v[2]; // // /* Copy each vertex over to thread register memory */ // v0.x = verts[0]->v[fidx.x].x[0]; v0.y = verts[0]->v[fidx.x].x[1]; // v0.z = verts[0]->v[fidx.x].x[2]; v1.x = verts[0]->v[fidx.y].x[0]; // v1.y = verts[0]->v[fidx.y].x[1]; v1.z = verts[0]->v[fidx.y].x[2]; // v2.x = verts[0]->v[fidx.z].x[0]; v2.y = verts[0]->v[fidx.z].x[1]; // v2.z = verts[0]->v[fidx.z].x[2]; // // /* Get the normal to this facet in body-fixed (asteroid) coordinates // * and convert it to observer coordinates */ // n.x = verts[0]->f[f].n[0]; // n.y = verts[0]->f[f].n[1]; // n.z = verts[0]->f[f].n[2]; // dev_cotrans3(&n, oa, n, 1, frm); // // /* Check if this facet is visible - is the facet normal pointing // * roughly at the observer? */ // if (n.z > 0.0) { // /* First, store the transformed normal back to the model and increase // * visible facet counter */ // pos[frm]->facet[f].nt.x = n.x; // pos[frm]->facet[f].nt.y = n.y; // pos[frm]->facet[f].nt.z = n.z; // /* Convert the 3 vertex coordinates from body to observer // * coordinates; orbit_offset is the center-of-mass offset // * (in observer coordinates) for this model at this frame's // * epoch due to orbital motion, in case the model is half of // * a binary system. */ // dev_cotrans3(&v0, oa, v0, 1, frm); // dev_cotrans3(&v1, oa, v1, 1, frm); // dev_cotrans3(&v2, oa, v2, 1, frm); // v0.x += orbit_offs.x; v0.y += orbit_offs.x; v0.z += orbit_offs.x; // v1.x += orbit_offs.y; v1.y += orbit_offs.y; v1.z += orbit_offs.y; // v2.x += orbit_offs.z; v2.y += orbit_offs.z; v2.z += orbit_offs.z; // // /* Find rectangular region (in POS pixels) containing the projected // * facet - use floats in case model has illegal parameters and the // * pixel numbers exceed the limits for valid integers */ // imin_dbl = floor(MIN(v0.x,MIN(v1.x,v2.x)) / kmpxl - SMALLVAL + 0.5); // imax_dbl = floor(MAX(v0.x,MAX(v1.x,v2.x)) / kmpxl + SMALLVAL + 0.5); // jmin_dbl = floor(MIN(v0.y,MIN(v1.y,v2.y)) / kmpxl - SMALLVAL + 0.5); // jmax_dbl = floor(MAX(v0.y,MAX(v1.y,v2.y)) / kmpxl + SMALLVAL + 0.5); // // imin = (imin_dbl < INT_MIN) ? INT_MIN : (int) imin_dbl; // imax = (imax_dbl > INT_MAX) ? INT_MAX : (int) imax_dbl; // jmin = (jmin_dbl < INT_MIN) ? INT_MIN : (int) jmin_dbl; // jmax = (jmax_dbl > INT_MAX) ? INT_MAX : (int) jmax_dbl; // // /* Set the outbnd flag if the facet extends beyond the POS window */ // if ((imin < (-pn)) || (imax > pn) || (jmin < (-pn)) || (jmax > pn)) { // posvis_tiled_outbnd = 1; // atomicExch(&outbndarr[frm], 1); // } // // /* Figure out if facet projects at least partly within POS window; // * if it does, look at each "contained" POS pixel and get the // * z-coordinate and cos(scattering angle) */ // i1 = MAX(imin, -pn); i2 = MIN(imax, pn); // j1 = MAX(jmin, -pn); j2 = MIN(jmax, pn); // // pos[frm]->facet[f].ilim.x = i1; // pos[frm]->facet[f].ilim.y = i2; // pos[frm]->facet[f].jlim.x = j1; // pos[frm]->facet[f].jlim.y = j2; // pos[frm]->facet[f].v0t = v0; // pos[frm]->facet[f].v1t = v1; // pos[frm]->facet[f].v2t = v2; // // /* Now keep track of the global region */ // if (i1 > pn || i2 < -pn || j1 > pn || j2 < -pn) { // /* Facet is entirely outside POS frame: just track POS region */ // dev_POSrect_gpu64(pos, src, imin_dbl, imax_dbl, jmin_dbl, // jmax_dbl, ijminmax_overall, frm); // // } else { // dev_POSrect_gpu64(pos, src, (double)i1, (double)i2, // (double)j1, (double)j2, ijminmax_overall, frm); // } // } // else { // /* The following makes a check in the bin_facets_krnl64 kernel easier */ // pos[frm]->facet[f].nt.x = -1.0; // pos[frm]->facet[f].nt.y = -1.0; // pos[frm]->facet[f].nt.z = -1.0; // } // } //} // //__global__ void transform_facet_normals_krnl64b( // struct mod_t *dmod, // struct pos_t **pos, // struct vertices_t **verts, // double4 *ijminmax_overall, // double3 orbit_offs, // double3 *oa_gm, // int *outbndarr, // int nf, // int src) //{ // /* This kernel launches nframes blocks of threads, performs a grid-stride loop through // * all model facets and transforms each facet normal with oa[frm] and stores // * the result back to dmod if n.z > 0.0. It also determines and stores the // * facet and global model bounding box via i1,i2,j1,j2 and xlim/ylim. // * These quantities are stored in pos_facet_t structures inside each frame's // * pos. This kernel also uses shared memory for ijminmax_overall_sh, used // * as temporary (faster) storage for pos window calculation. Additionally, // * the pos->xlim/ylim atomic operations have been moved to the very end of // * this kernel to be processed just once instead of for every facet. */ // // /* Declare kernel variables */ // __shared__ int pn; // __shared__ double kmpxl, oa_sh[3][3]; // __shared__ double4 ijminmax_overall_sh; // int frm=blockIdx.x, imin, jmin, imax, jmax, i1, i2, j1, j2; // int3 fidx; // double imin_dbl, jmin_dbl, imax_dbl, jmax_dbl; // double3 n, v0, v1, v2; // // /* Initialize the shared variables (accessed by every thread) */ // if (threadIdx.x==0) { // pn = pos[frm]->n; // kmpxl = pos[frm]->km_per_pixel; // ijminmax_overall_sh.w = ijminmax_overall_sh.x = // ijminmax_overall_sh.y = ijminmax_overall_sh.z = 0.0f; // // /* Load oa for this frame into shared memory */ // oa_sh[0][0] = oa_gm[3*frm].x; oa_sh[0][1] = oa_gm[3*frm].y; oa_sh[0][2] = oa_gm[3*frm].z; // oa_sh[1][0] = oa_gm[3*frm+1].x; oa_sh[1][1] = oa_gm[3*frm+1].y; oa_sh[1][2] = oa_gm[3*frm+1].z; // oa_sh[2][0] = oa_gm[3*frm+2].x; oa_sh[2][1] = oa_gm[3*frm+2].y; oa_sh[2][2] = oa_gm[3*frm+2].z; // } // __syncthreads(); // // /* Do a grid-stride loop on all facets */ // for (int f=threadIdx.x; f<nf; f+=blockDim.x) { // /* Get vertex indices of the three vertices making up the facet */ // fidx.x = verts[0]->f[f].v[0]; fidx.y = verts[0]->f[f].v[1]; // fidx.z = verts[0]->f[f].v[2]; // // /* Copy each vertex over to thread register memory */ // v0.x = verts[0]->v[fidx.x].x[0]; v0.y = verts[0]->v[fidx.x].x[1]; // v0.z = verts[0]->v[fidx.x].x[2]; v1.x = verts[0]->v[fidx.y].x[0]; // v1.y = verts[0]->v[fidx.y].x[1]; v1.z = verts[0]->v[fidx.y].x[2]; // v2.x = verts[0]->v[fidx.z].x[0]; v2.y = verts[0]->v[fidx.z].x[1]; // v2.z = verts[0]->v[fidx.z].x[2]; // // /* Get the normal to this facet in body-fixed (asteroid) coordinates // * and convert it to observer coordinates */ // n.x = verts[0]->f[f].n[0]; // n.y = verts[0]->f[f].n[1]; // n.z = verts[0]->f[f].n[2]; // dev_cotrans1(&n, oa_sh, n, 1); // // /* Check if this facet is visible - is the facet normal pointing // * roughly at the observer? */ // if (n.z > 0.0) { // /* First, store the transformed normal back to the model and increase // * visible facet counter */ // pos[frm]->facet[f].nt.x = n.x; // pos[frm]->facet[f].nt.y = n.y; // pos[frm]->facet[f].nt.z = n.z; // /* Convert the 3 vertex coordinates from body to observer // * coordinates; orbit_offset is the center-of-mass offset // * (in observer coordinates) for this model at this frame's // * epoch due to orbital motion, in case the model is half of // * a binary system. */ // dev_cotrans1(&v0, oa_sh, v0, 1); // dev_cotrans1(&v1, oa_sh, v1, 1); // dev_cotrans1(&v2, oa_sh, v2, 1); // v0.x += orbit_offs.x; v0.y += orbit_offs.x; v0.z += orbit_offs.x; // v1.x += orbit_offs.y; v1.y += orbit_offs.y; v1.z += orbit_offs.y; // v2.x += orbit_offs.z; v2.y += orbit_offs.z; v2.z += orbit_offs.z; // // /* Find rectangular region (in POS pixels) containing the projected // * facet - use floats in case model has illegal parameters and the // * pixel numbers exceed the limits for valid integers */ // imin_dbl = floor(MIN(v0.x,MIN(v1.x,v2.x)) / kmpxl - SMALLVAL + 0.5); // imax_dbl = floor(MAX(v0.x,MAX(v1.x,v2.x)) / kmpxl + SMALLVAL + 0.5); // jmin_dbl = floor(MIN(v0.y,MIN(v1.y,v2.y)) / kmpxl - SMALLVAL + 0.5); // jmax_dbl = floor(MAX(v0.y,MAX(v1.y,v2.y)) / kmpxl + SMALLVAL + 0.5); // // imin = (imin_dbl < INT_MIN) ? INT_MIN : (int) imin_dbl; // imax = (imax_dbl > INT_MAX) ? INT_MAX : (int) imax_dbl; // jmin = (jmin_dbl < INT_MIN) ? INT_MIN : (int) jmin_dbl; // jmax = (jmax_dbl > INT_MAX) ? INT_MAX : (int) jmax_dbl; // // /* Set the outbnd flag if the facet extends beyond the POS window */ // if ((imin < (-pn)) || (imax > pn) || (jmin < (-pn)) || (jmax > pn)) { // posvis_tiled_outbnd = 1; // atomicExch(&outbndarr[frm], 1); // } // // /* Figure out if facet projects at least partly within POS window; // * if it does, look at each "contained" POS pixel and get the // * z-coordinate and cos(scattering angle) */ // i1 = MAX(imin, -pn); i2 = MIN(imax, pn); // j1 = MAX(jmin, -pn); j2 = MIN(jmax, pn); // // pos[frm]->facet[f].ilim.x = i1; // pos[frm]->facet[f].ilim.y = i2; // pos[frm]->facet[f].jlim.x = j1; // pos[frm]->facet[f].jlim.y = j2; // pos[frm]->facet[f].v0t = v0; // pos[frm]->facet[f].v1t = v1; // pos[frm]->facet[f].v2t = v2; // // /* Now keep track of the global region */ // if (i1 > pn || i2 < -pn || j1 > pn || j2 < -pn) { // /* Facet is entirely outside POS frame: just track POS region */ // dev_POSrect_gpu64_shared(imin_dbl,imax_dbl, jmin_dbl,jmax_dbl, // &ijminmax_overall_sh, pn); // // } else { // dev_POSrect_gpu64_shared((double)i1, (double)i2, // (double)j1, (double)j2, &ijminmax_overall_sh, pn); // } // } // else { // /* The following makes a check in the bin_facets_krnl64 kernel easier */ //// pos[frm]->facet[f].nt.x = -1.0; //// pos[frm]->facet[f].nt.y = -1.0; //// pos[frm]->facet[f].nt.z = -1.0; // } // } // __syncthreads(); // // /* Now write the POS frame window limits from shared mem back to global mem */ // if (threadIdx.x==0) { // ijminmax_overall[frm].w = ijminmax_overall_sh.w; // ijminmax_overall[frm].x = ijminmax_overall_sh.x; // ijminmax_overall[frm].y = ijminmax_overall_sh.y; // ijminmax_overall[frm].z = ijminmax_overall_sh.z; // // /* Update the subset of the POS frame that contains the target */ // /* imin_dbl - ijminmax_overall[frm].w // * imax_dbl - ijminmax_overall[frm].x // * jmin_dbl - ijminmax_overall[frm].y // * jmax_dbl - ijminmax_overall[frm].z // */ // int imin = (ijminmax_overall_sh.w < INT_MIN) ? INT_MIN : (int) ijminmax_overall_sh.w; // int imax = (ijminmax_overall_sh.x > INT_MAX) ? INT_MAX : (int) ijminmax_overall_sh.x; // int jmin = (ijminmax_overall_sh.y < INT_MIN) ? INT_MIN : (int) ijminmax_overall_sh.y; // int jmax = (ijminmax_overall_sh.z > INT_MAX) ? INT_MAX : (int) ijminmax_overall_sh.z; // // /* Make sure it's smaller than n */ // imin = MAX(imin,-pn); // imax = MIN(imax, pn); // jmin = MAX(jmin,-pn); // jmax = MIN(jmax, pn); // // if (src) { // atomicMin(&pos[frm]->xlim2[0], imin); // atomicMax(&pos[frm]->xlim2[1], imax); // atomicMin(&pos[frm]->ylim2[0], jmin); // atomicMax(&pos[frm]->ylim2[1], jmax); // } else { // atomicMin(&pos[frm]->xlim[0], imin); // atomicMax(&pos[frm]->xlim[1], imax); // atomicMin(&pos[frm]->ylim[0], jmin); // atomicMax(&pos[frm]->ylim[1], jmax); // } // } //} // //__global__ void transform_facet_normals_krnl64c( // struct mod_t *dmod, // struct pos_t **pos, // struct vertices_t **verts, // double4 *ijminmax_overall, // double3 orbit_offs, // double3 *oa_gm, // int *outbndarr, // int nf, // int frm, // int src) //{ // /* This kernel launches 256 threads, performs a grid-stride loop through // * all model facets and transforms each facet normal with oa[frm] and stores // * the result back to dmod if n.z > 0.0. It also determines and stores the // * facet and global model bounding box via i1,i2,j1,j2 and xlim/ylim. // * These quantities are stored in pos_facet_t structures inside each frame's // * pos. This kernel also uses shared memory for ijminmax_overall_sh, used // * as temporary (faster) storage for pos window calculation. Additionally, // * the pos->xlim/ylim atomic operations have been moved to the very end of // * this kernel to be processed just once instead of for every facet. */ // // /* Declare kernel variables */ // __shared__ int pn; // __shared__ double kmpxl, oa_sh[3][3]; // __shared__ double4 ijminmax_overall_sh; // int imin, jmin, imax, jmax, i1, i2, j1, j2; // int3 fidx; // double imin_dbl, jmin_dbl, imax_dbl, jmax_dbl; // double3 n, v0, v1, v2; // // /* Initialize the shared variables (accessed by every thread) */ // if (threadIdx.x==0) { // pn = pos[frm]->n; // kmpxl = pos[frm]->km_per_pixel; // ijminmax_overall_sh.w = ijminmax_overall_sh.x = // ijminmax_overall_sh.y = ijminmax_overall_sh.z = 0.0f; // // /* Load oa for this frame into shared memory */ // oa_sh[0][0] = oa_gm[3*frm].x; oa_sh[0][1] = oa_gm[3*frm].y; oa_sh[0][2] = oa_gm[3*frm].z; // oa_sh[1][0] = oa_gm[3*frm+1].x; oa_sh[1][1] = oa_gm[3*frm+1].y; oa_sh[1][2] = oa_gm[3*frm+1].z; // oa_sh[2][0] = oa_gm[3*frm+2].x; oa_sh[2][1] = oa_gm[3*frm+2].y; oa_sh[2][2] = oa_gm[3*frm+2].z; // } // __syncthreads(); // // /* Do a grid-stride loop on all facets */ // for (int f=threadIdx.x; f<nf; f+=blockDim.x) { // /* Get vertex indices of the three vertices making up the facet */ // fidx.x = verts[0]->f[f].v[0]; fidx.y = verts[0]->f[f].v[1]; // fidx.z = verts[0]->f[f].v[2]; // // /* Copy each vertex over to thread register memory */ // v0.x = verts[0]->v[fidx.x].x[0]; v0.y = verts[0]->v[fidx.x].x[1]; // v0.z = verts[0]->v[fidx.x].x[2]; v1.x = verts[0]->v[fidx.y].x[0]; // v1.y = verts[0]->v[fidx.y].x[1]; v1.z = verts[0]->v[fidx.y].x[2]; // v2.x = verts[0]->v[fidx.z].x[0]; v2.y = verts[0]->v[fidx.z].x[1]; // v2.z = verts[0]->v[fidx.z].x[2]; // // /* Get the normal to this facet in body-fixed (asteroid) coordinates // * and convert it to observer coordinates */ // n.x = verts[0]->f[f].n[0]; // n.y = verts[0]->f[f].n[1]; // n.z = verts[0]->f[f].n[2]; // dev_cotrans1(&n, oa_sh, n, 1); // // /* Check if this facet is visible - is the facet normal pointing // * roughly at the observer? */ // if (n.z > 0.0) { // /* First, store the transformed normal back to the model and increase // * visible facet counter */ // pos[frm]->facet[f].nt.x = n.x; // pos[frm]->facet[f].nt.y = n.y; // pos[frm]->facet[f].nt.z = n.z; // /* Convert the 3 vertex coordinates from body to observer // * coordinates; orbit_offset is the center-of-mass offset // * (in observer coordinates) for this model at this frame's // * epoch due to orbital motion, in case the model is half of // * a binary system. */ // dev_cotrans1(&v0, oa_sh, v0, 1); // dev_cotrans1(&v1, oa_sh, v1, 1); // dev_cotrans1(&v2, oa_sh, v2, 1); // v0.x += orbit_offs.x; v0.y += orbit_offs.x; v0.z += orbit_offs.x; // v1.x += orbit_offs.y; v1.y += orbit_offs.y; v1.z += orbit_offs.y; // v2.x += orbit_offs.z; v2.y += orbit_offs.z; v2.z += orbit_offs.z; // // /* Find rectangular region (in POS pixels) containing the projected // * facet - use floats in case model has illegal parameters and the // * pixel numbers exceed the limits for valid integers */ // imin_dbl = floor(MIN(v0.x,MIN(v1.x,v2.x)) / kmpxl - SMALLVAL + 0.5); // imax_dbl = floor(MAX(v0.x,MAX(v1.x,v2.x)) / kmpxl + SMALLVAL + 0.5); // jmin_dbl = floor(MIN(v0.y,MIN(v1.y,v2.y)) / kmpxl - SMALLVAL + 0.5); // jmax_dbl = floor(MAX(v0.y,MAX(v1.y,v2.y)) / kmpxl + SMALLVAL + 0.5); // // imin = (imin_dbl < INT_MIN) ? INT_MIN : (int) imin_dbl; // imax = (imax_dbl > INT_MAX) ? INT_MAX : (int) imax_dbl; // jmin = (jmin_dbl < INT_MIN) ? INT_MIN : (int) jmin_dbl; // jmax = (jmax_dbl > INT_MAX) ? INT_MAX : (int) jmax_dbl; // // /* Set the outbnd flag if the facet extends beyond the POS window */ // if ((imin < (-pn)) || (imax > pn) || (jmin < (-pn)) || (jmax > pn)) { // posvis_tiled_outbnd = 1; // atomicExch(&outbndarr[frm], 1); // } // // /* Figure out if facet projects at least partly within POS window; // * if it does, look at each "contained" POS pixel and get the // * z-coordinate and cos(scattering angle) */ // i1 = MAX(imin, -pn); i2 = MIN(imax, pn); // j1 = MAX(jmin, -pn); j2 = MIN(jmax, pn); // // pos[frm]->facet[f].ilim.x = i1; // pos[frm]->facet[f].ilim.y = i2; // pos[frm]->facet[f].jlim.x = j1; // pos[frm]->facet[f].jlim.y = j2; // pos[frm]->facet[f].v0t = v0; // pos[frm]->facet[f].v1t = v1; // pos[frm]->facet[f].v2t = v2; // // /* Now keep track of the global region */ // if (i1 > pn || i2 < -pn || j1 > pn || j2 < -pn) { // /* Facet is entirely outside POS frame: just track POS region */ // dev_POSrect_gpu64_shared(imin_dbl,imax_dbl, jmin_dbl,jmax_dbl, // &ijminmax_overall_sh, pn); // // } else { // dev_POSrect_gpu64_shared((double)i1, (double)i2, // (double)j1, (double)j2, &ijminmax_overall_sh, pn); // } // } // else { // /* The following makes a check in the bin_facets_krnl64 kernel easier */ // pos[frm]->facet[f].nt.x = -1.0; // pos[frm]->facet[f].nt.y = -1.0; // pos[frm]->facet[f].nt.z = -1.0; // } // } // __syncthreads(); // // /* Now write the POS frame window limits from shared mem back to global mem */ // if (threadIdx.x==0) { // ijminmax_overall[frm].w = ijminmax_overall_sh.w; // ijminmax_overall[frm].x = ijminmax_overall_sh.x; // ijminmax_overall[frm].y = ijminmax_overall_sh.y; // ijminmax_overall[frm].z = ijminmax_overall_sh.z; // // /* Update the subset of the POS frame that contains the target */ // /* imin_dbl - ijminmax_overall[frm].w // * imax_dbl - ijminmax_overall[frm].x // * jmin_dbl - ijminmax_overall[frm].y // * jmax_dbl - ijminmax_overall[frm].z // */ // int imin = (ijminmax_overall_sh.w < INT_MIN) ? INT_MIN : (int) ijminmax_overall_sh.w; // int imax = (ijminmax_overall_sh.x > INT_MAX) ? INT_MAX : (int) ijminmax_overall_sh.x; // int jmin = (ijminmax_overall_sh.y < INT_MIN) ? INT_MIN : (int) ijminmax_overall_sh.y; // int jmax = (ijminmax_overall_sh.z > INT_MAX) ? INT_MAX : (int) ijminmax_overall_sh.z; // // /* Make sure it's smaller than n */ // imin = MAX(imin,-pn); // imax = MIN(imax, pn); // jmin = MAX(jmin,-pn); // jmax = MIN(jmax, pn); // // if (src) { // atomicMin(&pos[frm]->xlim2[0], imin); // atomicMax(&pos[frm]->xlim2[1], imax); // atomicMin(&pos[frm]->ylim2[0], jmin); // atomicMax(&pos[frm]->ylim2[1], jmax); // } else { // atomicMin(&pos[frm]->xlim[0], imin); // atomicMax(&pos[frm]->xlim[1], imax); // atomicMin(&pos[frm]->ylim[0], jmin); // atomicMax(&pos[frm]->ylim[1], jmax); // } // } //} // //__global__ void bin_facets_krnl64a(struct pos_t **pos, // struct vertices_t **verts, // int ***facet_index, // int **entries, // int nf, // int frm, // int *n_tiles, // int *n_tiles_x, // int *n_tiles_y, // int tile_size) //{ // /* This kernel is responsible for binning visible model facets according to // * which screen tile they appear on. Each facet can belong to 1, 2, or 4 // * different facets. (If the size of individual triangles should exceed // * the tile size, this is no longer true.) // * The kernel version has just one thread block with 1024 threads. It uses a grid- // * stride loop to cover all facets // */ // int f, current_i, next_i, current_j, next_j, i1, i2, j1, j2, bi, bin, old_indx; // __shared__ int2 xlim, ylim; /* These are the global pos limits */ // extern __shared__ int addr_index[]; /* Used for the facet_index entries */ // // /* Initialize shared variables that will be accessed by every thread */ // if (threadIdx.x==0) { // xlim.x = pos[frm]->xlim[0]; // xlim.y = pos[frm]->xlim[1]; // ylim.x = pos[frm]->ylim[0]; // ylim.y = pos[frm]->ylim[1]; // for (bin=0; bin<n_tiles[frm]; bin++) // addr_index[bin] = 0; // } // __syncthreads(); // // /* Do grid-stride loop through all facets in model */ // for (f=threadIdx.x; f<nf; f+=blockDim.x) { // /* Weed out any facets not visible to observer */ // if (pos[frm]->facet[f].nt.z > 0.0) { // bi = 0; /* Bin index for the four facet bin entries*/ // /* Copy facet limits into register memory for faster access */ // i1 = pos[frm]->facet[f].ilim.x; // i2 = pos[frm]->facet[f].ilim.y; // j1 = pos[frm]->facet[f].jlim.x; // j2 = pos[frm]->facet[f].jlim.y; // // /* Now check where the current facet lies, stepping through each // * tile */ // for (int k=0; k<n_tiles_y[frm]; k++) { // current_j = ylim.x + k * tile_size; // next_j = current_j + tile_size; // for (int n=0; n<n_tiles_x[frm]; n++) { // bin = k*n_tiles_x[frm] + n; // current_i = xlim.x + n * tile_size; // next_i = current_i + tile_size; // // /* If i1 or i2 AND j1 or j2 fall into this tile, register it */ // if ((i1>=current_i && i1<next_i) || (i2>=current_i && i2<next_i)) { // if ((j1>=current_j && j1<next_j) || (j2>=current_j && j2<next_j)) { // pos[frm]->facet[f].bin[bi] = bin; // old_indx = atomicAdd(&addr_index[bin], 1); // facet_index[frm][bin][old_indx] = f; // atomicAdd(&entries[frm][bin], 1); // bi++; // } // } // } // } // } // } //} // //__global__ void bin_facets_krnl64b(struct pos_t **pos, // struct vertices_t **verts, // int ***facet_index, // int **entries, // int **addr_index, // int nf, // int frm, // int *n_tiles, // int *n_tiles_x, // int *n_tiles_y, // int tile_size) //{ // /* This kernel is responsible for binning visible model facets according to // * which screen tile they appear on. Each facet can belong to 1, 2, or 4 // * different facets. (If the size of individual triangles should exceed // * the tile size, this is no longer true.) // * The kernel version uses nf-threads with as many thread blocks as it // * takes, considering the previously defined maxThreadsPerBlock. Because of // * this, the addr_index array is in global memory (instead of shared). */ // // int f, current_i, next_i, current_j, next_j, i1, i2, j1, j2, bi, bin, old_indx; // __shared__ int2 xlim, ylim; /* These are the global pos limits */ // // f = blockDim.x * blockIdx.x + threadIdx.x; // // /* Initialize shared variables that will be accessed by every thread */ // if (threadIdx.x==0) { // xlim.x = pos[frm]->xlim[0]; // xlim.y = pos[frm]->xlim[1]; // ylim.x = pos[frm]->ylim[0]; // ylim.y = pos[frm]->ylim[1]; //// for (bin=0; bin<n_tiles[frm]; bin++) //// addr_index[frm][bin] = 0; // } // __syncthreads(); // // /* Do grid-stride loop through all facets in model */ // if (f < nf) { // /* Weed out any facets not visible to observer */ // if (pos[frm]->facet[f].nt.z > 0.0) { // bi = 0; /* Bin index for the four facet bin entries*/ // /* Copy facet limits into register memory for faster access */ // i1 = pos[frm]->facet[f].ilim.x; // i2 = pos[frm]->facet[f].ilim.y; // j1 = pos[frm]->facet[f].jlim.x; // j2 = pos[frm]->facet[f].jlim.y; // // /* Now check where the current facet lies, stepping through each // * tile */ // for (int k=0; k<n_tiles_y[frm]; k++) { // current_j = ylim.x + k * tile_size; // next_j = current_j + tile_size; // for (int n=0; n<n_tiles_x[frm]; n++) { // bin = k*n_tiles_x[frm] + n; // current_i = xlim.x + n * tile_size; // next_i = current_i + tile_size; // // /* If i1 or i2 AND j1 or j2 fall into this tile, register it */ // if ((i1>=current_i && i1<next_i) || (i2>=current_i && i2<next_i)) { // if ((j1>=current_j && j1<next_j) || (j2>=current_j && j2<next_j)) { // pos[frm]->facet[f].bin[bi] = bin; // old_indx = atomicAdd(&addr_index[frm][bin], 1); // facet_index[frm][bin][old_indx] = f; // atomicAdd(&entries[frm][bin], 1); // bi++; // } // } // } // } // } // } //} // //__global__ void bin_facets_krnl64c(struct pos_t **pos, // struct vertices_t **verts, // int ***facet_index, // int **entries, // int nf, // int *n_tiles, // int *n_tiles_x, // int *n_tiles_y, // int tile_size) //{ // /* This kernel is responsible for binning visible model facets according to // * which screen tile they appear on. Each facet can belong to 1, 2, or 4 // * different facets. (If the size of individual triangles should exceed // * the tile size, this is no longer true.) // * The kernel version uses nframes-thread blocks to cover all frames in one // * go. Each block has its own __shared___ addr_index array and each of them // * uses a grid-stride loop to cover all facets // */ // int f, frm, current_i, next_i, current_j, next_j, i1, i2, j1, j2, bi, bin, old_indx; // __shared__ int2 xlim, ylim; /* These are the global pos limits */ // __shared__ int addr_index[160]; /* This allows for 40x40 tiles (at 32x32 // tile size, allowing for a maximum POS resolution of 1280x1280 pixels */ // frm = blockIdx.x; // // /* Initialize shared variables that will be accessed by every thread */ // if (threadIdx.x==0) { // xlim.x = pos[frm]->xlim[0]; // xlim.y = pos[frm]->xlim[1]; // ylim.x = pos[frm]->ylim[0]; // ylim.y = pos[frm]->ylim[1]; // for (bin=0; bin<n_tiles[frm]; bin++) // addr_index[bin] = 0; // } // __syncthreads(); // // /* Do grid-stride loop through all facets in model */ // for (f=threadIdx.x; f<nf; f+=blockDim.x) { // /* Weed out any facets not visible to observer */ // if (pos[frm]->facet[f].nt.z > 0.0) { // bi = 0; /* Bin index for the four facet bin entries*/ // /* Copy facet limits into register memory for faster access */ // i1 = pos[frm]->facet[f].ilim.x; // i2 = pos[frm]->facet[f].ilim.y; // j1 = pos[frm]->facet[f].jlim.x; // j2 = pos[frm]->facet[f].jlim.y; // // /* Now check where the current facet lies, stepping through each // * tile */ // for (int k=0; k<n_tiles_y[frm]; k++) { // current_j = ylim.x + k * tile_size; // next_j = current_j + tile_size; // for (int n=0; n<n_tiles_x[frm]; n++) { // bin = k*n_tiles_x[frm] + n; // current_i = xlim.x + n * tile_size; // next_i = current_i + tile_size; // // /* If i1 or i2 AND j1 or j2 fall into this tile, register it */ // if ((i1>=current_i && i1<next_i) || (i2>=current_i && i2<next_i)) { // if ((j1>=current_j && j1<next_j) || (j2>=current_j && j2<next_j)) { // pos[frm]->facet[f].bin[bi] = bin; // old_indx = atomicAdd(&addr_index[bin], 1); // facet_index[frm][bin][old_indx] = f; // atomicAdd(&entries[frm][bin], 1); // bi++; // } // } // } // } // } // } //} // //__global__ void radar_raster_krnl64(struct pos_t **pos, // struct vertices_t **verts, // double3 *oa_gm, // int ***facet_index, // int **entries, // int nf, // int frm, // int *n_tiles, // int *n_tiles_x, // int *n_tiles_y, // int tile_size, // int tile_x) { // // /* This kernel performs the rasterization tile by tile. Each thread block // * is responsible for one tile. */ // /* Determine which tile this thread block is responsible for and // * which element of the thread block this thread is. */ // int bin = blockIdx.x; // int index = threadIdx.x; // // /* Declare the shared memory variables and others */ // __shared__ double pos_z[32][32];//[55][55]; /* One per thread block */ // __shared__ double pos_cose[32][32];//[55][55]; /* One per thread block */ // __shared__ int2 bn; // __shared__ int xlim, ylim, offsetx, offsety; // __shared__ double kmpxl; // __shared__ double oa_sh[3][3]; // int i, j, ig, jg, i1, i2, j1, j2; /* ig,jg are global indices */ // int tile_i1, tile_i2, tile_j1, tile_j2, fct_indx; // double3 v0, v1, v2, n, tv0, tv1, tv2, n1n0; // int3 fidx; // // /* Initialize the shared memory arrays with grid-stride loop */ // for (int index=threadIdx.x; index<tile_size; index+=blockDim.x) { // i = index % tile_x; // j = index / tile_x; // pos_z[i][j] = -1e20; // pos_cose[i][j] = 0.0; // } // __syncthreads(); // // /* Load variables used by every thread (per block) to shared memory for // * faster access */ // if (threadIdx.x==0) { // xlim = pos[frm]->xlim[0]; // ylim = pos[frm]->ylim[0]; // kmpxl = pos[frm]->km_per_pixel; // bn.x = bin % n_tiles_x[frm]; // bn.y = bin / n_tiles_x[frm]; // // /* Calculate the pixel offsets needed to go back and forth between // * tiled POS space for this block's tile and global POS space */ // offsetx = xlim + tile_x * bn.x; // offsety = ylim + tile_x * bn.y; // // /* Load oa for this frame into shared memory */ // if (posvis_tiled_smooth) { // oa_sh[0][0] = oa_gm[3*frm].x; oa_sh[0][1] = oa_gm[3*frm].y; oa_sh[0][2] = oa_gm[3*frm].z; // oa_sh[1][0] = oa_gm[3*frm+1].x; oa_sh[1][1] = oa_gm[3*frm+1].y; oa_sh[1][2] = oa_gm[3*frm+1].z; // oa_sh[2][0] = oa_gm[3*frm+2].x; oa_sh[2][1] = oa_gm[3*frm+2].y; oa_sh[2][2] = oa_gm[3*frm+2].z; // } // // } // __syncthreads(); // // /* Using grid-stride loop, step through all facet entries for each bin where // * each thread block is responsible for one bin/tile */ // for (index=threadIdx.x; index<entries[frm][bin]; index+=blockDim.x) { // // /* Load facet index into registers */ // fct_indx = facet_index[frm][bin][index]; // // /* Load transformed facet vertices into registers */ // v0 = pos[frm]->facet[fct_indx].v0t; // v1 = pos[frm]->facet[fct_indx].v1t; // v2 = pos[frm]->facet[fct_indx].v2t; // n = pos[frm]->facet[fct_indx].nt; // // /* Calculate and store the boundaries of this tile */ // tile_i1 = offsetx; // tile_i2 = tile_i1 + tile_x; // tile_j1 = offsety; // tile_j2 = tile_j1 + tile_x; // // /* Load this facet's boundaries and clamp them if needed, then // * convert to local shared memory array addressing */ // i1 = max(pos[frm]->facet[fct_indx].ilim.x, tile_i1); // i2 = min(pos[frm]->facet[fct_indx].ilim.y, (tile_i2-1)); // j1 = max(pos[frm]->facet[fct_indx].jlim.x, tile_j1); // j2 = min(pos[frm]->facet[fct_indx].jlim.y, (tile_j2-1)); // // /* Precalculate s and t components for the pixel loop */ // double a, b, c, d, e, h, ti, tj, si, sj, si0, sj0, ti0, tj0, sz, tz, den, s, t, z, old; // a = i1*kmpxl - v0.x; // b = v2.y - v1.y; // c = v2.x - v1.x; // d = j1*kmpxl - v0.y; // e = v1.x - v0.x; // h = v1.y - v0.y; // den = e*b - c*h; // ti = -h*kmpxl/den; // tj = e*kmpxl/den; // si = b*kmpxl/den; // sj = -c*kmpxl/den; // si0 = (a*b - c*d)/den; // ti0 = (e*d -a*h)/den; // sz = v1.z - v0.z; // tz = v2.z - v1.z; // // /* Now convert i1, i2, j1, j2 to shared-memory tile coordinates */ // i1 -= (offsetx); // i2 -= (offsetx); // j1 -= (offsety); // j2 -= (offsety); // // /* Pre-calculate some quantities for cosine smoothing if enabled */ // if (posvis_tiled_smooth) { // /* Assign temp. normal components as float3 */ // fidx.x = verts[0]->f[fct_indx].v[0]; // fidx.y = verts[0]->f[fct_indx].v[1]; // fidx.z = verts[0]->f[fct_indx].v[2]; // // tv0.x = verts[0]->v[fidx.x].n[0]; tv0.y = verts[0]->v[fidx.x].n[1]; // tv0.z = verts[0]->v[fidx.x].n[2]; tv1.x = verts[0]->v[fidx.y].n[0]; // tv1.y = verts[0]->v[fidx.y].n[1]; tv1.z = verts[0]->v[fidx.y].n[2]; // tv2.x = verts[0]->v[fidx.z].n[0]; tv2.y = verts[0]->v[fidx.z].n[1]; // tv2.z = verts[0]->v[fidx.z].n[2]; // n1n0.x = tv1.x - tv0.x; n1n0.y = tv1.y - tv0.y; n1n0.z = tv1.z - tv0.z; // tv2.x -= tv1.x; tv2.y -= tv1.y; tv2.z -= tv1.z; // } // // /* Facet is at least partly within POS frame: find all POS // * pixels whose centers project onto this facet */ // for (i=i1; i<=i2; i++) { // // sj0 = si0; /* Initialize this loop's base sj0, tj0 */ // tj0 = ti0; // // for (j=j1; j<=j2; j++) { // // /* Calculate s and t parameters */ // s = sj0; // t = tj0; // // if ((s >= -SMALLVAL) && (s <= 1.0 + SMALLVAL)) {// && // // if( (t >= -SMALLVAL) && (t <= s + SMALLVAL)) { // // /* Compute z-coordinate of pixel center: its // * distance measured from the origin towards // * Earth. */ // z = v0.z + s*sz + t*tz; // // /* Compare calculated z to stored shared memory z // * array at this address and store the bigger value */ // old = atomicMax64(&pos_z[i][j], z); // // if (old < z){ // // if (posvis_tiled_smooth) { // /* Get pvs_smoothed version of facet unit // * normal: Take the linear combination // * of the three vertex normals; trans- // * form from body to observer coordina- // * tes; and make sure that it points // * somewhat in our direction. */ // n.x = tv0.x + s * n1n0.x + t * tv2.x; // n.y = tv0.y + s * n1n0.y + t * tv2.y; // n.z = tv0.z + s * n1n0.z + t * tv2.z; // dev_cotrans1(&n, oa_sh, n, 1); //// dev_cotrans3(&n, oa_gm, n, 1, frm); // dev_normalize3(&n); // } // // /* Determine scattering angles. */ // if (n.z > 0.0) { // atomicExch((unsigned long long int*)&pos_cose[i][j], // __double_as_longlong(n.z)); // } // /* Keeping track of facets may not be required. */ //// atomicExch(&pos[frm]->f[i][j], f); // // } /* end if (no other facet yet blocks this facet from view) */ // } /* end if 0 <= t <= s (facet center is "in" this POS pixel) */ // } /* end if 0 <= s <= 1 */ // // sj0 += sj; // tj0 += tj; // } /* end j-loop over POS rows */ // /* Modify s and t step-wise for the next i-iteration of the pixel loop */ // si0 += si; // ti0 += ti; // // } /* end i-loop over POS columns */ // } // __syncthreads(); // // /* Now write the shared memory array tiles into the global memory z buffer // * and cosine array, again with a block-stride loop */ // if (facet_index[frm][bin][0]!=0) // for (int index=threadIdx.x; index<tile_size; index+=blockDim.x) { // i = index % tile_x; // j = index / tile_x; // ig = i + offsetx; // jg = j + offsety; // if (pos_z[i][j]!=-1e20) // pos[frm]->z[ig][jg] = pos_z[i][j]; // if (pos_cose[i][j]!=0.0) // pos[frm]->cose[ig][jg] = pos_cose[i][j]; // } // __syncthreads(); //} // //__global__ void lightcurve_raster_krnl64(struct pos_t **pos, // struct vertices_t **verts, // double3 *oa, // double3 *usrc, // int ***facet_index, // int **entries, // int nf, // int frm, // int *n_tiles, // int *n_tiles_x, // int *n_tiles_y, // int tile_size, // int tile_x, // int src) { // // /* This kernel performs the rasterization tile by tile. Each thread block // * is responsible for one tile. */ // /* Determine which tile this thread block is responsible for and // * which element of the thread block this thread is. */ // int bin = blockIdx.x; // int index = threadIdx.x; // // /* Declare the shared memory variables and others */ // __shared__ double pos_z[32][32];//[55][55]; /* One per thread block */ // __shared__ double pos_cose[32][32];//[55][55]; /* One per thread block */ // __shared__ double pos_cosi[32][32]; // __shared__ int2 bn; // __shared__ int xlim, ylim, offsetx, offsety, bistatic; // __shared__ double kmpxl; // int i, j, ig, jg, i1, i2, j1, j2; /* ig,jg are global indices */ // int tile_i1, tile_i2, tile_j1, tile_j2, fct_indx; // double3 v0, v1, v2, n, tv0, tv1, tv2, n1n0; // int3 fidx; // // /* Initialize the shared memory arrays with grid-stride loop */ // for (int index=threadIdx.x; index<tile_size; index+=blockDim.x) { // i = index % tile_x; // j = index / tile_x; // pos_z[i][j] = -1e20; // pos_cose[i][j] = 0.0; // } // __syncthreads(); // // /* Load variables used by every thread (per block) to shared memory for // * faster access */ // if (threadIdx.x==0) { // bistatic = pos[frm]->bistatic; // xlim = pos[frm]->xlim[0]; // ylim = pos[frm]->ylim[0]; // kmpxl = pos[frm]->km_per_pixel; // bn.x = bin % n_tiles_x[frm]; // bn.y = bin / n_tiles_x[frm]; // // /* Calculate the pixel offsets needed to go back and forth between // * tiled POS space for this block's tile and global POS space */ // offsetx = xlim + tile_x * bn.x; // offsety = ylim + tile_x * bn.y; // } // __syncthreads(); // // /* Using grid-stride loop, step through all facet entries for each bin where // * each thread block is responsible for one bin/tile */ // for (index=threadIdx.x; index<entries[frm][bin]; index+=blockDim.x) { // // /* Load facet index into registers */ // fct_indx = facet_index[frm][bin][index]; // // /* Load transformed facet vertices into registers */ // v0 = pos[frm]->facet[fct_indx].v0t; // v1 = pos[frm]->facet[fct_indx].v1t; // v2 = pos[frm]->facet[fct_indx].v2t; // n = pos[frm]->facet[fct_indx].nt; // // /* Calculate and store the boundaries of this tile */ // tile_i1 = offsetx; // tile_i2 = tile_i1 + tile_x; // tile_j1 = offsety; // tile_j2 = tile_j1 + tile_x; // // /* Load this facet's boundaries and clamp them if needed, then // * convert to local shared memory array addressing */ // i1 = max(pos[frm]->facet[fct_indx].ilim.x, tile_i1); // i2 = min(pos[frm]->facet[fct_indx].ilim.y, (tile_i2-1)); // j1 = max(pos[frm]->facet[fct_indx].jlim.x, tile_j1); // j2 = min(pos[frm]->facet[fct_indx].jlim.y, (tile_j2-1)); // // /* Pre-calculate s and t components for the pixel loop */ // double a, b, c, d, e, h, ti, tj, si, sj, si0, sj0, ti0, tj0, sz, tz, den, s, t, z, old; // a = i1*kmpxl - v0.x; // b = v2.y - v1.y; // c = v2.x - v1.x; // d = j1*kmpxl - v0.y; // e = v1.x - v0.x; // h = v1.y - v0.y; // den = e*b - c*h; // ti = -h*kmpxl/den; // tj = e*kmpxl/den; // si = b*kmpxl/den; // sj = -c*kmpxl/den; // si0 = (a*b - c*d)/den; // ti0 = (e*d -a*h)/den; // sz = v1.z - v0.z; // tz = v2.z - v1.z; // // /* Now convert i1, i2, j1, j2 to shared-memory tile coordinates */ // i1 -= (offsetx); // i2 -= (offsetx); // j1 -= (offsety); // j2 -= (offsety); // // /* Pre-calculate some quantities for cosine smoothing if enabled */ // if (posvis_tiled_smooth) { // /* Assign temp. normal components as float3 */ // fidx.x = verts[0]->f[fct_indx].v[0]; // fidx.y = verts[0]->f[fct_indx].v[1]; // fidx.z = verts[0]->f[fct_indx].v[2]; // // tv0.x = verts[0]->v[fidx.x].n[0]; tv0.y = verts[0]->v[fidx.x].n[1]; // tv0.z = verts[0]->v[fidx.x].n[2]; tv1.x = verts[0]->v[fidx.y].n[0]; // tv1.y = verts[0]->v[fidx.y].n[1]; tv1.z = verts[0]->v[fidx.y].n[2]; // tv2.x = verts[0]->v[fidx.z].n[0]; tv2.y = verts[0]->v[fidx.z].n[1]; // tv2.z = verts[0]->v[fidx.z].n[2]; // n1n0.x = tv1.x - tv0.x; n1n0.y = tv1.y - tv0.y; n1n0.z = tv1.z - tv0.z; // tv2.x -= tv1.x; tv2.y -= tv1.y; tv2.z -= tv1.z; // } // // /* Facet is at least partly within POS frame: find all POS // * pixels whose centers project onto this facet */ // for (i=i1; i<=i2; i++) { // // sj0 = si0; /* Initialize this loop's base sj0, tj0 */ // tj0 = ti0; // // for (j=j1; j<=j2; j++) { // // /* Calculate s and t parameters */ // s = sj0; // t = tj0; // // if ((s >= -SMALLVAL) && (s <= 1.0 + SMALLVAL)) {// && // // if( (t >= -SMALLVAL) && (t <= s + SMALLVAL)) { // // /* Compute z-coordinate of pixel center: its // * distance measured from the origin towards // * Earth. */ // z = v0.z + s*sz + t*tz; // // /* Compare calculated z to stored shared memory z // * array at this address and store the bigger value */ // old = atomicMax64(&pos_z[i][j], z); // // if (old < z){ // if (posvis_tiled_smooth) { // /* Get pvs_smoothed version of facet unit // * normal: Take the linear combination // * of the three vertex normals; trans- // * form from body to observer coordina- // * tes; and make sure that it points // * somewhat in our direction. */ // n.x = tv0.x + s * n1n0.x + t * tv2.x; // n.y = tv0.y + s * n1n0.y + t * tv2.y; // n.z = tv0.z + s * n1n0.z + t * tv2.z; // dev_cotrans3(&n, oa, n, 1, frm); // dev_normalize3(&n); // } // // /* Determine scattering angles. */ // if (n.z > 0.0) { // if (src) // atomicExch((unsigned long long int*)&pos[frm]->cosill[i][j], // __double_as_longlong(n.z)); // else // atomicExch((unsigned long long int*)&pos[frm]->cose[i][j], // __double_as_longlong(n.z)); // // if ((!src) && (bistatic)) { // // double temp = dev_dot_d3(n,usrc[frm]); // atomicExch((unsigned long long int*)&pos[frm]->cosi[i][j], // __double_as_longlong(temp)); // if (pos[frm]->cosi[i][j] <= 0.0) // pos[frm]->cose[i][j] = 0.0; // } // // } // /* Keeping track of facets may not be required. */ //// atomicExch(&pos[frm]->f[i][j], f); // // } /* end if (no other facet yet blocks this facet from view) */ // } /* end if 0 <= t <= s (facet center is "in" this POS pixel) */ // } /* end if 0 <= s <= 1 */ // // sj0 += sj; // tj0 += tj; // } /* end j-loop over POS rows */ // /* Modify s and t step-wise for the next i-iteration of the pixel loop */ // si0 += si; // ti0 += ti; // // } /* end i-loop over POS columns */ // } // __syncthreads(); // // /* Now write the shared memory array tiles into the global memory z buffer // * and cosine array, again with a block-stride loop */ // if (facet_index[frm][bin][0]!=0) // for (int index=threadIdx.x; index<tile_size; index+=blockDim.x) { // i = index % tile_x; // j = index / tile_x; // ig = i + offsetx; // jg = j + offsety; // if (pos_z[i][j]!=-1e20) // pos[frm]->z[ig][jg] = pos_z[i][j]; // if (pos_cose[i][j]!=0.0) // pos[frm]->cose[ig][jg] = pos_cose[i][j]; // } // __syncthreads(); //} // //__global__ void posvis_outbnd_tiled_krnl64(struct pos_t **pos, // int *outbndarr, double4 *ijminmax_overall, int size, int start) { // /* nfrm_alloc-threaded kernel */ // int posn, f = blockIdx.x * blockDim.x + threadIdx.x + start; // double xfactor, yfactor; // if (f <size) { // if (outbndarr[f]) { // /* ijminmax_overall.w = imin_overall // * ijminmax_overall.x = imax_overall // * ijminmax_overall.y = jmin_overall // * ijminmax_overall.z = jmax_overall */ // posn = pos[f]->n; // xfactor = (MAX( ijminmax_overall[f].x, posn) - // MIN( ijminmax_overall[f].w, -posn) + 1) / (2*posn+1); // yfactor = (MAX( ijminmax_overall[f].z, posn) - // MIN( ijminmax_overall[f].y, -posn) + 1) / (2*posn+1); // pos[f]->posbnd_logfactor = log(xfactor*yfactor); // } // } //} // //__host__ int posvis_tiled_gpu64( // struct par_t *dpar, // struct mod_t *dmod, // struct dat_t *ddat, // struct pos_t **pos, // struct vertices_t **verts, // double3 orbit_offset, // int *posn, // int *outbndarr, // int set, // int nfrm_alloc, // int src, // int nf, // int body, int comp, unsigned char type, cudaStream_t *pv_stream, // int src_override) { // // dim3 BLK,THD, BLKfrm, THD64, *BLKtile, BLKaf, THDaf; // double4 *ijminmax_overall; // double3 *oa, *usrc; // int ***facet_index, *xspan, *yspan, *n_tiles_x, *n_tiles_y, *n_tiles, **entries; // int f, outbnd, start, sharedMem, oasize, span, tile_size, **addr_index; // // oasize=nfrm_alloc*3; // span=32; // tile_size=span*span; // // /* Launch parameters for the facet_streams kernel */ // THD.x = 256; THD64.x = 64; // BLK.x = floor((THD.x - 1 + nf) / THD.x); // BLKfrm.x = floor((THD64.x - 1 + nfrm_alloc)/THD64.x); // THDaf.x = 1024; // BLKaf.x = nfrm_alloc; // // /* Set up the offset addressing for lightcurves if this is a lightcurve */ // if (type == LGHTCRV) start = 1; /* fixes the lightcurve offsets */ // else start = 0; // // /* Allocate temporary arrays/structs */ // cudaCalloc1((void**)&ijminmax_overall, sizeof(double4), nfrm_alloc); // cudaCalloc1((void**)&oa, sizeof(double3), oasize); // cudaCalloc1((void**)&usrc, sizeof(double3), nfrm_alloc); // cudaCalloc1((void**)&xspan, sizeof(int), nfrm_alloc); // cudaCalloc1((void**)&yspan, sizeof(int), nfrm_alloc); // cudaCalloc1((void**)&n_tiles, sizeof(int), nfrm_alloc); // cudaCalloc1((void**)&n_tiles_x, sizeof(int), nfrm_alloc); // cudaCalloc1((void**)&n_tiles_y, sizeof(int), nfrm_alloc); // /* Allocate the frame portion of the facet index triple pointer and // * the bin entries counter */ // cudaCalloc((void**)&facet_index, sizeof(int**), nfrm_alloc); // cudaCalloc1((void**)&entries, sizeof(int*), nfrm_alloc); //// cudaCalloc1((void**)&addr_index, sizeof(int*), nfrm_alloc); // cudaCalloc((void**)&BLKtile, sizeof(dim3), nfrm_alloc); // // /* Initialize/pre-calculate values for rasterization */ // posvis_tiled_init_krnl64<<<BLKfrm,THD64>>>(dpar, pos, ijminmax_overall, oa, usrc, // outbndarr, comp, start, src, nfrm_alloc, set, src_override); // checkErrorAfterKernelLaunch("posvis_tiled_init_krnl64"); // // /* Transform facet normals and determine bounding for facets and pos. */ // for (f=start; f<nfrm_alloc; f++) // transform_facet_normals_krnl64c<<<1,THD,0,pv_stream[f]>>>(dmod, pos, // verts, ijminmax_overall, orbit_offset, oa, outbndarr, nf, // f, src); // checkErrorAfterKernelLaunch("transform_facet_normals_krnl64a"); //// /* Transform facet normals and determine bounding for facets and pos. */ //// for (f=start; f<nfrm_alloc; f++) //// transform_facet_normals_krnl64b<<<BLK,THD,0,pv_stream[f]>>>(dmod, pos, //// verts, ijminmax_overall, orbit_offset, oa, usrc, outbndarr, nf, //// f, src); //// checkErrorAfterKernelLaunch("transform_facet_normals_krnl64b"); //// transform_facet_normals_krnl64b<<<BLKaf,THD>>>(dmod, pos, verts, ijminmax_overall, //// orbit_offset, oa, outbndarr, nf, src); //// checkErrorAfterKernelLaunch("transform_facet_normals_krnl64a"); // // for (f=start; f<nfrm_alloc; f++) // cudaStreamSynchronize(pv_stream[f]); // // /* Now calculate the tiling parameters to cover the POS view */ // for (f=start; f<nfrm_alloc; f++) { // xspan[f] = pos[f]->xlim[1] - pos[f]->xlim[0] + 1; // yspan[f] = pos[f]->ylim[1] - pos[f]->ylim[0] + 1; // n_tiles_x[f] = (xspan[f]/span) + 1; // n_tiles_y[f] = (yspan[f]/span) + 1; // n_tiles[f] = n_tiles_x[f] * n_tiles_y[f]; // BLKtile[f].x = n_tiles[f]; // BLKtile[f].y = BLKtile[f].z = 1; // // /* Now allocate the tiles section of the facet index and then step // * through each tile section to allocate enough space for 1024 // * facet indices. This is the maximum number of entries allowable // * per thread block */ // /* Allocate the entries array to keep track of how many facets each bin holds */ //// cudaCalloc((void**)&addr_index[f], sizeof(int), n_tiles[f]); // cudaCalloc((void**)&entries[f], sizeof(int), n_tiles[f]); // cudaCalloc((void**)&facet_index[f], sizeof(int*),n_tiles[f]); // for (int ti=0; ti<n_tiles[f]; ti++) // cudaCalloc((void**)&facet_index[f][ti], sizeof(int), 4*1024); // } // // bin_facets_krnl64c<<<BLKaf,THDaf>>>(pos, verts, facet_index, // entries, nf, n_tiles, n_tiles_x, n_tiles_y, span); // checkErrorAfterKernelLaunch("bin_facets_krnl64"); // // /* Now we bin the triangles into the tiles */ // for (f=start; f<nfrm_alloc; f++) { //// sharedMem = sizeof(int)*n_tiles[f]; //// bin_facets_krnl64a<<<1,THD,sharedMem,pv_stream[f]>>>(pos, verts, facet_index, //// entries, nf, f, n_tiles, n_tiles_x, n_tiles_y, span); //// bin_facets_krnl64b<<<BLK,THD,sharedMem,pv_stream[f]>>>(pos, verts, facet_index, //// entries, addr_index, nf, f, n_tiles, n_tiles_x, n_tiles_y, span); // radar_raster_krnl64<<<BLKtile[f],THD,0,pv_stream[f]>>>(pos, verts, oa, // facet_index, entries, nf, f, n_tiles, n_tiles_x, // n_tiles_y, tile_size, span); // } // checkErrorAfterKernelLaunch("bin_facets_krnl64"); // // for (f=start; f<nfrm_alloc; f++) // cudaStreamSynchronize(pv_stream[f]); // // /* Take care of any posbnd flags */ // posvis_outbnd_tiled_krnl64<<<BLKfrm,THD64>>>(pos, // outbndarr, ijminmax_overall, nfrm_alloc, start); // checkErrorAfterKernelLaunch("posvis_outbnd_krnl64"); // gpuErrchk(cudaMemcpyFromSymbol(&outbnd, posvis_tiled_outbnd, sizeof(int), 0, // cudaMemcpyDeviceToHost)); // //// int n = 75; //// int npixels = 151*151; //// f = 0; //// dbg_print_pos_arrays_full64(pos, 0, npixels, n); //// dbg_print_pos_arrays_full64(pos, 1, npixels, n); //// dbg_print_pos_arrays_full64(pos, 2, npixels, n); //// dbg_print_pos_arrays_full64(pos, 3, npixels, n); // // /* Free temp arrays, destroy streams and timers, as applicable */ // cudaFree(oa); // cudaFree(usrc); // cudaFree(xspan); // cudaFree(yspan); // cudaFree(n_tiles); // cudaFree(entries); // cudaFree(BLKtile); // cudaFree(n_tiles_x); // cudaFree(n_tiles_y); //// cudaFree(addr_index); // cudaFree(facet_index); // cudaFree(ijminmax_overall); // // return outbnd; //}
9,937
#include <cuda.h> #include <stdio.h> #include <stdlib.h> #define N 3 // dim of matrix //Fattened matrix multiplication . Kernel does not support x,y addressing __global__ void mat_multiply(int* d_mat1, int* d_mat2, int* d_mat3, int width) { int k,sum=0; int col = blockDim.x * blockIdx.x + threadIdx.x; int row = blockDim.y * blockIdx.y + threadIdx.y; if(row<width && col<width) { for(k=0;k<width;k++) { sum += d_mat1[row*width+k] * d_mat2[k*width+col]; } d_mat3[row*width+col] = sum; } } int main() { int i,j; int SIZE = N*N; //int BYTES = SIZE*sizeof(int); int *d_mat1, *d_mat2, *d_mat3; // allocate memory on the device cudaMallocManaged(&d_mat1,N*N*sizeof(int)); cudaMallocManaged(&d_mat2,N*N*sizeof(int)); cudaMallocManaged(&d_mat3,N*N*sizeof(int)); // generate matrix on host for(i=0;i<N*N;i++) //linearize array { d_mat1[i] = 1; d_mat2[i] = 1; d_mat3[i] = 0; } dim3 dimGrid(1,1); dim3 dimBlock(N,N); // lauch kernel mat_multiply<<<dimGrid,dimBlock>>>(d_mat1,d_mat2,d_mat3,N); cudaDeviceSynchronize(); for(i=0;i<N*N;i++) { printf("%d ",d_mat3[i]); if(i%N==0 && i>N) printf("\n"); } printf("\n"); }
9,938
/******************************************************************************* * serveral useful gpu functions will be defined in this file to facilitate * the surface redistance scheme ******************************************************************************/ typedef struct { double sR; double sL; } double_eno_derivative; __device__ inline double max2(double x, double y) { return (x<y) ? y : x; } __device__ inline double min2(double x, double y) { return (x<y) ? x : y; } __device__ inline double min_mod(double x, double y) { return (x*y<0) ? 0.0 : (fabs(x)<fabs(y) ? x : y); } __device__ inline double sign(double x) { return (x>0) ? 1.0 : -1.0; } __device__ inline bool same_sign(double x, double y) { return (x*y>0) || (x==0 && y==0); } __device__ inline void advection_velocity(double & H1, double & H2, double & H3, double sign, double Dx, double Dy, double Dz, double nx, double ny, double nz) { double normal_d = nx * Dx + ny + Dy + nz * Dz; H1 = sign * (Dx - nx * normal_d); H2 = sign * (Dy - ny * normal_d); H3 = sign * (Dz - nz * normal_d); } // convert subindex to linear index // periodic boundary conditions are assumed __device__ inline int sub2ind(int row_idx, int col_idx, int pge_idx, int rows, int cols, int pges) { int row_idxn = min2(rows-1, max2(0, row_idx)); int col_idxn = min2(cols-1, max2(0, col_idx)); int pge_idxn = min2(pges-1, max2(0, pge_idx)); int ind = pge_idxn * rows * cols + col_idxn * rows + row_idxn; return ind; } /****************************************************************************** * calculate Eno derivatives at node v0: [v4,v1,v0,v2,v3] ******************************************************************************/ __device__ inline double_eno_derivative eno_derivative( double v4, double v1, double v0, double v2, double v3, double pr, double pl, double ds) { double p2m; double_eno_derivative eno_d; double p2 = v1 - 2.0 * v0 + v2; double p2r = v0 - 2.0 * v2 + v3; p2m = 0.5 * min_mod(p2, p2r) / pow(ds, 2); double vr = (pr==ds) ? v2 : 0; eno_d.sR = (vr - v0) / pr - pr * p2m; double p2l = v0 - 2.0 * v1 + v4; p2m = 0.5 * min_mod(p2, p2l) / pow(ds, 2); double vl = (pl==ds) ? v1 : 0; eno_d.sL = (v0 - vl) / pl + pl * p2m; return eno_d; } // calculate surface redistance step // now lsf represents the auxilary level set function(not the level set function) // inputs : the auxilary level set function, sign of the initial level set function, distance to the interface, normal vectors __global__ void surface_redistance_step(double * step, double const * lsf, double const * sign, double const * deltat, double const * nx, double const * ny, double const * nz, double const * xpr, double const * xpl, double const * ypf, double const * ypb, double const * zpu, double const * zpd, int rows, int cols, int pges, double dx, double dy, double dz, int num_ele) { int row_idx = blockIdx.x * blockDim.x + threadIdx.x; int col_idx = blockIdx.y * blockDim.y + threadIdx.y; int pge_idx = blockIdx.z * blockDim.z + threadIdx.z; if(row_idx >= rows || col_idx >= cols || pge_idx >= pges){ return; } int ind = sub2ind(row_idx, col_idx, pge_idx, rows, cols, pges); int right = sub2ind(row_idx, col_idx+1, pge_idx, rows, cols, pges); int right2 = sub2ind(row_idx, col_idx+2, pge_idx, rows, cols, pges); int left = sub2ind(row_idx, col_idx-1, pge_idx, rows, cols, pges); int left2 = sub2ind(row_idx, col_idx-2, pge_idx, rows, cols, pges); double_eno_derivative eno_dx = eno_derivative( lsf[left2], lsf[left], lsf[ind], lsf[right], lsf[right2], xpr[ind], xpl[ind], dx); double Dx[3] = {eno_dx.sR, 0, eno_dx.sL}; int front = sub2ind(row_idx+1, col_idx, pge_idx, rows, cols, pges); int front2 = sub2ind(row_idx+2, col_idx, pge_idx, rows, cols, pges); int back = sub2ind(row_idx-1, col_idx, pge_idx, rows, cols, pges); int back2 = sub2ind(row_idx-2, col_idx, pge_idx, rows, cols, pges); double_eno_derivative eno_dy = eno_derivative( lsf[back2], lsf[back], lsf[ind], lsf[front], lsf[front2], ypf[ind], ypb[ind], dy); double Dy[3] = {eno_dy.sR, 0, eno_dy.sL}; int up = sub2ind(row_idx, col_idx, pge_idx+1, rows, cols, pges); int up2 = sub2ind(row_idx, col_idx, pge_idx+2, rows, cols, pges); int down = sub2ind(row_idx, col_idx, pge_idx-1, rows, cols, pges); int down2 = sub2ind(row_idx, col_idx, pge_idx-2, rows, cols, pges); double_eno_derivative eno_dz = eno_derivative( lsf[down2], lsf[down], lsf[ind], lsf[up], lsf[up2], zpu[ind], zpd[ind], dz); double Dz[3] = {eno_dz.sR, 0, eno_dz.sL}; //Forward=-1, None=0, BackWard=1 int const choice_x[26] = {-1,-1,-1,-1, 1, 1, 1, 1, 0, 0, 0, 0,-1,-1, 1, 1,-1,-1, 1, 1, -1, 1, 0, 0, 0, 0}; int const choice_y[26] = {-1,-1, 1, 1,-1,-1, 1, 1, -1,-1, 1, 1, 0, 0, 0, 0,-1, 1,-1, 1, 0, 0,-1, 1, 0, 0}; int const choice_z[26] = {-1, 1,-1, 1,-1, 1,-1, 1, -1, 1,-1, 1,-1, 1,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0,-1, 1}; double Nx = nx[ind]; double Ny = ny[ind]; double Nz = nz[ind]; double Sign = sign[ind]; int Collision = 0; double dx_c = 0; double dy_c = 0; double dz_c = 0; for(int i=0;i<26;i++){ double dr_x = Dx[choice_x[i]+1]; double dr_y = Dy[choice_y[i]+1]; double dr_z = Dz[choice_z[i]+1]; double H1, H2, H3; // information propagation direction advection_velocity(H1,H2,H3,Sign,dr_x,dr_y,dr_z,Nx,Ny,Nz); // check if this choice is an upwind direction bool upwind_x = same_sign(choice_x[i],H1); bool upwind_y = same_sign(choice_y[i],H2); bool upwind_z = same_sign(choice_z[i],H3); int upwind = (int) upwind_x && upwind_y && upwind_z; // update choices if(upwind){ dx_c = (dx_c * Collision + dr_x*upwind)/(Collision+upwind); dy_c = (dy_c * Collision + dr_y*upwind)/(Collision+upwind); dz_c = (dz_c * Collision + dr_z*upwind)/(Collision+upwind); } Collision += upwind; } //step[ind] = deltat[ind]*Sign*(sqrt( pow(dx_c*Nz-Nx*dz_c,2)+pow(dy_c*Nx-Ny*dx_c,2)+pow(dz_c*Ny-Nz*dy_c,2) )-1); step[ind] = Collision; }
9,939
#define TPB 8 #define TPBZ 1 __global__ void ldc_D3Q15_LBGK_ts(float * fOut,const float * fIn, const int * snl, const int * lnl, const float u_bc,const float omega, const int Nx, const int Ny, const int Nz){ int X=threadIdx.x+blockIdx.x*blockDim.x; int Y=threadIdx.y+blockIdx.y*blockDim.y; int Z=threadIdx.z+blockIdx.z*blockDim.z; if((X<Nx)&&(Y<Ny)&&(Z<Nz)){ int tid=X+Y*Nx+Z*Nx*Ny; float f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14; float cu,cu1,cu2; //load the data into registers f0=fIn[tid]; f1=fIn[Nx*Ny*Nz+tid]; f2=fIn[2*Nx*Ny*Nz+tid]; f3=fIn[3*Nx*Ny*Nz+tid]; f4=fIn[4*Nx*Ny*Nz+tid]; f5=fIn[5*Nx*Ny*Nz+tid]; f6=fIn[6*Nx*Ny*Nz+tid]; f7=fIn[7*Nx*Ny*Nz+tid]; f8=fIn[8*Nx*Ny*Nz+tid]; f9=fIn[9*Nx*Ny*Nz+tid]; f10=fIn[10*Nx*Ny*Nz+tid]; f11=fIn[11*Nx*Ny*Nz+tid]; f12=fIn[12*Nx*Ny*Nz+tid]; f13=fIn[13*Nx*Ny*Nz+tid]; f14=fIn[14*Nx*Ny*Nz+tid]; //compute density float rho = f0+f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14; float ux=f1-f2+f7-f8+f9-f10+f11-f12+f13-f14; ux/=rho; float uy=f3-f4+f7+f8-f9-f10+f11+f12-f13-f14; uy/=rho; float uz=f5-f6+f7+f8+f9+f10-f11-f12-f13-f14; uz/=rho; //if it's a lid node, update //if(lnl[tid]==1){ if((X==0)&&(!((Y==0)||(Y==(Ny-1))||(Z==0)||(Z==(Nz-1))))){ //speed 1 ex=1 ey=ez=0. w=1./9. cu=3.*(1.)*(-ux); f1+=(1./9.)*rho*cu; //speed 2 ex=-1 ey=ez=0. w=1./9. cu1=3.*(-1.)*(-ux); f2+=(1./9.)*rho*cu1; //speed 3 ey=1; ex=ez=0; w=1./9. cu2=3.*(1.)*(u_bc-uy); f3+=(1./9.)*rho*cu2; //speed 4 ey=-1; ex=ez=0; w=1./9. cu=3.*(-1.)*(u_bc-uy); f4+=(1./9.)*rho*cu; //speed 5 ex=ey=0; ez=1; w=1./9. cu1=3.*(1.)*(-uz); f5+=(1./9.)*rho*cu1; //speed 6 ex=ey=0; ez=-1; w=1./9. cu2=3.*(-1.)*(-uz); f6+=(1./9.)*rho*cu2; //speed 7 ex=ey=ez=1; w=1./72. cu=3.*((1.)*-ux+(1.)*(u_bc-uy)+(1.)*-uz); f7+=(1./72.)*rho*cu; //speed 8 ex=-1 ey=ez=1; w=1./72. cu1=3.*((-1.)*-ux+(1.)*(u_bc-uy)+(1.)*-uz); f8+=(1./72.)*rho*cu1; //speed 9 ex=1 ey=-1 ez=1 cu2=3.0*((1.)*-ux+(-1.)*(u_bc-uy)+(1.)*-uz); f9+=(1./72.)*rho*cu2; //speed 10 ex=-1 ey=-1 ez=1 cu=3.0*((-1.)*-ux+(-1.)*(u_bc-uy)+(1.)*-uz); f10+=(1./72.)*rho*cu; //speed 11 ex=1 ey=1 ez=-1 cu1=3.0*((1.)*-ux +(1.)*(u_bc-uy)+(-1.)*-uz); f11+=(1./72.)*rho*cu1; //speed 12 ex=-1 ey=1 ez=-1 cu2=3.0*((-1.)*-ux+(1.)*(u_bc-uy)+(-1.)*-uz); f12+=(1./72.)*rho*cu2; //speed 13 ex=1 ey=-1 ez=-1 w=1./72. cu=3.0*((1.)*-ux+(-1.)*(u_bc-uy)+(-1.)*-uz); f13+=(1./72.)*rho*cu; //speed 14 ex=ey=ez=-1 w=1./72. cu1=3.0*((-1.)*-ux + (-1.)*(u_bc-uy) +(-1.)*-uz); f14+=(1./72.)*rho*cu1; ux=0.; uy=u_bc; uz=0.; }//if(lnl[tid]==1)... //if(snl[tid]==1){ if(((Y==0)||(Y==(Ny-1))||(Z==0)||(Z==(Nz-1))||(X==(Nx-1)))){ // 1--2 cu=f2; f2=f1; f1=cu; //3--4 cu1=f4; f4=f3; f3=cu1; //5--6 cu2=f6; f6=f5; f5=cu2; //7--14 cu=f14; f14=f7; f7=cu; //8--13 cu1=f13; f13=f8; f8=cu1; //9--12 cu2=f12; f12=f9; f9=cu2; //10--11 cu=f11; f11=f10; f10=cu; }else{ //relax //speed 0 ex=ey=ez=0 w=2./9. float fEq; fEq=rho*(2./9.)*(1.-1.5*(ux*ux+uy*uy+uz*uz)); f0=f0-omega*(f0-fEq); //speed 1 ex=1 ey=ez=0 w=1./9. cu1=3.*(1.*ux); fEq=rho*(1./9.)*(1.+cu1+0.5*(cu1*cu1)- 1.5*(ux*ux+uy*uy+uz*uz)); f1=f1-omega*(f1-fEq); //speed 2 ex=-1 ey=ez=0 w=1./9. cu2=3.*((-1.)*ux); fEq=rho*(1./9.)*(1.+cu2+0.5*(cu2*cu2)- 1.5*(ux*ux+uy*uy+uz*uz)); f2=f2-omega*(f2-fEq); //speed 3 ex=0 ey=1 ez=0 w=1./9. cu=3.*(1.*uy); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f3=f3-omega*(f3-fEq); //speed 4 ex=0 ey=-1 ez=0 w=1./9. cu1=3.*(-1.*uy); fEq=rho*(1./9.)*(1.+cu1+0.5*(cu1*cu1)- 1.5*(ux*ux+uy*uy+uz*uz)); f4=f4-omega*(f4-fEq); //speed 5 ex=ey=0 ez=1 w=1./9. cu2=3.*(1.*uz); fEq=rho*(1./9.)*(1.+cu2+0.5*(cu2*cu2)- 1.5*(ux*ux+uy*uy+uz*uz)); f5=f5-omega*(f5-fEq); //speed 6 ex=ey=0 ez=-1 w=1./9. cu=3.*(-1.*uz); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f6=f6-omega*(f6-fEq); //speed 7 ex=ey=ez=1 w=1./72. cu1=3.*(ux+uy+uz); fEq=rho*(1./72.)*(1.+cu1+0.5*(cu1*cu1)- 1.5*(ux*ux+uy*uy+uz*uz)); f7=f7-omega*(f7-fEq); //speed 8 ex=-1 ey=ez=1 w=1./72. cu2=3.*(-ux+uy+uz); fEq=rho*(1./72.)*(1.+cu2+0.5*(cu2*cu2)- 1.5*(ux*ux+uy*uy+uz*uz)); f8=f8-omega*(f8-fEq); //speed 9 ex=1 ey=-1 ez=1 w=1./72. cu=3.*(ux-uy+uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f9=f9-omega*(f9-fEq); //speed 10 ex=-1 ey=-1 ez=1 w=1/72 cu1=3.*(-ux-uy+uz); fEq=rho*(1./72.)*(1.+cu1+0.5*(cu1*cu1)- 1.5*(ux*ux+uy*uy+uz*uz)); f10=f10-omega*(f10-fEq); //speed 11 ex=1 ey=1 ez=-1 w=1/72 cu2=3.*(ux+uy-uz); fEq=rho*(1./72.)*(1.+cu2+0.5*(cu2*cu2)- 1.5*(ux*ux+uy*uy+uz*uz)); f11=f11-omega*(f11-fEq); //speed 12 ex=-1 ey=1 ez=-1 w=1/72 cu=3.*(-ux+uy-uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f12=f12-omega*(f12-fEq); //speed 13 ex=1 ey=ez=-1 w=1/72 cu1=3.*(ux-uy-uz); fEq=rho*(1./72.)*(1.+cu1+0.5*(cu1*cu1)- 1.5*(ux*ux+uy*uy+uz*uz)); f13=f13-omega*(f13-fEq); //speed 14 ex=ey=ez=-1 w=1/72 cu2=3.*(-ux-uy-uz); fEq=rho*(1./72.)*(1.+cu2+0.5*(cu2*cu2)- 1.5*(ux*ux+uy*uy+uz*uz)); f14=f14-omega*(f14-fEq); }//if/else snl //now, everybody streams... int X_t, Y_t, Z_t; int X_t1,Y_t1,Z_t1; int X_t2,Y_t2,Z_t2; int X_t3,Y_t3,Z_t3; int X_t4,Y_t4,Z_t4; int tid_t,tid_t1,tid_t2,tid_t3,tid_t4; //speed 0 ex=ey=ez=0 fOut[tid]=f0; //speed 1 ex=1 ey=ez=0 X_t=X+1; Y_t=Y; Z_t=Z; if(X_t==Nx) X_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; fOut[Nx*Ny*Nz+tid_t]=f1; //speed 2 ex=-1 ey=ez=0; X_t1=X-1; Y_t1=Y; Z_t1=Z; if(X_t1<0) X_t1=(Nx-1); tid_t1=X_t1+Y_t1*Nx+Z_t1*Nx*Ny; fOut[2*Nx*Ny*Nz+tid_t1]=f2; //speed 3 ex=0 ey=1 ez=0 X_t2=X; Y_t2=Y+1; Z_t2=Z; if(Y_t2==Ny) Y_t2=0; tid_t2=X_t2+Y_t2*Nx+Z_t2*Nx*Ny; fOut[3*Nx*Ny*Nz+tid_t2]=f3; //speed 4 ex=0 ey=-1 ez=0 X_t3=X; Y_t3=Y-1; Z_t3=Z; if(Y_t3<0) Y_t3=(Ny-1); tid_t3=X_t3+Y_t3*Nx+Z_t3*Nx*Ny; fOut[4*Nx*Ny*Nz+tid_t3]=f4; //speed 5 ex=ey=0 ez=1 X_t4=X; Y_t4=Y; Z_t4=Z+1; if(Z_t4==Nz) Z_t4=0; tid_t4=X_t4+Y_t4*Nx+Z_t4*Nx*Ny; fOut[5*Nx*Ny*Nz+tid_t4]=f5; //speed 6 ex=ey=0 ez=-1 X_t=X; Y_t=Y; Z_t=Z-1; if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; fOut[6*Nx*Ny*Nz+tid_t]=f6; //speed 7 ex=ey=ez=1 X_t1=X+1; Y_t1=Y+1; Z_t1=Z+1; if(X_t1==Nx) X_t1=0; if(Y_t1==Ny) Y_t1=0; if(Z_t1==Nz) Z_t1=0; tid_t1=X_t1+Y_t1*Nx+Z_t1*Nx*Ny; fOut[7*Nx*Ny*Nz+tid_t1]=f7; //speed 8 ex=-1 ey=1 ez=1 X_t2=X-1; Y_t2=Y+1; Z_t2=Z+1; if(X_t2<0) X_t2=(Nx-1); if(Y_t2==Ny) Y_t2=0; if(Z_t2==Nz) Z_t2=0; tid_t2=X_t2+Y_t2*Nx+Z_t2*Nx*Ny; fOut[8*Nx*Ny*Nz+tid_t2]=f8; //speed 9 ex=1 ey=-1 ez=1 X_t3=X+1; Y_t3=Y-1; Z_t3=Z+1; if(X_t3==Nx) X_t3=0; if(Y_t3<0) Y_t3=(Ny-1); if(Z_t3==Nz) Z_t3=0; tid_t3=X_t3+Y_t3*Nx+Z_t3*Nx*Ny; fOut[9*Nx*Ny*Nz+tid_t3]=f9; //speed 10 ex=-1 ey=-1 ez=1 X_t4=X-1; Y_t4=Y-1; Z_t4=Z+1; if(X_t4<0) X_t4=(Nx-1); if(Y_t4<0) Y_t4=(Ny-1); if(Z_t4==Nz) Z_t4=0; tid_t4=X_t4+Y_t4*Nx+Z_t4*Nx*Ny; fOut[10*Nx*Ny*Nz+tid_t4]=f10; //speed 11 ex=1 ey=1 ez=-1 X_t=X+1; Y_t=Y+1; Z_t=Z-1; if(X_t==Nx) X_t=0; if(Y_t==Ny) Y_t=0; if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; fOut[11*Nx*Ny*Nz+tid_t]=f11; //speed 12 ex=-1 ey=1 ez=-1 X_t1=X-1; Y_t1=Y+1; Z_t1=Z-1; if(X_t1<0) X_t1=(Nx-1); if(Y_t1==Ny) Y_t1=0; if(Z_t1<0) Z_t1=(Nz-1); tid_t1=X_t1+Y_t1*Nx+Z_t1*Nx*Ny; fOut[12*Nx*Ny*Nz+tid_t1]=f12; //speed 13 ex=1 ey=-1 ez=-1 X_t2=X+1; Y_t2=Y-1; Z_t2=Z-1; if(X_t2==Nx) X_t2=0; if(Y_t2<0) Y_t2=(Ny-1); if(Z_t2<0) Z_t2=(Nz-1); tid_t2=X_t2+Y_t2*Nx+Z_t2*Nx*Ny; fOut[13*Nx*Ny*Nz+tid_t2]=f13; //speed 14 ex=ey=ez=-1 X_t3=X-1; Y_t3=Y-1; Z_t3=Z-1; if(X_t3<0) X_t3=(Nx-1); if(Y_t3<0) Y_t3=(Ny-1); if(Z_t3<0) Z_t3=(Nz-1); tid_t3=X_t3+Y_t3*Nx+Z_t3*Nx*Ny; fOut[14*Nx*Ny*Nz+tid_t3]=f14; }//if(X<Nx... } void ldc_D3Q15_LBGK_ts_cuda(float * fOut, const float * fIn, const int * snl, const int * lnl, const float u_bc, const float omega, const int Nx, const int Ny, const int Nz){ dim3 BLOCKS(TPB,TPB,TPBZ); dim3 GRIDS((Nx+TPB-1)/TPB,(Ny+TPB-1)/TPB,(Nz+TPBZ-1)/TPBZ); ldc_D3Q15_LBGK_ts<<<GRIDS,BLOCKS>>>(fOut,fIn,snl,lnl,u_bc, omega,Nx,Ny,Nz); } __global__ void ldc_D3Q15_LBGK_tsT(float * fOut,const float * fIn, const int * snl, const int * lnl, const float u_bc,const float omega, const int Nx, const int Ny, const int Nz){ int X=threadIdx.x+blockIdx.x*blockDim.x; int Y=threadIdx.y+blockIdx.y*blockDim.y; int Z=threadIdx.z+blockIdx.z*blockDim.z; if((X<Nx)&&(Y<Ny)&&(Z<Nz)){ int tid=X+Y*Nx+Z*Nx*Ny; //3 mul, 3 add float f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14; float cu; //load the data into registers // f0=fIn[tid]; f1=fIn[Nx*Ny*Nz+tid]; // f2=fIn[2*Nx*Ny*Nz+tid]; f3=fIn[3*Nx*Ny*Nz+tid]; // f4=fIn[4*Nx*Ny*Nz+tid]; f5=fIn[5*Nx*Ny*Nz+tid]; // f6=fIn[6*Nx*Ny*Nz+tid]; f7=fIn[7*Nx*Ny*Nz+tid]; // f8=fIn[8*Nx*Ny*Nz+tid]; f9=fIn[9*Nx*Ny*Nz+tid]; // f10=fIn[10*Nx*Ny*Nz+tid]; f11=fIn[11*Nx*Ny*Nz+tid]; // f12=fIn[12*Nx*Ny*Nz+tid]; f13=fIn[13*Nx*Ny*Nz+tid]; // f14=fIn[14*Nx*Ny*Nz+tid]; f0=fIn[tid*15]; f1=fIn[tid*15+1]; f2=fIn[tid*15+2]; f3=fIn[tid*15+3]; f4=fIn[tid*15+4]; f5=fIn[tid*15+5]; f6=fIn[tid*15+6]; f7=fIn[tid*15+7]; f8=fIn[tid*15+8]; f9=fIn[tid*15+9]; f10=fIn[tid*15+10]; f11=fIn[tid*15+11]; f12=fIn[tid*15+12]; f13=fIn[tid*15+13]; f14=fIn[tid*15+14]; //compute density float rho = f0+f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14;//13 add float ux=f1-f2+f7-f8+f9-f10+f11-f12+f13-f14; ux/=rho; //9 add, 1 mul float uy=f3-f4+f7+f8-f9-f10+f11+f12-f13-f14; uy/=rho;//9 add, 1 mul float uz=f5-f6+f7+f8+f9+f10-f11-f12-f13-f14; uz/=rho;//9 add, 1 mul //if it's a lid node, update // if(lnl[tid]==1){ if((X==0)&&(!((Y==0)||(Y==(Ny-1))||(Z==0)||(Z==(Nz-1))))){ //speed 1 ex=1 ey=ez=0. w=1./9. //6 mul, 1 add cu=3.*(1.)*(-ux); f1+=(1./9.)*rho*cu; //speed 2 ex=-1 ey=ez=0. w=1./9. //6 mul, 1 add cu=3.*(-1.)*(-ux); f2+=(1./9.)*rho*cu; //speed 3 ey=1; ex=ez=0; w=1./9. //6 mul, 2 add cu=3.*(1.)*(u_bc-uy); f3+=(1./9.)*rho*cu; //speed 4 ey=-1; ex=ez=0; w=1./9. //6 mul, 2 add cu=3.*(-1.)*(u_bc-uy); f4+=(1./9.)*rho*cu; //speed 5 ex=ey=0; ez=1; w=1./9. //6 mul, 2 add cu=3.*(1.)*(-uz); f5+=(1./9.)*rho*cu; //speed 6 ex=ey=0; ez=-1; w=1./9. //6 mul, 1 add cu=3.*(-1.)*(-uz); f6+=(1./9.)*rho*cu; //speed 7 ex=ey=ez=1; w=1./72. cu=3.*((1.)*-ux+(1.)*(u_bc-uy)+(1.)*-uz); //9 mul, 4 add f7+=(1./72.)*rho*cu; //speed 8 ex=-1 ey=ez=1; w=1./72. cu=3.*((-1.)*-ux+(1.)*(u_bc-uy)+(1.)*-uz); //9 mul, 4 add f8+=(1./72.)*rho*cu; //speed 9 ex=1 ey=-1 ez=1 cu=3.0*((1.)*-ux+(-1.)*(u_bc-uy)+(1.)*-uz);//9 mul, 4 add f9+=(1./72.)*rho*cu; //speed 10 ex=-1 ey=-1 ez=1 cu=3.0*((-1.)*-ux+(-1.)*(u_bc-uy)+(1.)*-uz); //9 mul, 4 add f10+=(1./72.)*rho*cu; //speed 11 ex=1 ey=1 ez=-1 cu=3.0*((1.)*-ux +(1.)*(u_bc-uy)+(-1.)*-uz); //9 mul, 4 add f11+=(1./72.)*rho*cu; //speed 12 ex=-1 ey=1 ez=-1 cu=3.0*((-1.)*-ux+(1.)*(u_bc-uy)+(-1.)*-uz);// 9 mul, 4 add f12+=(1./72.)*rho*cu; //speed 13 ex=1 ey=-1 ez=-1 w=1./72. cu=3.0*((1.)*-ux+(-1.)*(u_bc-uy)+(-1.)*-uz);//9 mul, 4 add f13+=(1./72.)*rho*cu; //speed 14 ex=ey=ez=-1 w=1./72. cu=3.0*((-1.)*-ux + (-1.)*(u_bc-uy) +(-1.)*-uz); //9 mul, 4 add f14+=(1./72.)*rho*cu; ux=0.; uy=u_bc; uz=0.; }//if(lnl[tid]==1)... //if(snl[tid]==1){ if(((Y==0)||(Y==(Ny-1))||(Z==0)||(Z==(Nz-1))||(X==(Nx-1)))){ // 1--2 cu=f2; f2=f1; f1=cu; //3--4 cu=f4; f4=f3; f3=cu; //5--6 cu=f6; f6=f5; f5=cu; //7--14 cu=f14; f14=f7; f7=cu; //8--13 cu=f13; f13=f8; f8=cu; //9--12 cu=f12; f12=f9; f9=cu; //10--11 cu=f11; f11=f10; f10=cu; }else{ //relax //speed 0 ex=ey=ez=0 w=2./9. float fEq; fEq=rho*(2./9.)*(1.-1.5*(ux*ux+uy*uy+uz*uz)); //est 10 mul, 5 add per speed f0=f0-omega*(f0-fEq); //speed 1 ex=1 ey=ez=0 w=1./9. cu=3.*(1.*ux); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f1=f1-omega*(f1-fEq); //speed 2 ex=-1 ey=ez=0 w=1./9. cu=3.*((-1.)*ux); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f2=f2-omega*(f2-fEq); //speed 3 ex=0 ey=1 ez=0 w=1./9. cu=3.*(1.*uy); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f3=f3-omega*(f3-fEq); //speed 4 ex=0 ey=-1 ez=0 w=1./9. cu=3.*(-1.*uy); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f4=f4-omega*(f4-fEq); //speed 5 ex=ey=0 ez=1 w=1./9. cu=3.*(1.*uz); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f5=f5-omega*(f5-fEq); //speed 6 ex=ey=0 ez=-1 w=1./9. cu=3.*(-1.*uz); fEq=rho*(1./9.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f6=f6-omega*(f6-fEq); //speed 7 ex=ey=ez=1 w=1./72. cu=3.*(ux+uy+uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f7=f7-omega*(f7-fEq); //speed 8 ex=-1 ey=ez=1 w=1./72. cu=3.*(-ux+uy+uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f8=f8-omega*(f8-fEq); //speed 9 ex=1 ey=-1 ez=1 w=1./72. cu=3.*(ux-uy+uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f9=f9-omega*(f9-fEq); //speed 10 ex=-1 ey=-1 ez=1 w=1/72 cu=3.*(-ux-uy+uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f10=f10-omega*(f10-fEq); //speed 11 ex=1 ey=1 ez=-1 w=1/72 cu=3.*(ux+uy-uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f11=f11-omega*(f11-fEq); //speed 12 ex=-1 ey=1 ez=-1 w=1/72 cu=3.*(-ux+uy-uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f12=f12-omega*(f12-fEq); //speed 13 ex=1 ey=ez=-1 w=1/72 cu=3.*(ux-uy-uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f13=f13-omega*(f13-fEq); //speed 14 ex=ey=ez=-1 w=1/72 cu=3.*(-ux-uy-uz); fEq=rho*(1./72.)*(1.+cu+0.5*(cu*cu)- 1.5*(ux*ux+uy*uy+uz*uz)); f14=f14-omega*(f14-fEq); }//if/else snl //now, everybody streams... int X_t, Y_t, Z_t; int tid_t; //speed 0 ex=ey=ez=0 //fOut[tid]=f0; fOut[tid*15]=f0; //speed 1 ex=1 ey=ez=0 // est 5 mul, 3 add per speed X_t=X+1; Y_t=Y; Z_t=Z; if(X_t==Nx) X_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; //fOut[Nx*Ny*Nz+tid_t]=f1; fOut[tid_t*15+1]=f1; //speed 2 ex=-1 ey=ez=0; X_t=X-1; Y_t=Y; Z_t=Z; if(X_t<0) X_t=(Nx-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[2*Nx*Ny*Nz+tid_t]=f2; fOut[tid_t*15+2]=f2; //speed 3 ex=0 ey=1 ez=0 X_t=X; Y_t=Y+1; Z_t=Z; if(Y_t==Ny) Y_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[3*Nx*Ny*Nz+tid_t]=f3; fOut[tid_t*15+3]=f3; //speed 4 ex=0 ey=-1 ez=0 X_t=X; Y_t=Y-1; Z_t=Z; if(Y_t<0) Y_t=(Ny-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; //fOut[4*Nx*Ny*Nz+tid_t]=f4; fOut[tid_t*15+4]=f4; //speed 5 ex=ey=0 ez=1 X_t=X; Y_t=Y; Z_t=Z+1; if(Z_t==Nz) Z_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[5*Nx*Ny*Nz+tid_t]=f5; fOut[tid_t*15+5]=f5; //speed 6 ex=ey=0 ez=-1 X_t=X; Y_t=Y; Z_t=Z-1; if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[6*Nx*Ny*Nz+tid_t]=f6; fOut[tid_t*15+6]=f6; //speed 7 ex=ey=ez=1 X_t=X+1; Y_t=Y+1; Z_t=Z+1; if(X_t==Nx) X_t=0; if(Y_t==Ny) Y_t=0; if(Z_t==Nz) Z_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[7*Nx*Ny*Nz+tid_t]=f7; fOut[tid_t*15+7]=f7; //speed 8 ex=-1 ey=1 ez=1 X_t=X-1; Y_t=Y+1; Z_t=Z+1; if(X_t<0) X_t=(Nx-1); if(Y_t==Ny) Y_t=0; if(Z_t==Nz) Z_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[8*Nx*Ny*Nz+tid_t]=f8; fOut[tid_t*15+8]=f8; //speed 9 ex=1 ey=-1 ez=1 X_t=X+1; Y_t=Y-1; Z_t=Z+1; if(X_t==Nx) X_t=0; if(Y_t<0) Y_t=(Ny-1); if(Z_t==Nz) Z_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[9*Nx*Ny*Nz+tid_t]=f9; fOut[tid_t*15+9]=f9; //speed 10 ex=-1 ey=-1 ez=1 X_t=X-1; Y_t=Y-1; Z_t=Z+1; if(X_t<0) X_t=(Nx-1); if(Y_t<0) Y_t=(Ny-1); if(Z_t==Nz) Z_t=0; tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[10*Nx*Ny*Nz+tid_t]=f10; fOut[tid_t*15+10]=f10; //speed 11 ex=1 ey=1 ez=-1 X_t=X+1; Y_t=Y+1; Z_t=Z-1; if(X_t==Nx) X_t=0; if(Y_t==Ny) Y_t=0; if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; //fOut[11*Nx*Ny*Nz+tid_t]=f11; fOut[tid_t*15+11]=f11; //speed 12 ex=-1 ey=1 ez=-1 X_t=X-1; Y_t=Y+1; Z_t=Z-1; if(X_t<0) X_t=(Nx-1); if(Y_t==Ny) Y_t=0; if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; // fOut[12*Nx*Ny*Nz+tid_t]=f12; fOut[tid_t*15+12]=f12; //speed 13 ex=1 ey=-1 ez=-1 X_t=X+1; Y_t=Y-1; Z_t=Z-1; if(X_t==Nx) X_t=0; if(Y_t<0) Y_t=(Ny-1); if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; //fOut[13*Nx*Ny*Nz+tid_t]=f13; fOut[tid_t*15+13]=f13; //speed 14 ex=ey=ez=-1 X_t=X-1; Y_t=Y-1; Z_t=Z-1; if(X_t<0) X_t=(Nx-1); if(Y_t<0) Y_t=(Ny-1); if(Z_t<0) Z_t=(Nz-1); tid_t=X_t+Y_t*Nx+Z_t*Nx*Ny; //fOut[14*Nx*Ny*Nz+tid_t]=f14; fOut[tid_t*15+14]=f14; }//if(X<Nx... } void ldc_D3Q15_LBGK_ts_cudaT(float * fOut, const float * fIn, const int * snl, const int * lnl, const float u_bc, const float omega, const int Nx, const int Ny, const int Nz){ dim3 BLOCKS(TPB,TPB,1); dim3 GRIDS((Nx+TPB-1)/TPB,(Ny+TPB-1)/TPB,Nz); ldc_D3Q15_LBGK_tsT<<<GRIDS,BLOCKS>>>(fOut,fIn,snl,lnl,u_bc, omega,Nx,Ny,Nz); }
9,940
/* * CUDA C++ code to multiply two square matrices * * Written by: Abhijit Joshi <abhijit@accelereyes.com> * Last modified: Wed Apr 10 2013 @2:44 am * * To compile and link this example, use * * nvcc matMul.cu -o matMul.x * * To run this code, use * * ./matMul.x */ #include <iostream> #include <assert.h> /* Helper functions for timing CPU code. Does not handle async GPU computation, use cudaDeviceSynchronize(). */ #include <sys/time.h> typedef struct { timeval val; } timer; // get current time static inline timer timenow(void) { timer time; gettimeofday(&time.val, NULL); return time; } // difference in time between two timers (in seconds) static double timediff(timer start, timer end) { struct timeval elapsed; timersub(&start.val, &end.val, &elapsed); long sec = elapsed.tv_sec; long usec = elapsed.tv_usec; return fabs(sec + usec * 1e-6); } // parameter describing the size of the matrices const int rows = 1024; const int cols = 1024; // block size for tiled multiplication using shared memory const int BLOCK_SIZE = 16; // total number of blocks along X and Y const int NUM_BLOCKS = rows/BLOCK_SIZE; // print the matrix void displayMatrix(float *a) { std::cout << std::endl; for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { std::cout << a[i*cols+j] << " "; } std::cout << std::endl; } } void matrixMultiplyCPU(float *h_a, // pointer to matrix A on the cpu float *h_b, // pointer to matrix B on the cpu float *h_c) // pointer to matrix C = AB on the cpu { for (int row = 0; row < rows; ++row) { for (int col = 0; col < cols; ++col) { float sum = 0; for (int k = 0; k < cols; ++k) sum += h_a[row*rows+k] * h_b[k*rows+col]; h_c[row*cols+col] = sum; } } } // using global memory __global__ void matrixMultiplyNaive(float *_a, // pointer to matrix A on the device float *_b, // pointer to matrix B on the device float *_c) // pointer to matrix C = AB on the device { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; // make sure we stay within bounds while calculating C(i,j) if ((row < rows) && (col < cols)) { // compute the inner product using data from shared memory float sum = 0; for(int k=0; k<cols; k++) { sum += _a[row*rows+k]*_b[k*rows+col]; } _c[row*cols+col] = sum; } } __global__ void matrixMultiplyTiled(float *_a, // pointer to matrix A on the device float *_b, // pointer to matrix B on the device float *_c) // pointer to matrix C = AB on the device { // compute the "row" and "col" inside C = AB handled by this thread int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; // define two 2D arrays in shared memory, one a subset of A and another a subset of B __shared__ float Asub[BLOCK_SIZE][BLOCK_SIZE]; __shared__ float Bsub[BLOCK_SIZE][BLOCK_SIZE]; // the complete inner product will be stored here but assembled piece-by-piece float global_sum = 0.0; // loop over all the tiles in A and B for(int block=0;block<NUM_BLOCKS;block++) { // copy data from global memory to shared memory // shared memory is shared between all threads in a block Asub[threadIdx.y][threadIdx.x] = _a[row*cols + BLOCK_SIZE*block+threadIdx.x]; // copy one element from A into shared memory Bsub[threadIdx.y][threadIdx.x] = _b[(BLOCK_SIZE*block+threadIdx.y)*cols+col]; // copy one element from B into shared memory // synchronize threads __syncthreads(); // compute part of the inner product using data from shared memory for(int k=0; k<BLOCK_SIZE; k++) { global_sum += Asub[threadIdx.y][k]*Bsub[k][threadIdx.x]; } } _c[row*cols+col] = global_sum; } // the main program starts life on the CPU and calls device kernels as required int main(int argc, char *argv[]) { // allocate space in the host for storing input arrays (a and b) and the output array (c) float *a = new float[rows*cols]; float *b = new float[rows*cols]; float *c = new float[rows*cols]; // define device pointers for the same arrays when they'll be copied to the device float *_a, *_b, *_c; // allocate memory on the device (GPU) and check for errors (if any) during this call cudaError_t err; // allocate space for matrix A err = cudaMalloc((void **) &_a, rows*cols*sizeof(float)); if (err!= cudaSuccess) { std::cout << cudaGetErrorString(err) << " in " << __FILE__ << " at line " << __LINE__ << std::endl; exit(EXIT_FAILURE); } // allocate space for matrix B err = cudaMalloc((void **) &_b, rows*cols*sizeof(float)); if (err!= cudaSuccess) { std::cout << cudaGetErrorString(err) << " in " << __FILE__ << " at line " << __LINE__ << std::endl; exit(EXIT_FAILURE); } // allocate space for matrix C = AB err = cudaMalloc((void **) &_c, rows*cols*sizeof(float)); if (err!= cudaSuccess) { std::cout << cudaGetErrorString(err) << " in " << __FILE__ << " at line " << __LINE__ << std::endl; exit(EXIT_FAILURE); } // Fill matrix A for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { a[row + col*rows] = 2.0; } } if((rows<33) && (cols<33)) displayMatrix(a); // Fill matrix B for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { b[row + col*rows] = 4.0; } } if((rows<33) && (cols<33)) displayMatrix(b); // perform multiply on cpu (host) { float *c = new float[rows*cols]; timer start = timenow(); matrixMultiplyCPU(a,b,c); timer stop = timenow(); for (int i = 0; i < rows*cols; ++i) assert(c[i] == 1024*2*4); // ensure results match (assume a=2 b=4 1024x1024) delete [] c; double time_s = timediff(start,stop); // seconds double GFLOPs = (double)(rows*cols) * 2*rows / 1e9 / time_s; std::cout << "cpu elapsed time = " << time_s*1e3 << " ms, GFLOPs = " << GFLOPs << std::endl; } // Copy array contents of A and B from the host (CPU) to the device (GPU) // Note that this is copied to the "global" memory on the device and is accessible to all threads in all blocks // WARNING: Global memory is slow (latency of a few 100 cycles) // cudaMemcpy(_a, a, rows*cols*sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy(_b, b, rows*cols*sizeof(float), cudaMemcpyHostToDevice); dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE, 1); // calculate number of blocks along X and Y in a 2D CUDA "grid" dim3 dimGrid( ceil(float(cols)/float(dimBlock.x)), ceil(float(rows)/float(dimBlock.y)), 1 ); // create CUDA events cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); // start the timer cudaEventRecord( start, 0); // launch the GPU kernel for parallel matrix multiplication of A and B // matrixMultiplyNaive<<<dimGrid,dimBlock>>>(_a, _b, _c); matrixMultiplyTiled<<<dimGrid,dimBlock>>>(_a, _b, _c); // stop the timer cudaEventRecord( stop, 0); cudaEventSynchronize( stop ); float time_ms = 0; cudaEventElapsedTime( &time_ms, start, stop); // milliseconds // print out the number of GFLOPs double GFLOPs = (double)(rows*cols) * 2*rows / 1e9 / (time_ms / 1e3); std::cout << "gpu elapsed time = " << time_ms << " ms, GFLOPs = " << GFLOPs << std::endl; // copy the answer back to the host (CPU) from the device (GPU) cudaMemcpy(c, _c, rows*cols*sizeof(float), cudaMemcpyDeviceToHost); if((rows<33) && (cols<33)) displayMatrix(c); // free device memory cudaFree(_a); cudaFree(_b); cudaFree(_c); // free host memory delete a; delete b; delete c; // successful program termination return 0; }
9,941
#include <iostream> int main(void){ int devcount; int deviceInUse; int attrVal; int canAccess; cudaGetDeviceCount(&devcount); printf("This machine has %d CUDA capable GPUs\n", devcount); printf("------------------------\n"); int deviceGrid[devcount][8]; cudaSetDevice(0); cudaGetDevice(&deviceInUse); printf("This machine is currently using device %d\n", deviceInUse); printf("------------------------\n"); if (devcount > 1) { printf("Changing device in use.....\n"); for (int i = 1; i < devcount; i++) { cudaSetDevice(i); cudaGetDevice(&deviceInUse); printf("This machine is currently using device %d\n", deviceInUse); printf("------------------------\n"); } printf("Checking cross talk between devices.....\n"); for (int i = 0; i < devcount; i++) { if (i + 1 < devcount) { cudaDeviceCanAccessPeer(&canAccess, i, i + 1); if (canAccess == 1) { printf("CUDA Device %d can access CUDA Device %d\n", i, i + 1); } else { printf("ERROR CUDA Device %d can't access CUDA Device %d ensure that this devices supports P2P communication\n", i, i + 1); } } else { cudaDeviceCanAccessPeer(&canAccess, i, i - 1); if (canAccess == 1){ printf("CUDA Device %d can access CUDA Device %d\n", i, i - 1); } else { printf("ERROR CUDA Device %d can't access CUDA Device %d ensure that this devices supports P2P communication\n", i, i - 1); } } } } printf("------------------------\n"); printf("Building block matrix...\n"); printf("------------------------\n"); for (int i = 0; i < devcount; i++){ cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxThreadsPerBlock, i); deviceGrid[i][0] = attrVal; cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxBlockDimX, i); deviceGrid[i][1] = attrVal; cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxBlockDimY, i); deviceGrid[i][2] = attrVal; cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxBlockDimZ, i); deviceGrid[i][3] = attrVal; cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxGridDimX, i); deviceGrid[i][4] = attrVal; cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxGridDimY, i); deviceGrid[i][5] = attrVal; cudaDeviceGetAttribute(&attrVal, cudaDevAttrMaxGridDimZ, i); deviceGrid[i][6] = attrVal; } for (int i = 0; i < devcount; i++) { printf("Device %d has the following properties\n", i); printf("Max Threads Per Block: %d\n", deviceGrid[i][0]); printf("Max Blocks X: %d\n", deviceGrid[i][1]); printf("Max Blocks Y: %d\n", deviceGrid[i][2]); printf("Max Blocks Z: %d\n", deviceGrid[i][3]); printf("Max Grid X: %d\n", deviceGrid[i][4]); printf("Max Grid Y: %d\n", deviceGrid[i][5]); printf("Max Grid Z: %d\n", deviceGrid[i][6]); printf("----------------------------------\n"); } }
9,942
/*--------------------------------------------------------------------*/ /* CUDA utility Library */ /* written by Viktor K. Decyk, UCLA */ #include <stdlib.h> #include <stdio.h> #include "cuda.h" int nblock_size = 64; int ngrid_size = 1; int maxgsx = 65535; int mmcc = 0; static int devid; static cudaError_t crc; __global__ void emptyKernel() {} /*--------------------------------------------------------------------*/ extern "C" void gpu_setgbsize(int nblock) { /* set blocksize */ nblock_size = nblock; return; } /*--------------------------------------------------------------------*/ extern "C" int getmmcc() { /* get major and minor computer capability */ return mmcc; } /*--------------------------------------------------------------------*/ extern "C" void gpu_fallocate(float **g_f, int nsize, int *irc) { /* allocate global float memory on GPU, return pointer to C */ void *gptr; crc = cudaMalloc(&gptr,sizeof(float)*nsize); if (crc) { printf("cudaMalloc float Error=%d:%s,l=%d\n",crc, cudaGetErrorString(crc),nsize); *irc = 1; } *g_f = (float *)gptr; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_iallocate(int **g_i, int nsize, int *irc) { /* allocate global integer memory on GPU, return pointer to C */ void *gptr; crc = cudaMalloc(&gptr,sizeof(int)*nsize); if (crc) { printf("cudaMalloc int Error=%d:%s,l=%d\n",crc, cudaGetErrorString(crc),nsize); *irc = 1; } *g_i = (int *)gptr; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_callocate(float2 **g_c, int nsize, int *irc) { /* allocate global float2 memory on GPU, return pointer to C */ void *gptr; crc = cudaMalloc(&gptr,sizeof(float2)*nsize); if (crc) { printf("cudaMalloc float2 Error=%d:%s,l=%d\n",crc, cudaGetErrorString(crc),nsize); *irc = 1; } *g_c = (float2 *)gptr; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_deallocate(void *g_d, int *irc) { /* deallocate global memory on GPU */ crc = cudaFree(g_d); if (crc) { printf("cudaFree Error=%d:%s\n",crc,cudaGetErrorString(crc)); *irc = 1; } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_fcopyin(float *f, float *g_f, int nsize) { /* copy float array from host memory to global GPU memory */ crc = cudaMemcpy((void *)g_f,f,sizeof(float)*nsize, cudaMemcpyHostToDevice); if (crc) { printf("cudaMemcpyHostToDevice float Error=%d:%s\n",crc, cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_fcopyout(float *f, float *g_f, int nsize) { /* copy float array from global GPU memory to host memory */ crc = cudaMemcpy(f,(void *)g_f,sizeof(float)*nsize, cudaMemcpyDeviceToHost); if (crc) { printf("cudaMemcpyDeviceToHost float Error=%d:%s\n",crc, cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_icopyin(int *f, int *g_f, int nsize) { /* copy int array from host memory to global GPU memory */ crc = cudaMemcpy((void *)g_f,f,sizeof(int)*nsize, cudaMemcpyHostToDevice); if (crc) { printf("cudaMemcpyHostToDevice int Error=%d:%s\n",crc, cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_icopyout(int *f, int *g_f, int nsize) { /* copy int array from global GPU memory to host memory */ crc = cudaMemcpy(f,(void *)g_f,sizeof(int)*nsize, cudaMemcpyDeviceToHost); if (crc) { printf("cudaMemcpyDeviceToHost int Error=%d:%s\n",crc, cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_ccopyin(float2 *f, float2 *g_f, int nsize) { /* copy float2 array from host memory to global GPU memory */ crc = cudaMemcpy((void *)g_f,f,sizeof(float2)*nsize, cudaMemcpyHostToDevice); if (crc) { printf("cudaMemcpyHostToDevice float2 Error=%d:%s\n",crc, cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_ccopyout(float2 *f, float2 *g_f, int nsize) { /* copy float2 array from global GPU memory to host memory */ crc = cudaMemcpy(f,(void *)g_f,sizeof(float2)*nsize, cudaMemcpyDeviceToHost); if (crc) { printf("cudaMemcpyDeviceToHost float2 Error=%d:%s\n",crc, cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_zfmem(float *g_f, int nsize) { /* initialize float array in global GPU memory to zero */ crc = cudaMemset((void *)g_f,0,sizeof(float)*nsize); if (crc) { printf("cudaMemset Error=%d:%s\n",crc,cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_set_cache_size(int nscache) { /* request preferred cache size, requires CUDA 3.2 or higher */ /* nscache = (0,1,2) = (no,small,big) cache size */ cudaFuncCache cpref; if ((nscache < 0) || (nscache > 2)) return; if (nscache==0) cpref = cudaFuncCachePreferNone; else if (nscache==1) cpref = cudaFuncCachePreferShared; else if (nscache==2) cpref = cudaFuncCachePreferL1; crc = cudaThreadSetCacheConfig(cpref); /* crc = cudaDeviceSetCacheConfig(cpref); */ if (crc) { printf("cudaThreadSetCacheConfig error=%d:%s\n",crc, cudaGetErrorString(crc)); } return; } /*--------------------------------------------------------------------*/ extern "C" void emptykernel() { int ngx, ngy; ngx = nblock_size < 32768 ? nblock_size : 32768; ngy = (ngrid_size - 1)/ngx + 1; dim3 dimBlock(nblock_size,1); dim3 dimGrid(ngx,ngy); crc = cudaGetLastError(); emptyKernel<<<dimGrid,dimBlock>>>(); cudaThreadSynchronize(); crc = cudaGetLastError(); if (crc) { printf("emptyKernel error=%d:%s\n",crc,cudaGetErrorString(crc)); exit(1); } return; } /*--------------------------------------------------------------------*/ extern "C" void init_cu(int dev, int *irc) { /* initialize CUDA with device dev or selects best GPU available */ /* searches throughs devices, selects the device with the most compute */ /* units, and saves the device id devid */ /* if dev is a valid device, it is used, otherwise the GPU with the */ /* most multi-processors is selected */ /* error code is modified only if there is an error */ int maxcpus = 0, jm = -1; int j, ndevs, maxunits; unsigned long msize; double z; struct cudaDeviceProp prop; /* returns number of device */ crc = cudaGetDeviceCount(&ndevs); if (crc) { printf("cudaGetDeviceCount Error=%i:%s\n",crc, cudaGetErrorString(crc)); *irc = 1; return; } /* get information about devices */ for (j = 0; j < ndevs; j++) { crc = cudaGetDeviceProperties(&prop,j); if (crc) { printf("cudaGetDeviceProperties Error=%i:%s\n",crc, cudaGetErrorString(crc)); prop.name[0] = 0; } maxunits = prop.multiProcessorCount; if (dev <= 0) { printf("j=%i:CUDA_DEVICE_NAME=%s,CUDA_MULTIPROCESSOR_COUNT=%i\n", j,prop.name,maxunits); msize = prop.totalGlobalMem; z = ((double) msize)/1073741824.0; mmcc = 10*prop.major + prop.minor; printf(" CUDA_GLOBAL_MEM_SIZE=%lu(%f GB),Capability=%d\n", msize,(float) z,mmcc); if (maxunits > maxcpus) { maxcpus = maxunits; jm = j; } } } devid = jm; if (dev >= 0) devid = dev % ndevs; printf("using device j=%i\n",devid); /* get properties for this device */ crc = cudaGetDeviceProperties(&prop,devid); maxgsx = prop.maxGridSize[0]; mmcc = 10*prop.major + prop.minor; /* set device */ crc = cudaSetDevice(devid); if (crc) { printf("cudaSetDevice Error=%i:%s\n",crc, cudaGetErrorString(crc)); *irc = 1; return; } /* run empty kernel */ emptykernel(); return; } /*--------------------------------------------------------------------*/ extern "C" void end_cu() { /* terminate CUDA */ crc = cudaThreadExit(); if (crc) { printf("cudaThreadExit Error=%d:%s\n",crc,cudaGetErrorString(crc)); } return; } /* Interfaces to Fortran */ /*--------------------------------------------------------------------*/ extern "C" void gpu_setgbsize_(int *nblock) { gpu_setgbsize(*nblock); return; } /*--------------------------------------------------------------------*/ extern "C" int getmmcc_() { /* get major and minor computer capability */ return getmmcc(); } /*--------------------------------------------------------------------*/ extern "C" void gpu_fallocate_(unsigned long *gp_f, int *nsize, int *irc) { /* allocate global float memory on GPU, return pointer to Fortran */ float *fptr; gpu_fallocate(&fptr,*nsize,irc); *gp_f = (long )fptr; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_iallocate_(unsigned long *gp_i, int *nsize, int *irc) { /* allocate global integer memory on GPU, return pointer to Fortran */ int *iptr; gpu_iallocate(&iptr,*nsize,irc); *gp_i = (long )iptr; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_callocate_(unsigned long *gp_f, int *nsize, int *irc) { /* allocate global float2 memory on GPU, return pointer */ /* to Fortran */ float2 *fptr; gpu_callocate(&fptr,*nsize,irc); *gp_f = (long )fptr; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_deallocate_(unsigned long *gp_d, int *irc) { /* deallocate global memory on GPU, return pointer to Fortran */ void *d; d = (void *)*gp_d; gpu_deallocate(d,irc); *gp_d = 0; return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_fcopyin_(float *f, unsigned long *gp_f, int *nsize) { /* copy float array from main memory to global GPU memory */ float *g_f; g_f = (float *)*gp_f; gpu_fcopyin(f,g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_fcopyout_(float *f, unsigned long *gp_f, int *nsize) { /* copy float array from global GPU memory to main memory */ float *g_f; g_f = (float *)*gp_f; gpu_fcopyout(f,g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_icopyin_(int *f, unsigned long *gp_f, int *nsize) { /* copy int array from main memory to global GPU memory */ int *g_f; g_f = (int *)*gp_f; gpu_icopyin(f,g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_icopyout_(int *f, unsigned long *gp_f, int *nsize) { /* copy int array from global GPU memory to main memory */ int *g_f; g_f = (int *)*gp_f; gpu_icopyout(f,g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_ccopyin_(float2 *f, unsigned long *gp_f, int *nsize) { /* copy float2 array from main memory to global GPU memory */ float2 *g_f; g_f = (float2 *)*gp_f; gpu_ccopyin(f,g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_ccopyout_(float2 *f, unsigned long *gp_f, int *nsize) { /* copy float2 array from global GPU memory to main memory */ float2 *g_f; g_f = (float2 *)*gp_f; gpu_ccopyout(f,g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_zfmem_(unsigned long *gp_f, int *nsize) { float *g_f; g_f = (float *)*gp_f; gpu_zfmem(g_f,*nsize); return; } /*--------------------------------------------------------------------*/ extern "C" void gpu_set_cache_size_(int *nscache) { gpu_set_cache_size(*nscache); return; } /*--------------------------------------------------------------------*/ extern "C" void emptykernel_() { emptykernel(); return; } /*--------------------------------------------------------------------*/ extern "C" void init_cu_(int *dev, int *irc) { init_cu(*dev,irc); return; } /*--------------------------------------------------------------------*/ extern "C" void end_cu_() { end_cu(); return; }
9,943
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100 __global__ void CUDAStrCopy(char *str, char *sub, int *len2) { int start = blockIdx.x; int end = start + *len2; for(int i = start; i < end; i++) { if(str[i] != sub[i - start]) break; else if(i == end - 1) printf("Found at %d\n", (i - start)); } } int main() { char str[N]; char sub[N]; char *pstr, *psub; int *plen2; printf("Enter a string: "); scanf("%s", str); printf("Enter the substring: "); scanf("%s", sub); int len1 = strlen(str); int len2 = strlen(sub); cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); cudaMalloc((void**)&pstr, N * sizeof(char)); cudaMalloc((void**)&psub, len2 * sizeof(char)); cudaMalloc((void**)&plen2, sizeof(int)); cudaMemcpy(pstr, str, N * sizeof(char), cudaMemcpyHostToDevice); cudaMemcpy(psub, sub, len2 * sizeof(char), cudaMemcpyHostToDevice); cudaMemcpy(plen2, &len2, sizeof(int), cudaMemcpyHostToDevice); CUDAStrCopy<<<N - len2, 1>>>(pstr, psub, plen2); cudaEventRecord(stop, 0); cudaEventSynchronize(stop); float elapsedTime; cudaEventElapsedTime(&elapsedTime, start, stop); int i; /* printf("Value of C in host after kernel execution\n"); for(int i = 0; i < N; i++) printf("%c\n", C[i]); */ printf("Time taken = %f", elapsedTime); cudaFree(pstr); cudaFree(psub); cudaFree(plen2); printf("\n"); return 0; }
9,944
#include <cuda_runtime.h> #include <stdio.h> int main() { FILE *arq; // Abre um arquivo TEXTO para LEITURA arq = fopen("data//516747522.dc", "rt"); if (arq == NULL) // Se houve erro na abertura { printf("Problemas na abertura do arquivo\n"); return 0; } fclose(arq); }
9,945
int getNbThreadPerBlock(int device) { int value; cudaDeviceGetAttribute(&value, cudaDevAttrMaxThreadsPerBlock, device); return value; } int getNbBlockDimX(int device) { int value; cudaDeviceGetAttribute(&value, cudaDevAttrMaxBlockDimX, device); return value; }
9,946
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #define MAX_WORDS 67108864 #define NUMBER_OF_TESTS 100 // Device initialization void init_gpu(cudaDeviceProp *deviceProp){ // Detect GPU int deviceCount = 0; cudaError_t error_id = cudaGetDeviceCount(&deviceCount); if (error_id != cudaSuccess){ printf("Error: cudaGetDeviceCount returns %d\n-> %s\n", (int)error_id, cudaGetErrorString(error_id)); exit(EXIT_FAILURE); } if (deviceCount == 0){ printf("No CUDA device found\n"); exit(EXIT_FAILURE); } // Use the first device found cudaSetDevice(0); cudaGetDeviceProperties(deviceProp, 0); } int main(int argc, char **argv){ // Host buffer double *buf; // Device buffer double *devbuf; // Measure execution time struct timespec starttime, endtime; double elapsedtime; clock_t starttic, endtic, tics; // Counters size_t i, w, t; // GPU identification and initialization cudaDeviceProp deviceProp; init_gpu(&deviceProp); printf("Iteration\tWords\tBytes\tTicks\tMbit/sec\n"); for ( i = 0; pow(2, i) <= MAX_WORDS; i++ ){ // Amount of words (word = double) w = pow(2, i); // Allocate host buffer cudaMallocHost(&buf, w * sizeof(double)); // Allocate device buffer cudaMalloc(&devbuf, w * sizeof(double)); elapsedtime = 0; tics = 0; for ( t = 0; t < NUMBER_OF_TESTS; t++ ){ clock_gettime(CLOCK_MONOTONIC, &starttime); starttic = clock(); cudaMemcpy(devbuf, buf, w * sizeof(double), cudaMemcpyHostToDevice); clock_gettime(CLOCK_MONOTONIC, &endtime); endtic = clock(); elapsedtime += ( endtime.tv_sec - starttime.tv_sec ) + ( endtime.tv_nsec - starttime.tv_nsec ) / 1e9; tics += endtic - starttic; } // Elapsed time elapsedtime /= NUMBER_OF_TESTS; tics /= NUMBER_OF_TESTS; // Mbits / sec double bandwidth; bandwidth = w * sizeof(double) * 1.0e-6 * 8 / elapsedtime; printf("%ld\t%ld\t%ld\t%ld\t%ld\n", i, w, w * sizeof(double), (size_t)tics, (size_t)bandwidth); elapsedtime = 0; cudaFree(devbuf); cudaFreeHost(buf); } exit(EXIT_SUCCESS); }
9,947
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> int main() { int dev_count; cudaGetDeviceCount(&dev_count); std::cout << "cuda device number: " << dev_count << std::endl; cudaDeviceProp dev_prop; for (int i = 0; i < dev_count; i++) { cudaGetDeviceProperties(&dev_prop, i); std::cout << "max threads per block: " << dev_prop.maxThreadsPerBlock << std::endl; std::cout << "multi-processor count: " << dev_prop.multiProcessorCount << std::endl; std::cout << "clock rate: " << dev_prop.clockRate << std::endl; } return 0; }
9,948
#include <stdio.h> #define BLOCK_SIZE 16 // CUDA tutorial: http://www.nvidia.com/docs/IO/116711/sc11-cuda-c-basics.pdf // http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared-memory // A is shape (m,n), B is shape (n,k) and C is shape (m,k) __global__ void gemm(float* A, float* B, float* C, int m, int n, int k) { // Block row and column int blockRow = blockIdx.y; int blockCol = blockIdx.x; // Thread row and column within Csub int row = threadIdx.y; int col = threadIdx.x; // Each thread block computes one sub-matrix Csub of C float* Csub = &C[BLOCK_SIZE * k * blockRow + BLOCK_SIZE * blockCol]; // Shared memory used to store Asub and Bsub respectively __shared__ float As[BLOCK_SIZE][BLOCK_SIZE]; __shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE]; // Each thread computes one element of Csub // by accumulating results into Cvalue // block_size = 16 -> 256 threads, one per Csub element float Cvalue = 0.0; // Loop over all the sub-matrices of A and B that are // required to compute Csub // Multiply each pair of sub-matrices together // and accumulate the results for (int i = 0; i < (n / BLOCK_SIZE); ++i) { // Get sub-matrix Asub of A float* Asub = &A[BLOCK_SIZE * blockRow * n + BLOCK_SIZE * i]; // Get sub-matrix Bsub of B float* Bsub = &B[BLOCK_SIZE * k * i + BLOCK_SIZE * blockCol]; // Load Asub and Bsub from device memory to shared memory // Each thread loads one element of each sub-matrix As[row][col] = Asub[row*n+col]; Bs[row][col] = Bsub[row*k+col]; // Synchronize to make sure the sub-matrices are loaded // before starting the computation __syncthreads(); // Multiply Asub and Bsub together for (int j = 0; j < BLOCK_SIZE; ++j) Cvalue += As[row][j] * Bs[j][col]; // Synchronize to make sure that the preceding // computation is done before loading two new // sub-matrices of A and B in the next iteration __syncthreads(); } // Write Csub to device memory // Each thread writes one element if(col + blockCol* BLOCK_SIZE< k && row + blockRow* BLOCK_SIZE< m) Csub[row*k+col] = Cvalue; } // 32 single float array -> 32 bits unsigned int __device__ unsigned int concatenate(float* array) { unsigned int rvalue=0; unsigned int sign; for (int i = 0; i < 32; i++) { sign = (array[i]>=0); rvalue = rvalue | (sign<<i); } return rvalue; } __global__ void concatenate_rows_kernel(float *a, unsigned int *b, int size) { int i = blockIdx.x * blockDim.x + threadIdx.x; if(i<size) b[i] = concatenate(&a[i*32]); } __global__ void concatenate_cols_kernel(float *a, unsigned int *b, int m, int n) { int j = blockIdx.x * blockDim.x + threadIdx.x; if(j<n){ float * array = new float[32]; for(int i=0; i<m; i+=32){ for(int k=0; k<32;k++) array[k] = a[j + n*(i+k)]; b[j+n*i/32]=concatenate(array); } delete[] array; } } // 32 bits unsigned int -> 32 single float array // TODO: the array allocation should not be done here __device__ float* deconcatenate(unsigned int x) { float * array = new float[32]; for (int i = 0; i < 32; i++) { array[i] = (x & ( 1 << i )) >> i; } return array; } __global__ void deconcatenate_rows_kernel(unsigned int *a, float *b, int size) { float * array; for(int i=0; i<size; i+=32) { array = deconcatenate(a[i/32]); for (int k=0;k<32;k++) b[i+k] = array[k]; delete[] array; } } // A is shape (m,n), B is shape (n,k) and C is shape (m,k) __global__ void xnor_gemm(unsigned int* A, unsigned int* B, float* C, int m, int n, int k) { // Block row and column int blockRow = blockIdx.y; int blockCol = blockIdx.x; // Thread row and column within Csub int row = threadIdx.y; int col = threadIdx.x; // Each thread block computes one sub-matrix Csub of C float* Csub = &C[BLOCK_SIZE * k * blockRow + BLOCK_SIZE * blockCol]; // Shared memory used to store Asub and Bsub respectively __shared__ unsigned int As[BLOCK_SIZE][BLOCK_SIZE]; __shared__ unsigned int Bs[BLOCK_SIZE][BLOCK_SIZE]; // Each thread computes one element of Csub // by accumulating results into Cvalue // block_size = 16 -> 256 threads, one per Csub element unsigned int Cvalue = 0; // Loop over all the sub-matrices of A and B that are // required to compute Csub // Multiply each pair of sub-matrices together // and accumulate the results for (int i = 0; i < (n / BLOCK_SIZE); ++i) { // Get sub-matrix Asub of A unsigned int* Asub = &A[BLOCK_SIZE * blockRow * n + BLOCK_SIZE * i]; // Get sub-matrix Bsub of B unsigned int* Bsub = &B[BLOCK_SIZE * k * i + BLOCK_SIZE * blockCol]; // Load Asub and Bsub from device memory to shared memory // Each thread loads one element of each sub-matrix As[row][col] = Asub[row*n+col]; Bs[row][col] = Bsub[row*k+col]; // Synchronize to make sure the sub-matrices are loaded // before starting the computation __syncthreads(); // Multiply Asub and Bsub together // THIS IS THE MOST INTERESTING PART for (int j = 0; j < BLOCK_SIZE; ++j) Cvalue += __popc(As[row][j]^Bs[j][col]); // Synchronize to make sure that the preceding // computation is done before loading two new // sub-matrices of A and B in the next iteration __syncthreads(); } // Write Csub to device memory // Each thread writes one element if(col + blockCol* BLOCK_SIZE< k && row + blockRow* BLOCK_SIZE< m) Csub[row*k+col] = -(2*(float)Cvalue-32*n); }
9,949
/** * @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 globalBlockIndex = blockIdx.x + blockIdx.y * gridDim.x; // Which thread are we within the block? size_t const localThreadIdx = threadIdx.x + blockDim.x * threadIdx.y; // How big is each block? size_t const threadsPerBlock = blockDim.x*blockDim.y; // Which thread are we overall? return localThreadIdx + globalBlockIndex*threadsPerBlock; } /** The actual Mandelbrot algorithm for a single location */ __device__ unsigned int doIterations( double const realPart0, double const imagPart0, unsigned int const maxIters ) { // Initialise: z = z0 double realPart = realPart0; double imagPart = imagPart0; unsigned int count = 0; // Loop until escape while ( ( count <= maxIters ) && ((realPart*realPart + imagPart*imagPart) <= 4.0) ) { ++count; // Update: z = z*z + z0; double const oldRealPart = realPart; realPart = realPart*realPart - imagPart*imagPart + realPart0; imagPart = 2.0*oldRealPart*imagPart + imagPart0; } return count; } /** Main entry point. * Works out where the current thread should read/write to global memory * and calls doIterations to do the actual work. */ __global__ void processMandelbrotElement( double * out, const double * x, const double * y, const unsigned int maxIters, const unsigned int numel ) { // Work out which thread we are size_t const globalThreadIdx = calculateGlobalIndex(); // If we're off the end, return now if (globalThreadIdx >= numel) { return; } // Get our X and Y coords double const realPart0 = x[globalThreadIdx]; double const imagPart0 = y[globalThreadIdx]; // Run the itearations on this location unsigned int const count = doIterations( realPart0, imagPart0, maxIters ); out[globalThreadIdx] = log( double( count + 1 ) ); }
9,950
#include <stdint.h> #include <stdio.h> #include <iostream> #include <cuda_runtime.h> #include <cooperative_groups.h> #define CHECK(cmd) \ {\ cudaError_t error = cmd;\ if (error != cudaSuccess) { \ fprintf(stderr, "error: '%s'(%d) at %s:%d\n", cudaGetErrorString(error), error,__FILE__, __LINE__); \ exit(EXIT_FAILURE);\ }\ } /* * Square each element in the array A and write to array C. */ __global__ void vector_square() { cooperative_groups::grid_group grid = cooperative_groups::this_grid(); unsigned int rank = grid.thread_rank(); unsigned int grid_size = grid.size(); size_t offset = (blockIdx.x * blockDim.x + threadIdx.x); // printf("grid rank: %d\n",rank); if(offset == 0){ printf("grid.is_valid(): %d\n",grid.is_valid()); printf("grid_size: %d\n",grid_size); //printf("grid rank: %d\n",rank); //dim3 thread_loc=grid.group_index();//group_index() is not a member in cooperative group } /*if(offset == 0) printf("I am from thread 0\n"); else if(offset == 40) printf("I am from thread 40 \n"); if(offset==40){ //__syncthreads(); unsigned long long int wait_t=32000000000,start=clock64(),cur; do{cur=clock64()-start;} while(cur<wait_t); printf("Wait is over!\n"); } grid.sync(); if(offset == 0) printf("I am after grid.sync() from thread 0\n"); else if(offset == 40) printf("I am after grid.sync() from thread 40 \n");*/ } int main(int argc, char *argv[]) { CHECK(cudaSetDevice(2)); size_t N = 2560; cudaDeviceProp props; CHECK(cudaGetDeviceProperties(&props, 0/*deviceID*/)); printf ("info: running on device %s\n", props.name); int warp_size = props.warpSize; int num_sms = props.multiProcessorCount; int max_blocks_per_sm; // Calculate the device occupancy to know how many blocks can be run. CHECK(cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags( &max_blocks_per_sm, vector_square, warp_size, 0, cudaOccupancyDefault)); int desired_blocks = max_blocks_per_sm * num_sms; /*std::cout<<"warp_size: "<<warp_size<<std::endl; std::cout<<"multiProcessorCount: "<<num_sms<<std::endl; std::cout<<"max_blocks_per_sm: "<<max_blocks_per_sm<<std::endl; std::cout<<"desired_blocks: "<<desired_blocks<<std::endl;*/ const unsigned threadsPerBlock = 32; const unsigned blocks = N/threadsPerBlock; //const unsigned blocks = (desired_blocks+1); printf ("info: launch 'vector_square' kernel\n"); // vector_square <<<blocks, threadsPerBlock>>> (C_d, A_d, N); //CHECK(cudaDeviceSynchronize()); void *coop_params=NULL; //cudaError_t errval=(cudaLaunchCooperativeKernel((void*)vector_square,blocks,threadsPerBlock,coop_params,0,0)); cudaError_t errval=(cudaLaunchCooperativeKernel((void*)vector_square,blocks,threadsPerBlock,&coop_params,0,0)); CHECK(cudaDeviceSynchronize()); std::cout<<"errval: "<<cudaGetErrorString(errval)<<std::endl; if (errval != cudaSuccess) { std::cout << "CUDA error: " << cudaGetErrorString(errval); std::cout << std::endl; std::cout << " Location: " << __FILE__ << ":" << __LINE__ << std::endl; exit(errval); } printf ("DONE!\n"); return 0; }
9,951
#define d_sxx(z,x) d_sxx[(x)*(nz)+(z)] #define d_szz(z,x) d_szz[(x)*(nz)+(z)] #define d_Lambda(z,x) d_Lambda[(x)*(nz)+(z)] #define d_Cp(z,x) d_Cp[(x)*(nz)+(z)] #include<stdio.h> __global__ void add_source(float *d_szz, float *d_sxx, float amp, int nz, bool isFor, \ int z_loc, int x_loc, float dt, float *d_Cp) { int id = threadIdx.x + blockDim.x*blockIdx.x; float scale = pow(1500.0,2);; // float scale = pow(d_Cp(z_loc,x_loc),2); // float scale = d_Lambda(z_loc, x_loc); // float scale = 10890000.0; if (isFor) { if(id==0) { // printf("amp = %f ", amp); d_szz(z_loc,x_loc) += scale*amp * dt; d_sxx(z_loc,x_loc) += scale*amp * dt; } else{ return; } } else { if(id==0) { // printf("amp = %f ", amp); d_szz(z_loc,x_loc) -= scale*amp * dt; d_sxx(z_loc,x_loc) -= scale*amp * dt; } else{ return; } } } // __global__ void add_source(float *d_szz, float *d_sxx, int nz, float *d_source, bool isFor, \ // int z_loc, int x_loc, float dt, float *d_Cp) { // int iSrc = threadIdx.x + blockDim.x*blockIdx.x; // float scale = pow(d_Cp(z_loc,x_loc),2); // if (isFor) { // if(id==0) { // // printf("amp = %f ", amp); // d_szz(z_loc,x_loc) += scale*amp * dt; // d_sxx(z_loc,x_loc) += scale*amp * dt; // } // else{ // return; // } // } // else { // if(id==0) { // // printf("amp = %f ", amp); // d_szz(z_loc,x_loc) -= scale*amp * dt; // d_sxx(z_loc,x_loc) -= scale*amp * dt; // } // else{ // return; // } // } // }
9,952
#include <stdio.h> #include <cuda.h> #include <stdlib.h> #include <time.h> #include <math.h> __global__ void prefixSum(int *a, int N) { int tid = blockIdx.x * blockDim.x + threadIdx.x; int i; extern __shared__ int bufferA[]; if (tid < N) { for (i = 0; i < log2((double) N); i++) { if (tid >= powf(2, i) && (tid + (int) powf(2, i) < N)) { bufferA[tid] = a[tid] + a[tid + (int) powf(2, i)]; } __syncthreads(); a[tid] = bufferA[tid]; __syncthreads(); } } } int main(void) { int N, T, B, repeat; repeat = 1; while (repeat == 1) { printf("Enter size of matrices: "); scanf("%d", &N); while (N <= 0) { printf( "Size of matrices must be greater than 0. Enter a valid size of matrices: "); scanf("%d", &N); } printf("Enter number of threads in a block: "); scanf("%d", &T); while (T <= 0) { printf( "Number of threads must be greater than 0. Enter number of threads in a block: "); scanf("%d", &T); } while (T > 1024) { printf( "Number of threads must not exceed the device bandwidth. Enter number of threads in a block: "); scanf("%d", &T); } printf("Enter number of blocks in a grid: "); scanf("%d", &B); while (B <= 0) { printf( "Number of blocks must be greater than 0. Enter number of blocks in a grid: "); scanf("%d", &B); } while (B > 65535) { printf( "Number of blocks must not exceed the device bandwidth. Enter number of blocks in a grid: "); scanf("%d", &B); } int *a, *deviceA; int *dev_a; int i, j; int ssd = 0; cudaEvent_t start, stop; float elapsedTime; cudaEventCreate(&start); cudaEventCreate(&stop); cudaMalloc((void**) &dev_a, N * sizeof(int)); a = (int *) malloc(N * sizeof(int)); deviceA = (int *) malloc(N * sizeof(int)); srand(time(NULL)); //loop will generate the matrix with random integers for (i = 0; i < N; i++) { a[i] = (int) rand(); deviceA[i] = a[i]; } /*******************begin host code*****************************/ clock_t begin, end; begin = clock(); for (j = 0; i < (log(N) / log(2)); j++) { for (i = pow(2, j); i < N; i++) { if (i + (int) pow(2, j) < N) a[i] = a[i] + a[i + (int) pow(2, j)]; } } end = clock(); printf("It took %f seconds for the host to do the matrix operation.\n", (float) (end - begin) / (CLOCKS_PER_SEC)); /*******************end host code*****************************/ /*******************begin device code*****************************/ cudaMemcpy(dev_a, deviceA, N * sizeof(int), cudaMemcpyHostToDevice); dim3 grid(B, B); dim3 block(T, T); cudaEventRecord(start, 0); prefixSum<<<grid, block>>>(dev_a, N); cudaThreadSynchronize(); cudaEventRecord(stop, 0); cudaEventSynchronize(stop); cudaMemcpy(deviceA, dev_a, N * sizeof(int), cudaMemcpyDeviceToHost); cudaEventElapsedTime(&elapsedTime, start, stop); printf( "It took %f seconds for the device to do the matrix operation.\n", (elapsedTime / 1000)); for (i = 0; i < N; i++) { ssd += deviceA[i] - a[i]; } printf("The sum of square difference is %d.\n", ssd); printf("The speedup factor is %f.\n", ((float) (end - begin) / (CLOCKS_PER_SEC)) / (elapsedTime / 1000)); cudaEventDestroy(start); cudaEventDestroy(stop); free(a); free(deviceA); cudaFree(dev_a); /*******************end device code*****************************/ printf("Enter 1 to continue: "); scanf("%d", &repeat); } return 0; }
9,953
#include <stdio.h> #include <time.h> #include <cuda.h> #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <curand.h> #include <curand_kernel.h> #define ALIVE 1 #define DEAD 0 # define CUDA_SAFE_CALL( call) { \ cudaError err = call; \ if( cudaSuccess != err) { \ fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ __FILE__, __LINE__, cudaGetErrorString( err) ); \ exit(EXIT_FAILURE); \ } } int termCheck(int *prev, int *next, int N, int M, int gen); __global__ void kernel_update(int* t,int* t1,int N,int M); __global__ void initdat(int *t, int *t1, int N, int M, time_t clock); int main(int argc, char *argv[]) { int N, /* rows of the grid */ M, /* columns of the grid */ Gens, /* amount of generations. */ perGens; /* checks termination per perGens generations. if perGens zero no termination check */ int *grid, *grid1; int *gpu_grid, *gpu_grid1, *gpu_temp; if ( argc != 5) { printf("Error! Missing mandatory argument.\n"); return 1; } N = atoi(argv[1]); /* Getting rows amount */ M = atoi(argv[2]); /* Getting columns amount */ Gens = atoi(argv[3]); /* Getting Gens */ perGens = atoi(argv[4]); if (Gens <= 0 || N < 0 || M < 0 || perGens < 0) { printf("Please give positive values for rows/cols and Generations\n"); return 1; } int blockSize = 512; int numBlocks = (N*M + blockSize - 1) / blockSize; grid = (int*)malloc(sizeof(int)*N*M); grid1 = (int*)malloc(sizeof(int)*N*M); CUDA_SAFE_CALL(cudaMalloc(&gpu_grid, N*M*sizeof(int))); CUDA_SAFE_CALL(cudaMalloc(&gpu_grid1, N*M*sizeof(int))); /* Initialize random data */ initdat<<<numBlocks,blockSize>>>(gpu_grid, gpu_grid1, N, M, time(NULL)); CUDA_SAFE_CALL(cudaDeviceSynchronize()); for (int k = 1; k <= Gens; k++) { kernel_update<<<numBlocks,blockSize>>>(gpu_grid,gpu_grid1,N,M); CUDA_SAFE_CALL(cudaDeviceSynchronize()); if ( perGens ) { CUDA_SAFE_CALL(cudaMemcpy(grid, gpu_grid, N*M*sizeof(int), cudaMemcpyDeviceToHost)); CUDA_SAFE_CALL(cudaMemcpy(grid1, gpu_grid1, N*M*sizeof(int), cudaMemcpyDeviceToHost)); if ( k % perGens == 0) { if (termCheck(grid, grid1, N, M, k)) { cudaFree(gpu_grid1); cudaFree(gpu_grid); free(grid); free(grid1); return 0; } } } gpu_temp = gpu_grid; gpu_grid = gpu_grid1; gpu_grid1 = gpu_temp; } printf("Reached requested generations %d\n",Gens ); cudaFree(gpu_grid1); cudaFree(gpu_grid); free(grid); free(grid1); return 0; } int termCheck(int *prev, int *next, int N, int M, int gen){ int allDiff = 0; int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (prev[i*M+j] != next[i*M+j]) { allDiff = 1; } sum += next[i*M+j]; } } if (!sum) { printf("All cells are dead at generation %d\n", gen); return 1; } else if (!allDiff) { printf("Generation %d is the same with generation %d\n", gen, gen-1); return 1; } return 0; } __global__ void kernel_update(int* t,int* t1,int N,int M){ int x = blockIdx.x * blockDim.x + threadIdx.x; /*update starts*/ if (0 <= x && x < N*M ){ //if not out of bounds then.. int i,j,neighbours; i = x / M; j = x % M; if (i+1 > N-1) { if (j-1 < 0) { /* eimai o bot_left */ neighbours = t[(i-1)*M+M-1] + t[(i-1)*M+j] + t[(i-1)*M+j+1] + t[i*M+j+1] + t[0*M+j+1] + t[0*M+j] + t[0*M+M-1] + t[i*M+M-1]; } else if (j+1 > M-1) { /* eimai o bot_right */ neighbours = t[(i-1)*M+j-1] + t[(i-1)*M+j] + t[(i-1)*M+0] + t[i*M+0] + t[0*M+0] + t[0*M+j] + t[0*M+j-1] + t[i*M+j-1]; } else{ /* eimai aplos bot */ neighbours = t[(i-1)*M+j-1] + t[(i-1)*M+j] + t[(i-1)*M+j+1] + t[i*M+j+1] + t[0*M+j+1] + t[0*M+j] + t[0*M+j-1] + t[i*M+j-1]; } } else if (i-1 < 0) { if (j-1 < 0) { /* eimai o top_left */ neighbours = t[(N-1)*M+M-1] + t[(N-1)*M+j] + t[(N-1)*M+j+1] + t[i*M+j+1] + t[(i+1)*M+j+1] + t[(i+1)*M+j] + t[(i+1)*M+M-1] + t[i*M+M-1]; } else if (j+1 > M-1) { /* eimai o top_right */ neighbours = t[(N-1)*M+j-1] + t[(N-1)*M+j] + t[(N-1)*M+0] + t[i*M+0] + t[(i+1)*M+0] + t[(i+1)*M+j] + t[(i+1)*M+j-1] + t[i*M+j-1]; } else{ /* eimai aplos top */ neighbours = t[(N-1)*M+j-1] + t[(N-1)*M+j] + t[(N-1)*M+j+1] + t[i*M+j+1] + t[(i+1)*M+j+1] + t[(i+1)*M+j] + t[(i+1)*M+j-1] + t[i*M+j-1]; } } else if (j-1 < 0) { /* eimai aplos left */ neighbours = t[(i-1)*M+M-1] + t[(i-1)*M+j] + t[(i-1)*M+j+1] + t[i*M+j+1] + t[(i+1)*M+j+1] + t[(i+1)*M+j] + t[(i+1)*M+M-1] + t[i*M+M-1]; } else if (j+1 > M-1) { /* eimai aplos right */ neighbours = t[(i-1)*M+j-1] + t[(i-1)*M+j] + t[(i-1)*M+0] + t[i*M+0] + t[(i+1)*M+0] + t[(i+1)*M+j] + t[(i+1)*M+j-1] + t[i*M+j-1]; } else{ /* oi geitones mou den peftoun eksw */ neighbours = t[(i-1)*M+j-1] + t[(i-1)*M+j] + t[(i-1)*M+j+1] + t[i*M+j+1] + t[(i+1)*M+j+1] + t[(i+1)*M+j] + t[(i+1)*M+j-1] + t[i*M+j-1]; } /* kanones paixnidiou edw */ if (t[x] == ALIVE) { if (neighbours <= 1 || neighbours >= 4) { t1[x] = DEAD; } else{ t1[x] = ALIVE; } } else if (t[x] == DEAD && neighbours == 3) { t1[x] = ALIVE; } else{ t1[x] = DEAD; } } } __global__ void initdat(int *t, int *t1, int N, int M, time_t clock){ int x = blockIdx.x * blockDim.x + threadIdx.x; curandState_t state; curand_init(clock,x,0,&state); if (0 <= x && x < N*M ){ t[x] = (curand(&state) % 4) ? DEAD : ALIVE; t1[x] = DEAD; } }
9,954
#include "includes.h" __global__ void set_dynamic_indices(unsigned int *d_all_ib, unsigned int *d_ib, int flip) { if (flip == blockIdx.x) { d_ib[threadIdx.x] = d_all_ib[blockDim.x * blockIdx.x + threadIdx.x]; d_ib[3 + threadIdx.x] = 0; } }
9,955
extern "C" { typedef struct { short e[25]; } array_63718; __device__ inline int threadIdx_x() { return threadIdx.x; } __device__ inline int threadIdx_y() { return threadIdx.y; } __device__ inline int threadIdx_z() { return threadIdx.z; } __device__ inline int blockIdx_x() { return blockIdx.x; } __device__ inline int blockIdx_y() { return blockIdx.y; } __device__ inline int blockIdx_z() { return blockIdx.z; } __device__ inline int blockDim_x() { return blockDim.x; } __device__ inline int blockDim_y() { return blockDim.y; } __device__ inline int blockDim_z() { return blockDim.z; } __device__ inline int gridDim_x() { return gridDim.x; } __device__ inline int gridDim_y() { return gridDim.y; } __device__ inline int gridDim_z() { return gridDim.z; } __global__ void lambda_238003(int, int*, int*); __global__ void lambda_236333(int*, int, short*, int); __global__ void lambda_235522(int, int, short*, short*); __global__ void lambda_236828(int*); __global__ void lambda_237182(int*, int*, int*); __global__ void lambda_240566(int, short*, short*, short*); __global__ void lambda_236859(int*, int, int, float*); __global__ void lambda_231611(short*, int, int, float*); __global__ void lambda_238321(short*, int, int, short*, int, float*); __global__ __launch_bounds__ (256 * 1 * 1) void lambda_238003(int _238006_310597, int* _238007_310598, int* _238008_310599) { int threadIdx_x_310602; int pthreadIdx_x_310602; int blockDim_x_310605; int pblockDim_x_310605; int blockIdx_x_310608; int pblockIdx_x_310608; int converge_310618; int pconverge_310618; int threadIdx_x_310624; int pthreadIdx_x_310624; int blockDim_x_310627; int pblockDim_x_310627; int blockIdx_x_310630; int pblockIdx_x_310630; int atomicMin_310641; int patomicMin_310641; threadIdx_x_310602 = threadIdx_x(); pthreadIdx_x_310602 = threadIdx_x_310602; l310600: ; threadIdx_x_310602 = pthreadIdx_x_310602; blockDim_x_310605 = blockDim_x(); pblockDim_x_310605 = blockDim_x_310605; l310603: ; blockDim_x_310605 = pblockDim_x_310605; blockIdx_x_310608 = blockIdx_x(); pblockIdx_x_310608 = blockIdx_x_310608; l310606: ; blockIdx_x_310608 = pblockIdx_x_310608; int _310610; _310610 = blockDim_x_310605 * blockIdx_x_310608; int sum_310609; sum_310609 = _238006_310597 / 7; int _310611; _310611 = threadIdx_x_310602 + _310610; int* _310612; _310612 = _238008_310599 + _310611; int _310613; _310613 = *_310612; int _310614; _310614 = _310613; bool _310615; _310615 = sum_310609 < _310614; if (_310615) goto l310616; else goto l310643; l310643: ; pconverge_310618 = 0; goto l310617; l310616: ; pconverge_310618 = 1; goto l310617; l310617: ; converge_310618 = pconverge_310618; bool _310619; _310619 = converge_310618 != 0; if (_310619) goto l310620; else goto l310642; l310642: ; return ; l310620: ; threadIdx_x_310624 = threadIdx_x(); pthreadIdx_x_310624 = threadIdx_x_310624; l310622: ; threadIdx_x_310624 = pthreadIdx_x_310624; blockDim_x_310627 = blockDim_x(); pblockDim_x_310627 = blockDim_x_310627; l310625: ; blockDim_x_310627 = pblockDim_x_310627; blockIdx_x_310630 = blockIdx_x(); pblockIdx_x_310630 = blockIdx_x_310630; l310628: ; blockIdx_x_310630 = pblockIdx_x_310630; int* sum_310636; sum_310636 = _238007_310598 + 0; int _310637; _310637 = blockDim_x_310627 * blockIdx_x_310630; int _310638; _310638 = threadIdx_x_310624 + _310637; atomicMin_310641 = atomicMin(sum_310636, _310638); patomicMin_310641 = atomicMin_310641; l310639: ; atomicMin_310641 = patomicMin_310641; return ; } __global__ __launch_bounds__ (128 * 1 * 1) void lambda_236333(int* _236336_307755, int _236337_307756, short* _236338_307757, int _236339_307758) { int tid_307761; int ptid_307761; int* sm_sum_307769; int* psm_sum_307769; int lower_307772; int plower_307772; int upper_307773; int pupper_307773; int step_307774; int pstep_307774; int sum_307775; int psum_307775; int atomicAdd_307874; int patomicAdd_307874; int threadIdx_x_307780; int pthreadIdx_x_307780; int blockDim_x_307783; int pblockDim_x_307783; int blockIdx_x_307786; int pblockIdx_x_307786; int converge_307804; int pconverge_307804; tid_307761 = threadIdx_x(); ptid_307761 = tid_307761; l307759: ; tid_307761 = ptid_307761; __shared__ int reserver_sm_sum_307769[128]; psm_sum_307769 = reserver_sm_sum_307769; l307767: ; sm_sum_307769 = psm_sum_307769; int _307787; _307787 = 2 * _236337_307756; int _307788; _307788 = 64 + _307787; int _307789; _307789 = _307788 - 1; int _307790; _307790 = _307789 / 64; int _307791; _307791 = 64 * _307790; int stride_307792; stride_307792 = _307791 / 2; plower_307772 = 0; pupper_307773 = _236339_307758; pstep_307774 = 1; psum_307775 = 0; goto l307770; l307770: ; lower_307772 = plower_307772; upper_307773 = pupper_307773; step_307774 = pstep_307774; sum_307775 = psum_307775; bool _307776; _307776 = lower_307772 < upper_307773; if (_307776) goto l307777; else goto l307809; l307809: ; int* tid_307813; tid_307813 = sm_sum_307769 + tid_307761; *tid_307813 = sum_307775; __syncthreads(); l307815: ; bool _307817; _307817 = tid_307761 < 64; if (_307817) goto l307818; else goto l307952; l307952: ; goto l307819; l307818: ; int _307942; _307942 = 64 + tid_307761; int* _307943; _307943 = sm_sum_307769 + _307942; int _307944; _307944 = *_307943; int _307949; _307949 = _307944; int _307946; _307946 = *tid_307813; int _307948; _307948 = _307946; int _307950; _307950 = _307948 + _307949; *tid_307813 = _307950; goto l307819; l307819: ; __syncthreads(); l307821: ; bool _307824; _307824 = tid_307761 < 32; if (_307824) goto l307825; else goto l307941; l307941: ; goto l307826; l307825: ; int _307931; _307931 = 32 + tid_307761; int* _307932; _307932 = sm_sum_307769 + _307931; int _307933; _307933 = *_307932; int _307938; _307938 = _307933; int _307935; _307935 = *tid_307813; int _307937; _307937 = _307935; int _307939; _307939 = _307937 + _307938; *tid_307813 = _307939; goto l307826; l307826: ; __syncthreads(); l307828: ; bool _307830; _307830 = tid_307761 < 16; if (_307830) goto l307831; else goto l307930; l307930: ; goto l307832; l307831: ; int _307920; _307920 = 16 + tid_307761; int* _307921; _307921 = sm_sum_307769 + _307920; int _307922; _307922 = *_307921; int _307927; _307927 = _307922; int _307924; _307924 = *tid_307813; int _307926; _307926 = _307924; int _307928; _307928 = _307926 + _307927; *tid_307813 = _307928; goto l307832; l307832: ; __syncthreads(); l307834: ; bool _307836; _307836 = tid_307761 < 8; if (_307836) goto l307837; else goto l307919; l307919: ; goto l307838; l307837: ; int _307909; _307909 = 8 + tid_307761; int* _307910; _307910 = sm_sum_307769 + _307909; int _307911; _307911 = *_307910; int _307916; _307916 = _307911; int _307913; _307913 = *tid_307813; int _307915; _307915 = _307913; int _307917; _307917 = _307915 + _307916; *tid_307813 = _307917; goto l307838; l307838: ; __syncthreads(); l307840: ; bool _307842; _307842 = tid_307761 < 4; if (_307842) goto l307843; else goto l307908; l307908: ; goto l307844; l307843: ; int _307898; _307898 = 4 + tid_307761; int* _307899; _307899 = sm_sum_307769 + _307898; int _307900; _307900 = *_307899; int _307905; _307905 = _307900; int _307902; _307902 = *tid_307813; int _307904; _307904 = _307902; int _307906; _307906 = _307904 + _307905; *tid_307813 = _307906; goto l307844; l307844: ; __syncthreads(); l307846: ; bool _307848; _307848 = tid_307761 < 2; if (_307848) goto l307849; else goto l307897; l307897: ; goto l307850; l307849: ; int _307887; _307887 = 2 + tid_307761; int* _307888; _307888 = sm_sum_307769 + _307887; int _307889; _307889 = *_307888; int _307894; _307894 = _307889; int _307891; _307891 = *tid_307813; int _307893; _307893 = _307891; int _307895; _307895 = _307893 + _307894; *tid_307813 = _307895; goto l307850; l307850: ; __syncthreads(); l307852: ; bool _307854; _307854 = tid_307761 < 1; if (_307854) goto l307855; else goto l307886; l307886: ; goto l307856; l307855: ; int _307876; _307876 = 1 + tid_307761; int* _307877; _307877 = sm_sum_307769 + _307876; int _307878; _307878 = *_307877; int _307883; _307883 = _307878; int _307880; _307880 = *tid_307813; int _307882; _307882 = _307880; int _307884; _307884 = _307882 + _307883; *tid_307813 = _307884; goto l307856; l307856: ; __syncthreads(); l307858: ; bool _307860; _307860 = tid_307761 == 0; if (_307860) goto l307861; else goto l307875; l307875: ; return ; l307861: ; int* sum_307870; sum_307870 = _236336_307755 + 0; int* sum_307867; sum_307867 = sm_sum_307769 + 0; int _307868; _307868 = *sum_307867; int _307871; _307871 = _307868; atomicAdd_307874 = atomicAdd(sum_307870, _307871); patomicAdd_307874 = atomicAdd_307874; l307872: ; atomicAdd_307874 = patomicAdd_307874; return ; l307777: ; threadIdx_x_307780 = threadIdx_x(); pthreadIdx_x_307780 = threadIdx_x_307780; l307778: ; threadIdx_x_307780 = pthreadIdx_x_307780; blockDim_x_307783 = blockDim_x(); pblockDim_x_307783 = blockDim_x_307783; l307781: ; blockDim_x_307783 = pblockDim_x_307783; blockIdx_x_307786 = blockIdx_x(); pblockIdx_x_307786 = blockIdx_x_307786; l307784: ; blockIdx_x_307786 = pblockIdx_x_307786; int _307794; _307794 = blockDim_x_307783 * blockIdx_x_307786; int _307793; _307793 = lower_307772 * stride_307792; int _307795; _307795 = threadIdx_x_307780 + _307794; int _307796; _307796 = _307793 + _307795; short* idx_307797; idx_307797 = _236338_307757 + _307796; short _307798; _307798 = *idx_307797; short _307799; _307799 = _307798; bool _307801; _307801 = _307799 == 0; if (_307801) goto l307802; else goto l307808; l307808: ; pconverge_307804 = 1; goto l307803; l307802: ; pconverge_307804 = 0; goto l307803; l307803: ; converge_307804 = pconverge_307804; int _307807; _307807 = sum_307775 + converge_307804; int _307806; _307806 = lower_307772 + step_307774; plower_307772 = _307806; pupper_307773 = upper_307773; pstep_307774 = step_307774; psum_307775 = _307807; goto l307770; } __global__ __launch_bounds__ (32 * 4 * 1) void lambda_235522(int _235525_310124, int _235526_310125, short* _235527_310126, short* _235528_310127) { int threadIdx_x_310130; int pthreadIdx_x_310130; int blockDim_x_310133; int pblockDim_x_310133; int blockIdx_x_310136; int pblockIdx_x_310136; int _310139; int p_310139; int _310142; int p_310142; int _310145; int p_310145; int _310148; int p_310148; int converge_310155; int pconverge_310155; int converge_310159; int pconverge_310159; int converge_310166; int pconverge_310166; int converge_310170; int pconverge_310170; int converge_310173; int pconverge_310173; int converge_310177; int pconverge_310177; int converge_310180; int pconverge_310180; int converge_310184; int pconverge_310184; int converge_310188; int pconverge_310188; int converge_310192; int pconverge_310192; int converge_310195; int pconverge_310195; int converge_310199; int pconverge_310199; int converge_310204; int pconverge_310204; int converge_310208; int pconverge_310208; int converge_310211; int pconverge_310211; int converge_310215; int pconverge_310215; int converge_310218; int pconverge_310218; int converge_310222; int pconverge_310222; int converge_310225; int pconverge_310225; int converge_310229; int pconverge_310229; int converge_310232; int pconverge_310232; int converge_310236; int pconverge_310236; int converge_310240; int pconverge_310240; int converge_310244; int pconverge_310244; int converge_310247; int pconverge_310247; int converge_310251; int pconverge_310251; int converge_310254; int pconverge_310254; int converge_310258; int pconverge_310258; int converge_310261; int pconverge_310261; int converge_310265; int pconverge_310265; int converge_310270; int pconverge_310270; int converge_310274; int pconverge_310274; int converge_310277; int pconverge_310277; int converge_310281; int pconverge_310281; int converge_310284; int pconverge_310284; int converge_310288; int pconverge_310288; int converge_310291; int pconverge_310291; int converge_310295; int pconverge_310295; int converge_310298; int pconverge_310298; int converge_310302; int pconverge_310302; int converge_310305; int pconverge_310305; int converge_310309; int pconverge_310309; int converge_310312; int pconverge_310312; int converge_310316; int pconverge_310316; int converge_310319; int pconverge_310319; int converge_310323; int pconverge_310323; int converge_310326; int pconverge_310326; int converge_310330; int pconverge_310330; float sqrtf_310443; float psqrtf_310443; short val_310449; short pval_310449; threadIdx_x_310130 = threadIdx_x(); pthreadIdx_x_310130 = threadIdx_x_310130; l310128: ; threadIdx_x_310130 = pthreadIdx_x_310130; blockDim_x_310133 = blockDim_x(); pblockDim_x_310133 = blockDim_x_310133; l310131: ; blockDim_x_310133 = pblockDim_x_310133; blockIdx_x_310136 = blockIdx_x(); pblockIdx_x_310136 = blockIdx_x_310136; l310134: ; blockIdx_x_310136 = pblockIdx_x_310136; _310139 = threadIdx_y(); p_310139 = _310139; l310137: ; _310139 = p_310139; _310142 = blockDim_y(); p_310142 = _310142; l310140: ; _310142 = p_310142; _310145 = blockIdx_y(); p_310145 = _310145; l310143: ; _310145 = p_310145; _310148 = blockDim_y(); p_310148 = _310148; l310146: ; _310148 = p_310148; int _310149; _310149 = blockDim_x_310133 * blockIdx_x_310136; int _310150; _310150 = threadIdx_x_310130 + _310149; int _310151; _310151 = -1 + _310150; int _310507; _310507 = 0 - _310151; bool _310152; _310152 = _310151 < 0; int _310508; _310508 = _310507 - 1; if (_310152) goto l310153; else goto l310593; l310593: ; pconverge_310155 = _310151; goto l310154; l310153: ; pconverge_310155 = _310508; goto l310154; l310154: ; converge_310155 = pconverge_310155; bool _310156; _310156 = _235525_310124 <= converge_310155; if (_310156) goto l310157; else goto l310592; l310592: ; pconverge_310159 = converge_310155; goto l310158; l310157: ; int _310589; _310589 = 1 + converge_310155; int _310590; _310590 = _310589 - _235525_310124; int _310591; _310591 = _235525_310124 - _310590; pconverge_310159 = _310591; goto l310158; l310158: ; converge_310159 = pconverge_310159; int _310160; _310160 = _310142 * _310145; int gid_y_310161; gid_y_310161 = _310139 + _310160; int _310162; _310162 = -1 + gid_y_310161; bool _310163; _310163 = _310162 < 0; int _310546; _310546 = 0 - _310162; int _310547; _310547 = _310546 - 1; if (_310163) goto l310164; else goto l310588; l310588: ; pconverge_310166 = _310162; goto l310165; l310164: ; pconverge_310166 = _310547; goto l310165; l310165: ; converge_310166 = pconverge_310166; bool _310167; _310167 = _235526_310125 <= converge_310166; if (_310167) goto l310168; else goto l310587; l310587: ; pconverge_310170 = converge_310166; goto l310169; l310168: ; int _310584; _310584 = 1 + converge_310166; int _310585; _310585 = _310584 - _235526_310125; int _310586; _310586 = _235526_310125 - _310585; pconverge_310170 = _310586; goto l310169; l310169: ; converge_310170 = pconverge_310170; if (_310152) goto l310171; else goto l310583; l310583: ; pconverge_310173 = _310151; goto l310172; l310171: ; pconverge_310173 = _310508; goto l310172; l310172: ; converge_310173 = pconverge_310173; bool _310174; _310174 = _235525_310124 <= converge_310173; if (_310174) goto l310175; else goto l310582; l310582: ; pconverge_310177 = converge_310173; goto l310176; l310175: ; int _310579; _310579 = 1 + converge_310173; int _310580; _310580 = _310579 - _235525_310124; int _310581; _310581 = _235525_310124 - _310580; pconverge_310177 = _310581; goto l310176; l310176: ; converge_310177 = pconverge_310177; if (_310163) goto l310178; else goto l310578; l310578: ; pconverge_310180 = _310162; goto l310179; l310178: ; pconverge_310180 = _310547; goto l310179; l310179: ; converge_310180 = pconverge_310180; bool _310181; _310181 = _235526_310125 <= converge_310180; if (_310181) goto l310182; else goto l310577; l310577: ; pconverge_310184 = converge_310180; goto l310183; l310182: ; int _310574; _310574 = 1 + converge_310180; int _310575; _310575 = _310574 - _235526_310125; int _310576; _310576 = _235526_310125 - _310575; pconverge_310184 = _310576; goto l310183; l310183: ; converge_310184 = pconverge_310184; int _310495; _310495 = 0 - _310150; int _310496; _310496 = _310495 - 1; bool _310185; _310185 = _310150 < 0; if (_310185) goto l310186; else goto l310573; l310573: ; pconverge_310188 = _310150; goto l310187; l310186: ; pconverge_310188 = _310496; goto l310187; l310187: ; converge_310188 = pconverge_310188; bool _310189; _310189 = _235525_310124 <= converge_310188; if (_310189) goto l310190; else goto l310572; l310572: ; pconverge_310192 = converge_310188; goto l310191; l310190: ; int _310569; _310569 = 1 + converge_310188; int _310570; _310570 = _310569 - _235525_310124; int _310571; _310571 = _235525_310124 - _310570; pconverge_310192 = _310571; goto l310191; l310191: ; converge_310192 = pconverge_310192; if (_310163) goto l310193; else goto l310568; l310568: ; pconverge_310195 = _310162; goto l310194; l310193: ; pconverge_310195 = _310547; goto l310194; l310194: ; converge_310195 = pconverge_310195; bool _310196; _310196 = _235526_310125 <= converge_310195; if (_310196) goto l310197; else goto l310567; l310567: ; pconverge_310199 = converge_310195; goto l310198; l310197: ; int _310564; _310564 = 1 + converge_310195; int _310565; _310565 = _310564 - _235526_310125; int _310566; _310566 = _235526_310125 - _310565; pconverge_310199 = _310566; goto l310198; l310198: ; converge_310199 = pconverge_310199; int _310200; _310200 = 1 + _310150; int _310473; _310473 = 0 - _310200; bool _310201; _310201 = _310200 < 0; int _310474; _310474 = _310473 - 1; if (_310201) goto l310202; else goto l310563; l310563: ; pconverge_310204 = _310200; goto l310203; l310202: ; pconverge_310204 = _310474; goto l310203; l310203: ; converge_310204 = pconverge_310204; bool _310205; _310205 = _235525_310124 <= converge_310204; if (_310205) goto l310206; else goto l310562; l310562: ; pconverge_310208 = converge_310204; goto l310207; l310206: ; int _310559; _310559 = 1 + converge_310204; int _310560; _310560 = _310559 - _235525_310124; int _310561; _310561 = _235525_310124 - _310560; pconverge_310208 = _310561; goto l310207; l310207: ; converge_310208 = pconverge_310208; if (_310163) goto l310209; else goto l310558; l310558: ; pconverge_310211 = _310162; goto l310210; l310209: ; pconverge_310211 = _310547; goto l310210; l310210: ; converge_310211 = pconverge_310211; bool _310212; _310212 = _235526_310125 <= converge_310211; if (_310212) goto l310213; else goto l310557; l310557: ; pconverge_310215 = converge_310211; goto l310214; l310213: ; int _310554; _310554 = 1 + converge_310211; int _310555; _310555 = _310554 - _235526_310125; int _310556; _310556 = _235526_310125 - _310555; pconverge_310215 = _310556; goto l310214; l310214: ; converge_310215 = pconverge_310215; if (_310201) goto l310216; else goto l310553; l310553: ; pconverge_310218 = _310200; goto l310217; l310216: ; pconverge_310218 = _310474; goto l310217; l310217: ; converge_310218 = pconverge_310218; bool _310219; _310219 = _235525_310124 <= converge_310218; if (_310219) goto l310220; else goto l310552; l310552: ; pconverge_310222 = converge_310218; goto l310221; l310220: ; int _310549; _310549 = 1 + converge_310218; int _310550; _310550 = _310549 - _235525_310124; int _310551; _310551 = _235525_310124 - _310550; pconverge_310222 = _310551; goto l310221; l310221: ; converge_310222 = pconverge_310222; if (_310163) goto l310223; else goto l310548; l310548: ; pconverge_310225 = _310162; goto l310224; l310223: ; pconverge_310225 = _310547; goto l310224; l310224: ; converge_310225 = pconverge_310225; bool _310226; _310226 = _235526_310125 <= converge_310225; if (_310226) goto l310227; else goto l310545; l310545: ; pconverge_310229 = converge_310225; goto l310228; l310227: ; int _310542; _310542 = 1 + converge_310225; int _310543; _310543 = _310542 - _235526_310125; int _310544; _310544 = _235526_310125 - _310543; pconverge_310229 = _310544; goto l310228; l310228: ; converge_310229 = pconverge_310229; if (_310152) goto l310230; else goto l310541; l310541: ; pconverge_310232 = _310151; goto l310231; l310230: ; pconverge_310232 = _310508; goto l310231; l310231: ; converge_310232 = pconverge_310232; bool _310233; _310233 = _235525_310124 <= converge_310232; if (_310233) goto l310234; else goto l310540; l310540: ; pconverge_310236 = converge_310232; goto l310235; l310234: ; int _310537; _310537 = 1 + converge_310232; int _310538; _310538 = _310537 - _235525_310124; int _310539; _310539 = _235525_310124 - _310538; pconverge_310236 = _310539; goto l310235; l310235: ; converge_310236 = pconverge_310236; int _310524; _310524 = 0 - gid_y_310161; bool _310237; _310237 = gid_y_310161 < 0; int _310525; _310525 = _310524 - 1; if (_310237) goto l310238; else goto l310536; l310536: ; pconverge_310240 = gid_y_310161; goto l310239; l310238: ; pconverge_310240 = _310525; goto l310239; l310239: ; converge_310240 = pconverge_310240; bool _310241; _310241 = _235526_310125 <= converge_310240; if (_310241) goto l310242; else goto l310535; l310535: ; pconverge_310244 = converge_310240; goto l310243; l310242: ; int _310532; _310532 = 1 + converge_310240; int _310533; _310533 = _310532 - _235526_310125; int _310534; _310534 = _235526_310125 - _310533; pconverge_310244 = _310534; goto l310243; l310243: ; converge_310244 = pconverge_310244; if (_310201) goto l310245; else goto l310531; l310531: ; pconverge_310247 = _310200; goto l310246; l310245: ; pconverge_310247 = _310474; goto l310246; l310246: ; converge_310247 = pconverge_310247; bool _310248; _310248 = _235525_310124 <= converge_310247; if (_310248) goto l310249; else goto l310530; l310530: ; pconverge_310251 = converge_310247; goto l310250; l310249: ; int _310527; _310527 = 1 + converge_310247; int _310528; _310528 = _310527 - _235525_310124; int _310529; _310529 = _235525_310124 - _310528; pconverge_310251 = _310529; goto l310250; l310250: ; converge_310251 = pconverge_310251; if (_310237) goto l310252; else goto l310526; l310526: ; pconverge_310254 = gid_y_310161; goto l310253; l310252: ; pconverge_310254 = _310525; goto l310253; l310253: ; converge_310254 = pconverge_310254; bool _310255; _310255 = _235526_310125 <= converge_310254; if (_310255) goto l310256; else goto l310523; l310523: ; pconverge_310258 = converge_310254; goto l310257; l310256: ; int _310520; _310520 = 1 + converge_310254; int _310521; _310521 = _310520 - _235526_310125; int _310522; _310522 = _235526_310125 - _310521; pconverge_310258 = _310522; goto l310257; l310257: ; converge_310258 = pconverge_310258; if (_310152) goto l310259; else goto l310519; l310519: ; pconverge_310261 = _310151; goto l310260; l310259: ; pconverge_310261 = _310508; goto l310260; l310260: ; converge_310261 = pconverge_310261; bool _310262; _310262 = _235525_310124 <= converge_310261; if (_310262) goto l310263; else goto l310518; l310518: ; pconverge_310265 = converge_310261; goto l310264; l310263: ; int _310515; _310515 = 1 + converge_310261; int _310516; _310516 = _310515 - _235525_310124; int _310517; _310517 = _235525_310124 - _310516; pconverge_310265 = _310517; goto l310264; l310264: ; converge_310265 = pconverge_310265; int _310266; _310266 = 1 + gid_y_310161; int _310466; _310466 = 0 - _310266; int _310467; _310467 = _310466 - 1; bool _310267; _310267 = _310266 < 0; if (_310267) goto l310268; else goto l310514; l310514: ; pconverge_310270 = _310266; goto l310269; l310268: ; pconverge_310270 = _310467; goto l310269; l310269: ; converge_310270 = pconverge_310270; bool _310271; _310271 = _235526_310125 <= converge_310270; if (_310271) goto l310272; else goto l310513; l310513: ; pconverge_310274 = converge_310270; goto l310273; l310272: ; int _310510; _310510 = 1 + converge_310270; int _310511; _310511 = _310510 - _235526_310125; int _310512; _310512 = _235526_310125 - _310511; pconverge_310274 = _310512; goto l310273; l310273: ; converge_310274 = pconverge_310274; if (_310152) goto l310275; else goto l310509; l310509: ; pconverge_310277 = _310151; goto l310276; l310275: ; pconverge_310277 = _310508; goto l310276; l310276: ; converge_310277 = pconverge_310277; bool _310278; _310278 = _235525_310124 <= converge_310277; if (_310278) goto l310279; else goto l310506; l310506: ; pconverge_310281 = converge_310277; goto l310280; l310279: ; int _310503; _310503 = 1 + converge_310277; int _310504; _310504 = _310503 - _235525_310124; int _310505; _310505 = _235525_310124 - _310504; pconverge_310281 = _310505; goto l310280; l310280: ; converge_310281 = pconverge_310281; if (_310267) goto l310282; else goto l310502; l310502: ; pconverge_310284 = _310266; goto l310283; l310282: ; pconverge_310284 = _310467; goto l310283; l310283: ; converge_310284 = pconverge_310284; bool _310285; _310285 = _235526_310125 <= converge_310284; if (_310285) goto l310286; else goto l310501; l310501: ; pconverge_310288 = converge_310284; goto l310287; l310286: ; int _310498; _310498 = 1 + converge_310284; int _310499; _310499 = _310498 - _235526_310125; int _310500; _310500 = _235526_310125 - _310499; pconverge_310288 = _310500; goto l310287; l310287: ; converge_310288 = pconverge_310288; if (_310185) goto l310289; else goto l310497; l310497: ; pconverge_310291 = _310150; goto l310290; l310289: ; pconverge_310291 = _310496; goto l310290; l310290: ; converge_310291 = pconverge_310291; bool _310292; _310292 = _235525_310124 <= converge_310291; if (_310292) goto l310293; else goto l310494; l310494: ; pconverge_310295 = converge_310291; goto l310294; l310293: ; int _310491; _310491 = 1 + converge_310291; int _310492; _310492 = _310491 - _235525_310124; int _310493; _310493 = _235525_310124 - _310492; pconverge_310295 = _310493; goto l310294; l310294: ; converge_310295 = pconverge_310295; if (_310267) goto l310296; else goto l310490; l310490: ; pconverge_310298 = _310266; goto l310297; l310296: ; pconverge_310298 = _310467; goto l310297; l310297: ; converge_310298 = pconverge_310298; bool _310299; _310299 = _235526_310125 <= converge_310298; if (_310299) goto l310300; else goto l310489; l310489: ; pconverge_310302 = converge_310298; goto l310301; l310300: ; int _310486; _310486 = 1 + converge_310298; int _310487; _310487 = _310486 - _235526_310125; int _310488; _310488 = _235526_310125 - _310487; pconverge_310302 = _310488; goto l310301; l310301: ; converge_310302 = pconverge_310302; if (_310201) goto l310303; else goto l310485; l310485: ; pconverge_310305 = _310200; goto l310304; l310303: ; pconverge_310305 = _310474; goto l310304; l310304: ; converge_310305 = pconverge_310305; bool _310306; _310306 = _235525_310124 <= converge_310305; if (_310306) goto l310307; else goto l310484; l310484: ; pconverge_310309 = converge_310305; goto l310308; l310307: ; int _310481; _310481 = 1 + converge_310305; int _310482; _310482 = _310481 - _235525_310124; int _310483; _310483 = _235525_310124 - _310482; pconverge_310309 = _310483; goto l310308; l310308: ; converge_310309 = pconverge_310309; if (_310267) goto l310310; else goto l310480; l310480: ; pconverge_310312 = _310266; goto l310311; l310310: ; pconverge_310312 = _310467; goto l310311; l310311: ; converge_310312 = pconverge_310312; bool _310313; _310313 = _235526_310125 <= converge_310312; if (_310313) goto l310314; else goto l310479; l310479: ; pconverge_310316 = converge_310312; goto l310315; l310314: ; int _310476; _310476 = 1 + converge_310312; int _310477; _310477 = _310476 - _235526_310125; int _310478; _310478 = _235526_310125 - _310477; pconverge_310316 = _310478; goto l310315; l310315: ; converge_310316 = pconverge_310316; if (_310201) goto l310317; else goto l310475; l310475: ; pconverge_310319 = _310200; goto l310318; l310317: ; pconverge_310319 = _310474; goto l310318; l310318: ; converge_310319 = pconverge_310319; bool _310320; _310320 = _235525_310124 <= converge_310319; if (_310320) goto l310321; else goto l310472; l310472: ; pconverge_310323 = converge_310319; goto l310322; l310321: ; int _310469; _310469 = 1 + converge_310319; int _310470; _310470 = _310469 - _235525_310124; int _310471; _310471 = _235525_310124 - _310470; pconverge_310323 = _310471; goto l310322; l310322: ; converge_310323 = pconverge_310323; if (_310267) goto l310324; else goto l310468; l310468: ; pconverge_310326 = _310266; goto l310325; l310324: ; pconverge_310326 = _310467; goto l310325; l310325: ; converge_310326 = pconverge_310326; bool _310327; _310327 = _235526_310125 <= converge_310326; if (_310327) goto l310328; else goto l310465; l310465: ; pconverge_310330 = converge_310326; goto l310329; l310328: ; int _310462; _310462 = 1 + converge_310326; int _310463; _310463 = _310462 - _235526_310125; int _310464; _310464 = _235526_310125 - _310463; pconverge_310330 = _310464; goto l310329; l310329: ; converge_310330 = pconverge_310330; int _310375; _310375 = converge_310288 * _235525_310124; int _310365; _310365 = converge_310258 * _235525_310124; int _310350; _310350 = converge_310215 * _235525_310124; int _310360; _310360 = converge_310244 * _235525_310124; int _310380; _310380 = converge_310302 * _235525_310124; int _310340; _310340 = converge_310184 * _235525_310124; int _310335; _310335 = converge_310170 * _235525_310124; int _310385; _310385 = converge_310316 * _235525_310124; int _310341; _310341 = _310340 + converge_310177; int _310386; _310386 = _310385 + converge_310309; short* idx_310387; idx_310387 = _235528_310127 + _310386; int _310345; _310345 = converge_310199 * _235525_310124; int _310390; _310390 = converge_310330 * _235525_310124; int _310336; _310336 = _310335 + converge_310159; int _310370; _310370 = converge_310274 * _235525_310124; int _310376; _310376 = _310375 + converge_310281; int _310346; _310346 = _310345 + converge_310192; int _310355; _310355 = converge_310229 * _235525_310124; int _310366; _310366 = _310365 + converge_310251; int _310351; _310351 = _310350 + converge_310208; int _310361; _310361 = _310360 + converge_310236; int _310381; _310381 = _310380 + converge_310295; short* idx_310342; idx_310342 = _235528_310127 + _310341; int _310391; _310391 = _310390 + converge_310323; short* idx_310337; idx_310337 = _235528_310127 + _310336; int _310371; _310371 = _310370 + converge_310265; short* idx_310377; idx_310377 = _235528_310127 + _310376; short* idx_310347; idx_310347 = _235528_310127 + _310346; int _310356; _310356 = _310355 + converge_310222; short* idx_310367; idx_310367 = _235528_310127 + _310366; short* idx_310352; idx_310352 = _235528_310127 + _310351; short* idx_310362; idx_310362 = _235528_310127 + _310361; short* idx_310382; idx_310382 = _235528_310127 + _310381; short* idx_310392; idx_310392 = _235528_310127 + _310391; short _310338; _310338 = *idx_310337; short* idx_310372; idx_310372 = _235528_310127 + _310371; short* idx_310357; idx_310357 = _235528_310127 + _310356; short _310395; _310395 = _310338; int _310396; _310396 = (int)_310395; short _310343; _310343 = *idx_310342; int _310397; _310397 = -1 * _310396; short _310417; _310417 = _310343; int _310418; _310418 = (int)_310417; short _310348; _310348 = *idx_310347; short _310398; _310398 = _310348; int _310399; _310399 = (int)_310398; short _310353; _310353 = *idx_310352; int _310400; _310400 = -2 * _310399; short _310402; _310402 = _310353; int _310401; _310401 = _310397 + _310400; int _310403; _310403 = (int)_310402; short _310358; _310358 = *idx_310357; int _310404; _310404 = -1 * _310403; short _310419; _310419 = _310358; int _310405; _310405 = _310401 + _310404; int _310420; _310420 = (int)_310419; short _310363; _310363 = *idx_310362; int _310421; _310421 = -1 * _310420; short _310423; _310423 = _310363; int _310422; _310422 = _310418 + _310421; int _310424; _310424 = (int)_310423; short _310368; _310368 = *idx_310367; int _310425; _310425 = 2 * _310424; short _310427; _310427 = _310368; int _310426; _310426 = _310422 + _310425; int _310428; _310428 = (int)_310427; short _310373; _310373 = *idx_310372; int _310429; _310429 = -2 * _310428; short _310406; _310406 = _310373; int _310430; _310430 = _310426 + _310429; int _310407; _310407 = (int)_310406; short _310378; _310378 = *idx_310377; int _310408; _310408 = _310405 + _310407; short _310431; _310431 = _310378; short _310383; _310383 = *idx_310382; int _310432; _310432 = (int)_310431; short _310409; _310409 = _310383; int _310433; _310433 = _310430 + _310432; short _310388; _310388 = *idx_310387; int _310410; _310410 = (int)_310409; short _310413; _310413 = _310388; int _310411; _310411 = 2 * _310410; short _310393; _310393 = *idx_310392; int _310414; _310414 = (int)_310413; int _310412; _310412 = _310408 + _310411; short _310434; _310434 = _310393; int _310415; _310415 = _310412 + _310414; int _310435; _310435 = (int)_310434; int _310416; _310416 = _310415 * _310415; int _310436; _310436 = -1 * _310435; int _310437; _310437 = _310433 + _310436; int _310438; _310438 = _310437 * _310437; int _310439; _310439 = _310416 + _310438; float _310440; _310440 = (float)_310439; sqrtf_310443 = sqrtf(_310440); psqrtf_310443 = sqrtf_310443; l310441: ; sqrtf_310443 = psqrtf_310443; short g_310445; g_310445 = (short)sqrtf_310443; bool _310446; _310446 = 150 < g_310445; if (_310446) goto l310447; else goto l310461; l310461: ; pval_310449 = 0; goto l310448; l310447: ; pval_310449 = 1; goto l310448; l310448: ; val_310449 = pval_310449; int _310450; _310450 = 2 * _235525_310124; int _310451; _310451 = 64 + _310450; int _310452; _310452 = _310451 - 1; int _310453; _310453 = _310452 / 64; int _310454; _310454 = 64 * _310453; int stride_310455; stride_310455 = _310454 / 2; int _310456; _310456 = gid_y_310161 * stride_310455; int _310457; _310457 = _310456 + _310150; short* idx_310458; idx_310458 = _235527_310126 + _310457; *idx_310458 = val_310449; return ; } __global__ __launch_bounds__ (64 * 1 * 1) void lambda_236828(int* _236831_307956) { int threadIdx_x_307959; int pthreadIdx_x_307959; int blockDim_x_307962; int pblockDim_x_307962; int blockIdx_x_307965; int pblockIdx_x_307965; threadIdx_x_307959 = threadIdx_x(); pthreadIdx_x_307959 = threadIdx_x_307959; l307957: ; threadIdx_x_307959 = pthreadIdx_x_307959; blockDim_x_307962 = blockDim_x(); pblockDim_x_307962 = blockDim_x_307962; l307960: ; blockDim_x_307962 = pblockDim_x_307962; blockIdx_x_307965 = blockIdx_x(); pblockIdx_x_307965 = blockIdx_x_307965; l307963: ; blockIdx_x_307965 = pblockIdx_x_307965; int _307966; _307966 = blockDim_x_307962 * blockIdx_x_307965; int _307967; _307967 = threadIdx_x_307959 + _307966; int* _307968; _307968 = _236831_307956 + _307967; *_307968 = 0; return ; } __global__ __launch_bounds__ (128 * 1 * 1) void lambda_237182(int* _237185_309742, int* _237186_309743, int* _237187_309744) { int threadIdx_x_309747; int pthreadIdx_x_309747; int blockDim_x_309750; int pblockDim_x_309750; int blockIdx_x_309753; int pblockIdx_x_309753; int tid_309756; int ptid_309756; int* sm_tmp_309764; int* psm_tmp_309764; int _309877; int p_309877; threadIdx_x_309747 = threadIdx_x(); pthreadIdx_x_309747 = threadIdx_x_309747; l309745: ; threadIdx_x_309747 = pthreadIdx_x_309747; blockDim_x_309750 = blockDim_x(); pblockDim_x_309750 = blockDim_x_309750; l309748: ; blockDim_x_309750 = pblockDim_x_309750; blockIdx_x_309753 = blockIdx_x(); pblockIdx_x_309753 = blockIdx_x_309753; l309751: ; blockIdx_x_309753 = pblockIdx_x_309753; tid_309756 = threadIdx_x(); ptid_309756 = tid_309756; l309754: ; tid_309756 = ptid_309756; __shared__ int reserver_sm_tmp_309764[256]; psm_tmp_309764 = reserver_sm_tmp_309764; l309762: ; sm_tmp_309764 = psm_tmp_309764; int _309771; _309771 = 2 * tid_309756; int _309765; _309765 = blockDim_x_309750 * blockIdx_x_309753; int _309779; _309779 = 1 + _309771; int* _309772; _309772 = sm_tmp_309764 + _309771; int* _309780; _309780 = sm_tmp_309764 + _309779; int _309766; _309766 = threadIdx_x_309747 + _309765; int _309767; _309767 = 2 * _309766; int _309775; _309775 = 1 + _309767; int* _309768; _309768 = _237185_309742 + _309767; int* _309776; _309776 = _237185_309742 + _309775; int _309769; _309769 = *_309768; int _309773; _309773 = _309769; *_309772 = _309773; int _309777; _309777 = *_309776; int _309781; _309781 = _309777; *_309780 = _309781; __syncthreads(); l309783: ; bool _309785; _309785 = tid_309756 < 128; int _309902; _309902 = 2 + _309771; int bi_309903; bi_309903 = _309902 - 1; int ai_309898; ai_309898 = _309779 - 1; int* bi_309904; bi_309904 = sm_tmp_309764 + bi_309903; int* ai_309899; ai_309899 = sm_tmp_309764 + ai_309898; if (_309785) goto l309786; else goto l310120; l310120: ; goto l309787; l309786: ; int _310112; _310112 = *ai_309899; int _310117; _310117 = _310112; int _310114; _310114 = *bi_309904; int _310116; _310116 = _310114; int _310118; _310118 = _310116 + _310117; *bi_309904 = _310118; goto l309787; l309787: ; __syncthreads(); l309789: ; int _309916; _309916 = 2 * _309779; bool _309791; _309791 = tid_309756 < 64; int _309921; _309921 = 2 * _309902; int bi_309922; bi_309922 = _309921 - 1; int ai_309917; ai_309917 = _309916 - 1; int* bi_309923; bi_309923 = sm_tmp_309764 + bi_309922; int* ai_309918; ai_309918 = sm_tmp_309764 + ai_309917; if (_309791) goto l309792; else goto l310111; l310111: ; goto l309793; l309792: ; int _310103; _310103 = *ai_309918; int _310105; _310105 = *bi_309923; int _310108; _310108 = _310103; int _310107; _310107 = _310105; int _310109; _310109 = _310107 + _310108; *bi_309923 = _310109; goto l309793; l309793: ; __syncthreads(); l309795: ; bool _309797; _309797 = tid_309756 < 32; int _309940; _309940 = 4 * _309902; int _309935; _309935 = 4 * _309779; int bi_309941; bi_309941 = _309940 - 1; int ai_309936; ai_309936 = _309935 - 1; int* bi_309942; bi_309942 = sm_tmp_309764 + bi_309941; int* ai_309937; ai_309937 = sm_tmp_309764 + ai_309936; if (_309797) goto l309798; else goto l310102; l310102: ; goto l309799; l309798: ; int _310094; _310094 = *ai_309937; int _310099; _310099 = _310094; int _310096; _310096 = *bi_309942; int _310098; _310098 = _310096; int _310100; _310100 = _310098 + _310099; *bi_309942 = _310100; goto l309799; l309799: ; __syncthreads(); l309801: ; int _309959; _309959 = 8 * _309902; int _309954; _309954 = 8 * _309779; bool _309803; _309803 = tid_309756 < 16; int bi_309960; bi_309960 = _309959 - 1; int* bi_309961; bi_309961 = sm_tmp_309764 + bi_309960; int ai_309955; ai_309955 = _309954 - 1; int* ai_309956; ai_309956 = sm_tmp_309764 + ai_309955; if (_309803) goto l309804; else goto l310093; l310093: ; goto l309805; l309804: ; int _310085; _310085 = *ai_309956; int _310090; _310090 = _310085; int _310087; _310087 = *bi_309961; int _310089; _310089 = _310087; int _310091; _310091 = _310089 + _310090; *bi_309961 = _310091; goto l309805; l309805: ; __syncthreads(); l309807: ; int _309978; _309978 = 16 * _309902; int _309973; _309973 = 16 * _309779; bool _309809; _309809 = tid_309756 < 8; int bi_309979; bi_309979 = _309978 - 1; int ai_309974; ai_309974 = _309973 - 1; int* bi_309980; bi_309980 = sm_tmp_309764 + bi_309979; int* ai_309975; ai_309975 = sm_tmp_309764 + ai_309974; if (_309809) goto l309810; else goto l310084; l310084: ; goto l309811; l309810: ; int _310076; _310076 = *ai_309975; int _310081; _310081 = _310076; int _310078; _310078 = *bi_309980; int _310080; _310080 = _310078; int _310082; _310082 = _310080 + _310081; *bi_309980 = _310082; goto l309811; l309811: ; __syncthreads(); l309813: ; bool _309815; _309815 = tid_309756 < 4; int _309997; _309997 = 32 * _309902; int _309992; _309992 = 32 * _309779; int ai_309993; ai_309993 = _309992 - 1; int bi_309998; bi_309998 = _309997 - 1; int* ai_309994; ai_309994 = sm_tmp_309764 + ai_309993; int* bi_309999; bi_309999 = sm_tmp_309764 + bi_309998; if (_309815) goto l309816; else goto l310075; l310075: ; goto l309817; l309816: ; int _310067; _310067 = *ai_309994; int _310072; _310072 = _310067; int _310069; _310069 = *bi_309999; int _310071; _310071 = _310069; int _310073; _310073 = _310071 + _310072; *bi_309999 = _310073; goto l309817; l309817: ; __syncthreads(); l309819: ; int _310011; _310011 = 64 * _309779; int ai_310012; ai_310012 = _310011 - 1; bool _309821; _309821 = tid_309756 < 2; int* ai_310013; ai_310013 = sm_tmp_309764 + ai_310012; int _310016; _310016 = 64 * _309902; int bi_310017; bi_310017 = _310016 - 1; int* bi_310018; bi_310018 = sm_tmp_309764 + bi_310017; if (_309821) goto l309822; else goto l310066; l310066: ; goto l309823; l309822: ; int _310058; _310058 = *ai_310013; int _310063; _310063 = _310058; int _310060; _310060 = *bi_310018; int _310062; _310062 = _310060; int _310064; _310064 = _310062 + _310063; *bi_310018 = _310064; goto l309823; l309823: ; __syncthreads(); l309825: ; int _310030; _310030 = 128 * _309779; int _310035; _310035 = 128 * _309902; int ai_310031; ai_310031 = _310030 - 1; bool _309827; _309827 = tid_309756 < 1; int bi_310036; bi_310036 = _310035 - 1; int* ai_310032; ai_310032 = sm_tmp_309764 + ai_310031; int* bi_310037; bi_310037 = sm_tmp_309764 + bi_310036; if (_309827) goto l309828; else goto l310057; l310057: ; goto l309829; l309828: ; int _310049; _310049 = *ai_310032; int _310051; _310051 = *bi_310037; int _310054; _310054 = _310049; int _310053; _310053 = _310051; int _310055; _310055 = _310053 + _310054; *bi_310037 = _310055; goto l309829; l309829: ; __syncthreads(); l309831: ; if (_309827) goto l309833; else goto l310048; l310048: ; goto l309834; l309833: ; int _310033; _310033 = *ai_310032; int tmp_310045; tmp_310045 = _310033; int _310038; _310038 = *bi_310037; int _310040; _310040 = _310038; *ai_310032 = _310040; int _310042; _310042 = *bi_310037; int _310044; _310044 = _310042; int _310046; _310046 = _310044 + tmp_310045; *bi_310037 = _310046; goto l309834; l309834: ; __syncthreads(); l309836: ; if (_309821) goto l309838; else goto l310029; l310029: ; goto l309839; l309838: ; int _310014; _310014 = *ai_310013; int tmp_310026; tmp_310026 = _310014; int _310019; _310019 = *bi_310018; int _310021; _310021 = _310019; *ai_310013 = _310021; int _310023; _310023 = *bi_310018; int _310025; _310025 = _310023; int _310027; _310027 = _310025 + tmp_310026; *bi_310018 = _310027; goto l309839; l309839: ; __syncthreads(); l309841: ; if (_309815) goto l309843; else goto l310010; l310010: ; goto l309844; l309843: ; int _309995; _309995 = *ai_309994; int tmp_310007; tmp_310007 = _309995; int _310000; _310000 = *bi_309999; int _310002; _310002 = _310000; *ai_309994 = _310002; int _310004; _310004 = *bi_309999; int _310006; _310006 = _310004; int _310008; _310008 = _310006 + tmp_310007; *bi_309999 = _310008; goto l309844; l309844: ; __syncthreads(); l309846: ; if (_309809) goto l309848; else goto l309991; l309991: ; goto l309849; l309848: ; int _309976; _309976 = *ai_309975; int tmp_309988; tmp_309988 = _309976; int _309981; _309981 = *bi_309980; int _309983; _309983 = _309981; *ai_309975 = _309983; int _309985; _309985 = *bi_309980; int _309987; _309987 = _309985; int _309989; _309989 = _309987 + tmp_309988; *bi_309980 = _309989; goto l309849; l309849: ; __syncthreads(); l309851: ; if (_309803) goto l309853; else goto l309972; l309972: ; goto l309854; l309853: ; int _309957; _309957 = *ai_309956; int tmp_309969; tmp_309969 = _309957; int _309962; _309962 = *bi_309961; int _309964; _309964 = _309962; *ai_309956 = _309964; int _309966; _309966 = *bi_309961; int _309968; _309968 = _309966; int _309970; _309970 = _309968 + tmp_309969; *bi_309961 = _309970; goto l309854; l309854: ; __syncthreads(); l309856: ; if (_309797) goto l309858; else goto l309953; l309953: ; goto l309859; l309858: ; int _309938; _309938 = *ai_309937; int _309943; _309943 = *bi_309942; int tmp_309950; tmp_309950 = _309938; int _309945; _309945 = _309943; *ai_309937 = _309945; int _309947; _309947 = *bi_309942; int _309949; _309949 = _309947; int _309951; _309951 = _309949 + tmp_309950; *bi_309942 = _309951; goto l309859; l309859: ; __syncthreads(); l309861: ; if (_309791) goto l309863; else goto l309934; l309934: ; goto l309864; l309863: ; int _309919; _309919 = *ai_309918; int tmp_309931; tmp_309931 = _309919; int _309924; _309924 = *bi_309923; int _309926; _309926 = _309924; *ai_309918 = _309926; int _309928; _309928 = *bi_309923; int _309930; _309930 = _309928; int _309932; _309932 = _309930 + tmp_309931; *bi_309923 = _309932; goto l309864; l309864: ; __syncthreads(); l309866: ; if (_309785) goto l309868; else goto l309915; l309915: ; goto l309869; l309868: ; int _309900; _309900 = *ai_309899; int _309905; _309905 = *bi_309904; int tmp_309912; tmp_309912 = _309900; int _309907; _309907 = _309905; *ai_309899 = _309907; int _309909; _309909 = *bi_309904; int _309911; _309911 = _309909; int _309913; _309913 = _309911 + tmp_309912; *bi_309904 = _309913; goto l309869; l309869: ; __syncthreads(); l309871: ; bool _309873; _309873 = tid_309756 == 0; if (_309873) goto l309874; else goto l309897; l309897: ; goto l309878; l309874: ; _309877 = blockIdx_x(); p_309877 = _309877; l309875: ; _309877 = p_309877; int* _309891; _309891 = sm_tmp_309764 + 255; int* _309894; _309894 = _237186_309743 + _309877; int _309892; _309892 = *_309891; int _309895; _309895 = _309892; *_309894 = _309895; goto l309878; l309878: ; int* _309882; _309882 = _237187_309744 + _309767; int* _309887; _309887 = _237187_309744 + _309775; int _309880; _309880 = *_309772; int _309883; _309883 = _309880; *_309882 = _309883; int _309885; _309885 = *_309780; int _309888; _309888 = _309885; *_309887 = _309888; return ; } __global__ __launch_bounds__ (32 * 4 * 1) void lambda_240566(int _240569_310719, short* _240570_310720, short* _240571_310721, short* _240572_310722) { int threadIdx_x_310725; int pthreadIdx_x_310725; int blockDim_x_310728; int pblockDim_x_310728; int blockIdx_x_310731; int pblockIdx_x_310731; int _310734; int p_310734; int _310737; int p_310737; int _310740; int p_310740; int _310743; int p_310743; threadIdx_x_310725 = threadIdx_x(); pthreadIdx_x_310725 = threadIdx_x_310725; l310723: ; threadIdx_x_310725 = pthreadIdx_x_310725; blockDim_x_310728 = blockDim_x(); pblockDim_x_310728 = blockDim_x_310728; l310726: ; blockDim_x_310728 = pblockDim_x_310728; blockIdx_x_310731 = blockIdx_x(); pblockIdx_x_310731 = blockIdx_x_310731; l310729: ; blockIdx_x_310731 = pblockIdx_x_310731; _310734 = threadIdx_y(); p_310734 = _310734; l310732: ; _310734 = p_310734; _310737 = blockDim_y(); p_310737 = _310737; l310735: ; _310737 = p_310737; _310740 = blockIdx_y(); p_310740 = _310740; l310738: ; _310740 = p_310740; _310743 = blockDim_y(); p_310743 = _310743; l310741: ; _310743 = p_310743; int _310744; _310744 = _310737 * _310740; int _310747; _310747 = blockDim_x_310728 * blockIdx_x_310731; int _310748; _310748 = threadIdx_x_310725 + _310747; int _310753; _310753 = 2 * _240569_310719; int gid_y_310745; gid_y_310745 = _310734 + _310744; int _310754; _310754 = 64 + _310753; int _310746; _310746 = gid_y_310745 * _240569_310719; int _310755; _310755 = _310754 - 1; int _310749; _310749 = _310746 + _310748; int _310756; _310756 = _310755 / 64; short* idx_310764; idx_310764 = _240572_310722 + _310749; short* idx_310750; idx_310750 = _240570_310720 + _310749; int _310757; _310757 = 64 * _310756; short _310751; _310751 = *idx_310750; int stride_310758; stride_310758 = _310757 / 2; short _310765; _310765 = _310751; int _310759; _310759 = gid_y_310745 * stride_310758; int _310760; _310760 = _310759 + _310748; short* idx_310761; idx_310761 = _240571_310721 + _310760; short _310762; _310762 = *idx_310761; short _310766; _310766 = _310762; short _310767; _310767 = _310765 - _310766; short _310768; _310768 = _310765 + _310767; *idx_310764 = _310768; return ; } __global__ __launch_bounds__ (256 * 1 * 1) void lambda_236859(int* _236862_310647, int _236863_310648, int _236864_310649, float* _236865_310650) { int* sm_hist_310657; int* psm_hist_310657; int lower_310660; int plower_310660; int upper_310661; int pupper_310661; int step_310662; int pstep_310662; int _310704; int p_310704; int _310707; int p_310707; int atomicAdd_310715; int patomicAdd_310715; int threadIdx_x_310667; int pthreadIdx_x_310667; int blockDim_x_310670; int pblockDim_x_310670; int blockIdx_x_310673; int pblockIdx_x_310673; int atomicAdd_310699; int patomicAdd_310699; __shared__ int reserver_sm_hist_310657[256]; psm_hist_310657 = reserver_sm_hist_310657; l310655: ; sm_hist_310657 = psm_hist_310657; int _310679; _310679 = 4 * _236863_310648; int _310680; _310680 = 64 + _310679; int _310681; _310681 = _310680 - 1; int _310682; _310682 = _310681 / 64; int _310683; _310683 = 64 * _310682; int stride_310684; stride_310684 = _310683 / 4; plower_310660 = 0; pupper_310661 = _236864_310649; pstep_310662 = 1; goto l310658; l310658: ; lower_310660 = plower_310660; upper_310661 = pupper_310661; step_310662 = pstep_310662; bool _310663; _310663 = lower_310660 < upper_310661; if (_310663) goto l310664; else goto l310701; l310701: ; _310704 = threadIdx_x(); p_310704 = _310704; l310702: ; _310704 = p_310704; _310707 = threadIdx_x(); p_310707 = _310707; l310705: ; _310707 = p_310707; int* _310711; _310711 = _236862_310647 + _310704; int* _310708; _310708 = sm_hist_310657 + _310707; int _310709; _310709 = *_310708; int _310712; _310712 = _310709; atomicAdd_310715 = atomicAdd(_310711, _310712); patomicAdd_310715 = atomicAdd_310715; l310713: ; atomicAdd_310715 = patomicAdd_310715; return ; l310664: ; threadIdx_x_310667 = threadIdx_x(); pthreadIdx_x_310667 = threadIdx_x_310667; l310665: ; threadIdx_x_310667 = pthreadIdx_x_310667; blockDim_x_310670 = blockDim_x(); pblockDim_x_310670 = blockDim_x_310670; l310668: ; blockDim_x_310670 = pblockDim_x_310670; blockIdx_x_310673 = blockIdx_x(); pblockIdx_x_310673 = blockIdx_x_310673; l310671: ; blockIdx_x_310673 = pblockIdx_x_310673; int _310686; _310686 = blockDim_x_310670 * blockIdx_x_310673; int _310685; _310685 = lower_310660 * stride_310684; int _310687; _310687 = threadIdx_x_310667 + _310686; int _310688; _310688 = _310685 + _310687; float* idx_310689; idx_310689 = _236865_310650 + _310688; float _310690; _310690 = *idx_310689; float _310693; _310693 = _310690; float _310694; _310694 = 2.550000e+02f * _310693; int _310695; _310695 = (int)_310694; int* bin_310696; bin_310696 = sm_hist_310657 + _310695; atomicAdd_310699 = atomicAdd(bin_310696, 1); patomicAdd_310699 = atomicAdd_310699; l310697: ; atomicAdd_310699 = patomicAdd_310699; int _310700; _310700 = lower_310660 + step_310662; plower_310660 = _310700; pupper_310661 = upper_310661; pstep_310662 = step_310662; goto l310658; } __global__ __launch_bounds__ (32 * 4 * 1) void lambda_231611(short* _231614_304149, int _231615_304150, int _231616_304151, float* _231617_304152) { int threadIdx_x_304161; int pthreadIdx_x_304161; int blockDim_x_304167; int pblockDim_x_304167; int blockIdx_x_304173; int pblockIdx_x_304173; int _304179; int p_304179; int _304185; int p_304185; int _304191; int p_304191; int _304194; int p_304194; int converge_304199; int pconverge_304199; int converge_304203; int pconverge_304203; int converge_304208; int pconverge_304208; int converge_304211; int pconverge_304211; int converge_304216; int pconverge_304216; int converge_304219; int pconverge_304219; int converge_304224; int pconverge_304224; int converge_304227; int pconverge_304227; int converge_304232; int pconverge_304232; int converge_304235; int pconverge_304235; int converge_304238; int pconverge_304238; int converge_304242; int pconverge_304242; int converge_304245; int pconverge_304245; int converge_304248; int pconverge_304248; int converge_304251; int pconverge_304251; int converge_304254; int pconverge_304254; int converge_304257; int pconverge_304257; int converge_304260; int pconverge_304260; int converge_304263; int pconverge_304263; int converge_304266; int pconverge_304266; int converge_304269; int pconverge_304269; int converge_304273; int pconverge_304273; int converge_304276; int pconverge_304276; int converge_304279; int pconverge_304279; int converge_304282; int pconverge_304282; int converge_304285; int pconverge_304285; int converge_304288; int pconverge_304288; int converge_304291; int pconverge_304291; int converge_304294; int pconverge_304294; int converge_304297; int pconverge_304297; int converge_304300; int pconverge_304300; int converge_304304; int pconverge_304304; int converge_304307; int pconverge_304307; int converge_304310; int pconverge_304310; int converge_304313; int pconverge_304313; int converge_304316; int pconverge_304316; int converge_304319; int pconverge_304319; int converge_304322; int pconverge_304322; int converge_304325; int pconverge_304325; int converge_304328; int pconverge_304328; int converge_304331; int pconverge_304331; int converge_304335; int pconverge_304335; int converge_304338; int pconverge_304338; int converge_304341; int pconverge_304341; int converge_304344; int pconverge_304344; int converge_304347; int pconverge_304347; int converge_304350; int pconverge_304350; int converge_304353; int pconverge_304353; int converge_304356; int pconverge_304356; int converge_304359; int pconverge_304359; array_63718 arr_304367_slot; array_63718* arr_304367; arr_304367 = &arr_304367_slot; threadIdx_x_304161 = threadIdx_x(); pthreadIdx_x_304161 = threadIdx_x_304161; l304159: ; threadIdx_x_304161 = pthreadIdx_x_304161; blockDim_x_304167 = blockDim_x(); pblockDim_x_304167 = blockDim_x_304167; l304165: ; blockDim_x_304167 = pblockDim_x_304167; blockIdx_x_304173 = blockIdx_x(); pblockIdx_x_304173 = blockIdx_x_304173; l304171: ; blockIdx_x_304173 = pblockIdx_x_304173; _304179 = threadIdx_y(); p_304179 = _304179; l304177: ; _304179 = p_304179; _304185 = blockDim_y(); p_304185 = _304185; l304183: ; _304185 = p_304185; _304191 = blockIdx_y(); p_304191 = _304191; l304189: ; _304191 = p_304191; _304194 = blockDim_y(); p_304194 = _304194; l304192: ; _304194 = p_304194; int _307701; _307701 = 1 - _231615_304150; bool _304196; _304196 = _231615_304150 <= 0; int _307702; _307702 = _231615_304150 - _307701; if (_304196) goto l304197; else goto l307751; l307751: ; pconverge_304199 = 0; goto l304198; l304197: ; pconverge_304199 = _307702; goto l304198; l304198: ; converge_304199 = pconverge_304199; bool _304200; _304200 = _231616_304151 <= 0; int _307740; _307740 = 1 - _231616_304151; int _307741; _307741 = _231616_304151 - _307740; if (_304200) goto l304201; else goto l307750; l307750: ; pconverge_304203 = 0; goto l304202; l304201: ; pconverge_304203 = _307741; goto l304202; l304202: ; converge_304203 = pconverge_304203; int _307697; _307697 = 2 - _231615_304150; bool _304205; _304205 = _231615_304150 <= 1; int _307698; _307698 = _231615_304150 - _307697; if (_304205) goto l304206; else goto l307749; l307749: ; pconverge_304208 = 1; goto l304207; l304206: ; pconverge_304208 = _307698; goto l304207; l304207: ; converge_304208 = pconverge_304208; if (_304200) goto l304209; else goto l307748; l307748: ; pconverge_304211 = 0; goto l304210; l304209: ; pconverge_304211 = _307741; goto l304210; l304210: ; converge_304211 = pconverge_304211; bool _304213; _304213 = _231615_304150 <= 2; int _307693; _307693 = 3 - _231615_304150; int _307694; _307694 = _231615_304150 - _307693; if (_304213) goto l304214; else goto l307747; l307747: ; pconverge_304216 = 2; goto l304215; l304214: ; pconverge_304216 = _307694; goto l304215; l304215: ; converge_304216 = pconverge_304216; if (_304200) goto l304217; else goto l307746; l307746: ; pconverge_304219 = 0; goto l304218; l304217: ; pconverge_304219 = _307741; goto l304218; l304218: ; converge_304219 = pconverge_304219; bool _304221; _304221 = _231615_304150 <= 3; int _307689; _307689 = 4 - _231615_304150; int _307690; _307690 = _231615_304150 - _307689; if (_304221) goto l304222; else goto l307745; l307745: ; pconverge_304224 = 3; goto l304223; l304222: ; pconverge_304224 = _307690; goto l304223; l304223: ; converge_304224 = pconverge_304224; if (_304200) goto l304225; else goto l307744; l307744: ; pconverge_304227 = 0; goto l304226; l304225: ; pconverge_304227 = _307741; goto l304226; l304226: ; converge_304227 = pconverge_304227; int _307685; _307685 = 5 - _231615_304150; bool _304229; _304229 = _231615_304150 <= 4; int _307686; _307686 = _231615_304150 - _307685; if (_304229) goto l304230; else goto l307743; l307743: ; pconverge_304232 = 4; goto l304231; l304230: ; pconverge_304232 = _307686; goto l304231; l304231: ; converge_304232 = pconverge_304232; if (_304200) goto l304233; else goto l307742; l307742: ; pconverge_304235 = 0; goto l304234; l304233: ; pconverge_304235 = _307741; goto l304234; l304234: ; converge_304235 = pconverge_304235; if (_304196) goto l304236; else goto l307739; l307739: ; pconverge_304238 = 0; goto l304237; l304236: ; pconverge_304238 = _307702; goto l304237; l304237: ; converge_304238 = pconverge_304238; int _307728; _307728 = 2 - _231616_304151; bool _304239; _304239 = _231616_304151 <= 1; int _307729; _307729 = _231616_304151 - _307728; if (_304239) goto l304240; else goto l307738; l307738: ; pconverge_304242 = 1; goto l304241; l304240: ; pconverge_304242 = _307729; goto l304241; l304241: ; converge_304242 = pconverge_304242; if (_304205) goto l304243; else goto l307737; l307737: ; pconverge_304245 = 1; goto l304244; l304243: ; pconverge_304245 = _307698; goto l304244; l304244: ; converge_304245 = pconverge_304245; if (_304239) goto l304246; else goto l307736; l307736: ; pconverge_304248 = 1; goto l304247; l304246: ; pconverge_304248 = _307729; goto l304247; l304247: ; converge_304248 = pconverge_304248; if (_304213) goto l304249; else goto l307735; l307735: ; pconverge_304251 = 2; goto l304250; l304249: ; pconverge_304251 = _307694; goto l304250; l304250: ; converge_304251 = pconverge_304251; if (_304239) goto l304252; else goto l307734; l307734: ; pconverge_304254 = 1; goto l304253; l304252: ; pconverge_304254 = _307729; goto l304253; l304253: ; converge_304254 = pconverge_304254; if (_304221) goto l304255; else goto l307733; l307733: ; pconverge_304257 = 3; goto l304256; l304255: ; pconverge_304257 = _307690; goto l304256; l304256: ; converge_304257 = pconverge_304257; if (_304239) goto l304258; else goto l307732; l307732: ; pconverge_304260 = 1; goto l304259; l304258: ; pconverge_304260 = _307729; goto l304259; l304259: ; converge_304260 = pconverge_304260; if (_304229) goto l304261; else goto l307731; l307731: ; pconverge_304263 = 4; goto l304262; l304261: ; pconverge_304263 = _307686; goto l304262; l304262: ; converge_304263 = pconverge_304263; if (_304239) goto l304264; else goto l307730; l307730: ; pconverge_304266 = 1; goto l304265; l304264: ; pconverge_304266 = _307729; goto l304265; l304265: ; converge_304266 = pconverge_304266; if (_304196) goto l304267; else goto l307727; l307727: ; pconverge_304269 = 0; goto l304268; l304267: ; pconverge_304269 = _307702; goto l304268; l304268: ; converge_304269 = pconverge_304269; bool _304270; _304270 = _231616_304151 <= 2; int _307716; _307716 = 3 - _231616_304151; int _307717; _307717 = _231616_304151 - _307716; if (_304270) goto l304271; else goto l307726; l307726: ; pconverge_304273 = 2; goto l304272; l304271: ; pconverge_304273 = _307717; goto l304272; l304272: ; converge_304273 = pconverge_304273; if (_304205) goto l304274; else goto l307725; l307725: ; pconverge_304276 = 1; goto l304275; l304274: ; pconverge_304276 = _307698; goto l304275; l304275: ; converge_304276 = pconverge_304276; if (_304270) goto l304277; else goto l307724; l307724: ; pconverge_304279 = 2; goto l304278; l304277: ; pconverge_304279 = _307717; goto l304278; l304278: ; converge_304279 = pconverge_304279; if (_304213) goto l304280; else goto l307723; l307723: ; pconverge_304282 = 2; goto l304281; l304280: ; pconverge_304282 = _307694; goto l304281; l304281: ; converge_304282 = pconverge_304282; if (_304270) goto l304283; else goto l307722; l307722: ; pconverge_304285 = 2; goto l304284; l304283: ; pconverge_304285 = _307717; goto l304284; l304284: ; converge_304285 = pconverge_304285; if (_304221) goto l304286; else goto l307721; l307721: ; pconverge_304288 = 3; goto l304287; l304286: ; pconverge_304288 = _307690; goto l304287; l304287: ; converge_304288 = pconverge_304288; if (_304270) goto l304289; else goto l307720; l307720: ; pconverge_304291 = 2; goto l304290; l304289: ; pconverge_304291 = _307717; goto l304290; l304290: ; converge_304291 = pconverge_304291; if (_304229) goto l304292; else goto l307719; l307719: ; pconverge_304294 = 4; goto l304293; l304292: ; pconverge_304294 = _307686; goto l304293; l304293: ; converge_304294 = pconverge_304294; if (_304270) goto l304295; else goto l307718; l307718: ; pconverge_304297 = 2; goto l304296; l304295: ; pconverge_304297 = _307717; goto l304296; l304296: ; converge_304297 = pconverge_304297; if (_304196) goto l304298; else goto l307715; l307715: ; pconverge_304300 = 0; goto l304299; l304298: ; pconverge_304300 = _307702; goto l304299; l304299: ; converge_304300 = pconverge_304300; bool _304301; _304301 = _231616_304151 <= 3; int _307704; _307704 = 4 - _231616_304151; int _307705; _307705 = _231616_304151 - _307704; if (_304301) goto l304302; else goto l307714; l307714: ; pconverge_304304 = 3; goto l304303; l304302: ; pconverge_304304 = _307705; goto l304303; l304303: ; converge_304304 = pconverge_304304; if (_304205) goto l304305; else goto l307713; l307713: ; pconverge_304307 = 1; goto l304306; l304305: ; pconverge_304307 = _307698; goto l304306; l304306: ; converge_304307 = pconverge_304307; if (_304301) goto l304308; else goto l307712; l307712: ; pconverge_304310 = 3; goto l304309; l304308: ; pconverge_304310 = _307705; goto l304309; l304309: ; converge_304310 = pconverge_304310; if (_304213) goto l304311; else goto l307711; l307711: ; pconverge_304313 = 2; goto l304312; l304311: ; pconverge_304313 = _307694; goto l304312; l304312: ; converge_304313 = pconverge_304313; if (_304301) goto l304314; else goto l307710; l307710: ; pconverge_304316 = 3; goto l304315; l304314: ; pconverge_304316 = _307705; goto l304315; l304315: ; converge_304316 = pconverge_304316; if (_304221) goto l304317; else goto l307709; l307709: ; pconverge_304319 = 3; goto l304318; l304317: ; pconverge_304319 = _307690; goto l304318; l304318: ; converge_304319 = pconverge_304319; if (_304301) goto l304320; else goto l307708; l307708: ; pconverge_304322 = 3; goto l304321; l304320: ; pconverge_304322 = _307705; goto l304321; l304321: ; converge_304322 = pconverge_304322; if (_304229) goto l304323; else goto l307707; l307707: ; pconverge_304325 = 4; goto l304324; l304323: ; pconverge_304325 = _307686; goto l304324; l304324: ; converge_304325 = pconverge_304325; if (_304301) goto l304326; else goto l307706; l307706: ; pconverge_304328 = 3; goto l304327; l304326: ; pconverge_304328 = _307705; goto l304327; l304327: ; converge_304328 = pconverge_304328; if (_304196) goto l304329; else goto l307703; l307703: ; pconverge_304331 = 0; goto l304330; l304329: ; pconverge_304331 = _307702; goto l304330; l304330: ; converge_304331 = pconverge_304331; int _307682; _307682 = 5 - _231616_304151; bool _304332; _304332 = _231616_304151 <= 4; int _307683; _307683 = _231616_304151 - _307682; if (_304332) goto l304333; else goto l307700; l307700: ; pconverge_304335 = 4; goto l304334; l304333: ; pconverge_304335 = _307683; goto l304334; l304334: ; converge_304335 = pconverge_304335; if (_304205) goto l304336; else goto l307699; l307699: ; pconverge_304338 = 1; goto l304337; l304336: ; pconverge_304338 = _307698; goto l304337; l304337: ; converge_304338 = pconverge_304338; if (_304332) goto l304339; else goto l307696; l307696: ; pconverge_304341 = 4; goto l304340; l304339: ; pconverge_304341 = _307683; goto l304340; l304340: ; converge_304341 = pconverge_304341; if (_304213) goto l304342; else goto l307695; l307695: ; pconverge_304344 = 2; goto l304343; l304342: ; pconverge_304344 = _307694; goto l304343; l304343: ; converge_304344 = pconverge_304344; if (_304332) goto l304345; else goto l307692; l307692: ; pconverge_304347 = 4; goto l304346; l304345: ; pconverge_304347 = _307683; goto l304346; l304346: ; converge_304347 = pconverge_304347; if (_304221) goto l304348; else goto l307691; l307691: ; pconverge_304350 = 3; goto l304349; l304348: ; pconverge_304350 = _307690; goto l304349; l304349: ; converge_304350 = pconverge_304350; if (_304332) goto l304351; else goto l307688; l307688: ; pconverge_304353 = 4; goto l304352; l304351: ; pconverge_304353 = _307683; goto l304352; l304352: ; converge_304353 = pconverge_304353; if (_304229) goto l304354; else goto l307687; l307687: ; pconverge_304356 = 4; goto l304355; l304354: ; pconverge_304356 = _307686; goto l304355; l304355: ; converge_304356 = pconverge_304356; if (_304332) goto l304357; else goto l307684; l307684: ; pconverge_304359 = 4; goto l304358; l304357: ; pconverge_304359 = _307683; goto l304358; l304358: ; converge_304359 = pconverge_304359; short* _304580; _304580 = &arr_304367->e[24]; short* _304376; _304376 = &arr_304367->e[1]; int _304360; _304360 = converge_304203 * _231615_304150; short* _304368; _304368 = &arr_304367->e[0]; int _304511; _304511 = converge_304316 * _231615_304150; int _304520; _304520 = converge_304322 * _231615_304150; short* _304544; _304544 = &arr_304367->e[20]; int _304448; _304448 = converge_304273 * _231615_304150; int _304457; _304457 = converge_304279 * _231615_304150; int _304529; _304529 = converge_304328 * _231615_304150; short* _304499; _304499 = &arr_304367->e[15]; int _304574; _304574 = converge_304359 * _231615_304150; int _304430; _304430 = converge_304260 * _231615_304150; short* _304463; _304463 = &arr_304367->e[11]; int _304512; _304512 = _304511 + converge_304313; int _304361; _304361 = _304360 + converge_304199; short* _304562; _304562 = &arr_304367->e[22]; int _304458; _304458 = _304457 + converge_304276; short* _304384; _304384 = &arr_304367->e[2]; short* _304445; _304445 = &arr_304367->e[9]; int _304412; _304412 = converge_304248 * _231615_304150; short* _304427; _304427 = &arr_304367->e[7]; short* _304481; _304481 = &arr_304367->e[13]; int _304387; _304387 = converge_304227 * _231615_304150; short* _304418; _304418 = &arr_304367->e[6]; int _304493; _304493 = converge_304304 * _231615_304150; short* _304400; _304400 = &arr_304367->e[4]; int _304439; _304439 = converge_304266 * _231615_304150; int _304475; _304475 = converge_304291 * _231615_304150; short* _304436; _304436 = &arr_304367->e[8]; int _304395; _304395 = converge_304235 * _231615_304150; int _304388; _304388 = _304387 + converge_304224; int _304476; _304476 = _304475 + converge_304288; int _304538; _304538 = converge_304335 * _231615_304150; int _304484; _304484 = converge_304297 * _231615_304150; int _304556; _304556 = converge_304347 * _231615_304150; short* _304392; _304392 = &arr_304367->e[3]; int _304403; _304403 = converge_304242 * _231615_304150; int _304413; _304413 = _304412 + converge_304245; int _304557; _304557 = _304556 + converge_304344; short* _304472; _304472 = &arr_304367->e[12]; int _304521; _304521 = _304520 + converge_304319; short* _304553; _304553 = &arr_304367->e[21]; short* _304490; _304490 = &arr_304367->e[14]; int _304431; _304431 = _304430 + converge_304257; int _304371; _304371 = converge_304211 * _231615_304150; short* idx_304459; idx_304459 = _231614_304149 + _304458; int _304547; _304547 = converge_304341 * _231615_304150; short* _304517; _304517 = &arr_304367->e[17]; short* idx_304522; idx_304522 = _231614_304149 + _304521; short* _304526; _304526 = &arr_304367->e[18]; int _304565; _304565 = converge_304353 * _231615_304150; short* _304571; _304571 = &arr_304367->e[23]; short* _304535; _304535 = &arr_304367->e[19]; short* idx_304513; idx_304513 = _231614_304149 + _304512; short* _304409; _304409 = &arr_304367->e[5]; int _304421; _304421 = converge_304254 * _231615_304150; int _304502; _304502 = converge_304310 * _231615_304150; short* _304508; _304508 = &arr_304367->e[16]; int _304379; _304379 = converge_304219 * _231615_304150; short* idx_304558; idx_304558 = _231614_304149 + _304557; int _304575; _304575 = _304574 + converge_304356; short* _304454; _304454 = &arr_304367->e[10]; int _304466; _304466 = converge_304285 * _231615_304150; int _304449; _304449 = _304448 + converge_304269; int _304530; _304530 = _304529 + converge_304325; short* idx_304362; idx_304362 = _231614_304149 + _304361; int _304494; _304494 = _304493 + converge_304300; int _304440; _304440 = _304439 + converge_304263; int _304396; _304396 = _304395 + converge_304232; short* idx_304389; idx_304389 = _231614_304149 + _304388; short* idx_304477; idx_304477 = _231614_304149 + _304476; int _304539; _304539 = _304538 + converge_304331; int _304485; _304485 = _304484 + converge_304294; int _304404; _304404 = _304403 + converge_304238; short* idx_304414; idx_304414 = _231614_304149 + _304413; short* idx_304432; idx_304432 = _231614_304149 + _304431; int _304372; _304372 = _304371 + converge_304208; int _304548; _304548 = _304547 + converge_304338; int _304566; _304566 = _304565 + converge_304350; int _304422; _304422 = _304421 + converge_304251; int _304503; _304503 = _304502 + converge_304307; int _304380; _304380 = _304379 + converge_304216; short* idx_304576; idx_304576 = _231614_304149 + _304575; int _304467; _304467 = _304466 + converge_304282; short* idx_304450; idx_304450 = _231614_304149 + _304449; short* idx_304531; idx_304531 = _231614_304149 + _304530; short _304363; _304363 = *idx_304362; short* idx_304495; idx_304495 = _231614_304149 + _304494; short* idx_304441; idx_304441 = _231614_304149 + _304440; short* idx_304397; idx_304397 = _231614_304149 + _304396; short* idx_304540; idx_304540 = _231614_304149 + _304539; short* idx_304486; idx_304486 = _231614_304149 + _304485; short* idx_304405; idx_304405 = _231614_304149 + _304404; short* idx_304373; idx_304373 = _231614_304149 + _304372; short* idx_304549; idx_304549 = _231614_304149 + _304548; short* idx_304567; idx_304567 = _231614_304149 + _304566; short* idx_304423; idx_304423 = _231614_304149 + _304422; short* idx_304504; idx_304504 = _231614_304149 + _304503; short* idx_304381; idx_304381 = _231614_304149 + _304380; short* idx_304468; idx_304468 = _231614_304149 + _304467; short _304369; _304369 = _304363; *_304368 = _304369; short _304374; _304374 = *idx_304373; short _304377; _304377 = _304374; *_304376 = _304377; short _304382; _304382 = *idx_304381; short _304385; _304385 = _304382; *_304384 = _304385; short _304390; _304390 = *idx_304389; short _304393; _304393 = _304390; *_304392 = _304393; short _304398; _304398 = *idx_304397; short _304401; _304401 = _304398; *_304400 = _304401; short _304406; _304406 = *idx_304405; short _304410; _304410 = _304406; *_304409 = _304410; short _304415; _304415 = *idx_304414; short _304419; _304419 = _304415; *_304418 = _304419; short _304424; _304424 = *idx_304423; short _304428; _304428 = _304424; *_304427 = _304428; short _304433; _304433 = *idx_304432; short _304437; _304437 = _304433; *_304436 = _304437; short _304442; _304442 = *idx_304441; short _304446; _304446 = _304442; *_304445 = _304446; short _304451; _304451 = *idx_304450; short _304455; _304455 = _304451; *_304454 = _304455; short _304460; _304460 = *idx_304459; short _304464; _304464 = _304460; *_304463 = _304464; short _304469; _304469 = *idx_304468; short _304473; _304473 = _304469; *_304472 = _304473; short _304478; _304478 = *idx_304477; short _304482; _304482 = _304478; *_304481 = _304482; short _304487; _304487 = *idx_304486; short _304491; _304491 = _304487; *_304490 = _304491; short _304496; _304496 = *idx_304495; short _304500; _304500 = _304496; *_304499 = _304500; short _304505; _304505 = *idx_304504; short _304509; _304509 = _304505; *_304508 = _304509; short _304514; _304514 = *idx_304513; short _304518; _304518 = _304514; *_304517 = _304518; short _304523; _304523 = *idx_304522; short _304527; _304527 = _304523; *_304526 = _304527; short _304532; _304532 = *idx_304531; short _304536; _304536 = _304532; *_304535 = _304536; short _304541; _304541 = *idx_304540; short _304545; _304545 = _304541; *_304544 = _304545; short _304550; _304550 = *idx_304549; short _304554; _304554 = _304550; *_304553 = _304554; short _304559; _304559 = *idx_304558; short _304563; _304563 = _304559; *_304562 = _304563; short _304568; _304568 = *idx_304567; short _304572; _304572 = _304568; *_304571 = _304572; short _304577; _304577 = *idx_304576; short _304581; _304581 = _304577; *_304580 = _304581; short _304583; _304583 = *_304376; short _304587; _304587 = _304583; short _304585; _304585 = *_304384; short _304586; _304586 = _304585; bool _304588; _304588 = _304586 < _304587; bool _304590; _304590 = _304588 == true; if (_304590) goto l304591; else goto l307681; l307681: ; goto l304592; l304591: ; short _307673; _307673 = *_304376; short _307679; _307679 = _307673; short _307675; _307675 = *_304384; short _307677; _307677 = _307675; *_304376 = _307677; *_304384 = _307679; goto l304592; l304592: ; short _304594; _304594 = *_304368; short _304598; _304598 = _304594; short _304596; _304596 = *_304384; short _304597; _304597 = _304596; bool _304599; _304599 = _304597 < _304598; bool _304600; _304600 = _304599 == true; if (_304600) goto l304601; else goto l307671; l307671: ; goto l304602; l304601: ; short _307663; _307663 = *_304368; short _307669; _307669 = _307663; short _307665; _307665 = *_304384; short _307667; _307667 = _307665; *_304368 = _307667; *_304384 = _307669; goto l304602; l304602: ; short _304604; _304604 = *_304368; short _304608; _304608 = _304604; short _304606; _304606 = *_304376; short _304607; _304607 = _304606; bool _304609; _304609 = _304607 < _304608; bool _304610; _304610 = _304609 == true; if (_304610) goto l304611; else goto l307661; l307661: ; goto l304612; l304611: ; short _307653; _307653 = *_304368; short _307659; _307659 = _307653; short _307655; _307655 = *_304376; short _307657; _307657 = _307655; *_304368 = _307657; *_304376 = _307659; goto l304612; l304612: ; short _304614; _304614 = *_304400; short _304618; _304618 = _304614; short _304616; _304616 = *_304409; short _304617; _304617 = _304616; bool _304619; _304619 = _304617 < _304618; bool _304621; _304621 = _304619 == true; if (_304621) goto l304622; else goto l307651; l307651: ; goto l304623; l304622: ; short _307643; _307643 = *_304400; short _307649; _307649 = _307643; short _307645; _307645 = *_304409; short _307647; _307647 = _307645; *_304400 = _307647; *_304409 = _307649; goto l304623; l304623: ; short _304625; _304625 = *_304392; short _304627; _304627 = *_304409; short _304629; _304629 = _304625; short _304628; _304628 = _304627; bool _304630; _304630 = _304628 < _304629; bool _304631; _304631 = _304630 == true; if (_304631) goto l304632; else goto l307641; l307641: ; goto l304633; l304632: ; short _307633; _307633 = *_304392; short _307639; _307639 = _307633; short _307635; _307635 = *_304409; short _307637; _307637 = _307635; *_304392 = _307637; *_304409 = _307639; goto l304633; l304633: ; short _304635; _304635 = *_304392; short _304639; _304639 = _304635; short _304637; _304637 = *_304400; short _304638; _304638 = _304637; bool _304640; _304640 = _304638 < _304639; bool _304641; _304641 = _304640 == true; if (_304641) goto l304642; else goto l307631; l307631: ; goto l304643; l304642: ; short _307623; _307623 = *_304392; short _307629; _307629 = _307623; short _307625; _307625 = *_304400; short _307627; _307627 = _307625; *_304392 = _307627; *_304400 = _307629; goto l304643; l304643: ; short _304645; _304645 = *_304368; short _304649; _304649 = _304645; short _304647; _304647 = *_304400; short _304648; _304648 = _304647; bool _304650; _304650 = _304648 < _304649; bool _304651; _304651 = _304650 == true; if (_304651) goto l304652; else goto l307621; l307621: ; goto l304653; l304652: ; short _307613; _307613 = *_304368; short _307619; _307619 = _307613; short _307615; _307615 = *_304400; short _307617; _307617 = _307615; *_304368 = _307617; *_304400 = _307619; goto l304653; l304653: ; short _304655; _304655 = *_304376; short _304659; _304659 = _304655; short _304657; _304657 = *_304409; short _304658; _304658 = _304657; bool _304660; _304660 = _304658 < _304659; bool _304661; _304661 = _304660 == true; if (_304661) goto l304662; else goto l307611; l307611: ; goto l304663; l304662: ; short _307603; _307603 = *_304376; short _307609; _307609 = _307603; short _307605; _307605 = *_304409; short _307607; _307607 = _307605; *_304376 = _307607; *_304409 = _307609; goto l304663; l304663: ; short _304665; _304665 = *_304368; short _304669; _304669 = _304665; short _304667; _304667 = *_304384; short _304668; _304668 = _304667; bool _304670; _304670 = _304668 < _304669; bool _304671; _304671 = _304670 == true; if (_304671) goto l304672; else goto l307601; l307601: ; goto l304673; l304672: ; short _307593; _307593 = *_304368; short _307595; _307595 = *_304384; short _307599; _307599 = _307593; short _307597; _307597 = _307595; *_304368 = _307597; *_304384 = _307599; goto l304673; l304673: ; short _304675; _304675 = *_304376; short _304679; _304679 = _304675; short _304677; _304677 = *_304392; short _304678; _304678 = _304677; bool _304680; _304680 = _304678 < _304679; bool _304681; _304681 = _304680 == true; if (_304681) goto l304682; else goto l307591; l307591: ; goto l304683; l304682: ; short _307583; _307583 = *_304376; short _307589; _307589 = _307583; short _307585; _307585 = *_304392; short _307587; _307587 = _307585; *_304376 = _307587; *_304392 = _307589; goto l304683; l304683: ; short _304685; _304685 = *_304368; short _304689; _304689 = _304685; short _304687; _304687 = *_304376; short _304688; _304688 = _304687; bool _304690; _304690 = _304688 < _304689; bool _304691; _304691 = _304690 == true; if (_304691) goto l304692; else goto l307581; l307581: ; goto l304693; l304692: ; short _307573; _307573 = *_304368; short _307579; _307579 = _307573; short _307575; _307575 = *_304376; short _307577; _307577 = _307575; *_304368 = _307577; *_304376 = _307579; goto l304693; l304693: ; short _304695; _304695 = *_304384; short _304699; _304699 = _304695; short _304697; _304697 = *_304392; short _304698; _304698 = _304697; bool _304700; _304700 = _304698 < _304699; bool _304701; _304701 = _304700 == true; if (_304701) goto l304702; else goto l307571; l307571: ; goto l304703; l304702: ; short _307563; _307563 = *_304384; short _307569; _307569 = _307563; short _307565; _307565 = *_304392; short _307567; _307567 = _307565; *_304384 = _307567; *_304392 = _307569; goto l304703; l304703: ; short _304705; _304705 = *_304400; short _304709; _304709 = _304705; short _304707; _304707 = *_304409; short _304708; _304708 = _304707; bool _304710; _304710 = _304708 < _304709; bool _304711; _304711 = _304710 == true; if (_304711) goto l304712; else goto l307561; l307561: ; goto l304713; l304712: ; short _307553; _307553 = *_304400; short _307559; _307559 = _307553; short _307555; _307555 = *_304409; short _307557; _307557 = _307555; *_304400 = _307557; *_304409 = _307559; goto l304713; l304713: ; short _304715; _304715 = *_304427; short _304719; _304719 = _304715; short _304717; _304717 = *_304436; short _304718; _304718 = _304717; bool _304720; _304720 = _304718 < _304719; bool _304721; _304721 = _304720 == true; if (_304721) goto l304722; else goto l307551; l307551: ; goto l304723; l304722: ; short _307543; _307543 = *_304427; short _307549; _307549 = _307543; short _307545; _307545 = *_304436; short _307547; _307547 = _307545; *_304427 = _307547; *_304436 = _307549; goto l304723; l304723: ; short _304725; _304725 = *_304418; short _304729; _304729 = _304725; short _304727; _304727 = *_304436; short _304728; _304728 = _304727; bool _304730; _304730 = _304728 < _304729; bool _304731; _304731 = _304730 == true; if (_304731) goto l304732; else goto l307541; l307541: ; goto l304733; l304732: ; short _307533; _307533 = *_304418; short _307539; _307539 = _307533; short _307535; _307535 = *_304436; short _307537; _307537 = _307535; *_304418 = _307537; *_304436 = _307539; goto l304733; l304733: ; short _304735; _304735 = *_304418; short _304739; _304739 = _304735; short _304737; _304737 = *_304427; short _304738; _304738 = _304737; bool _304740; _304740 = _304738 < _304739; bool _304741; _304741 = _304740 == true; if (_304741) goto l304742; else goto l307531; l307531: ; goto l304743; l304742: ; short _307523; _307523 = *_304418; short _307529; _307529 = _307523; short _307525; _307525 = *_304427; short _307527; _307527 = _307525; *_304418 = _307527; *_304427 = _307529; goto l304743; l304743: ; short _304745; _304745 = *_304454; short _304749; _304749 = _304745; short _304747; _304747 = *_304463; short _304748; _304748 = _304747; bool _304750; _304750 = _304748 < _304749; bool _304751; _304751 = _304750 == true; if (_304751) goto l304752; else goto l307521; l307521: ; goto l304753; l304752: ; short _307513; _307513 = *_304454; short _307519; _307519 = _307513; short _307515; _307515 = *_304463; short _307517; _307517 = _307515; *_304454 = _307517; *_304463 = _307519; goto l304753; l304753: ; short _304755; _304755 = *_304445; short _304759; _304759 = _304755; short _304757; _304757 = *_304463; short _304758; _304758 = _304757; bool _304760; _304760 = _304758 < _304759; bool _304761; _304761 = _304760 == true; if (_304761) goto l304762; else goto l307511; l307511: ; goto l304763; l304762: ; short _307503; _307503 = *_304445; short _307509; _307509 = _307503; short _307505; _307505 = *_304463; short _307507; _307507 = _307505; *_304445 = _307507; *_304463 = _307509; goto l304763; l304763: ; short _304765; _304765 = *_304445; short _304769; _304769 = _304765; short _304767; _304767 = *_304454; short _304768; _304768 = _304767; bool _304770; _304770 = _304768 < _304769; bool _304771; _304771 = _304770 == true; if (_304771) goto l304772; else goto l307501; l307501: ; goto l304773; l304772: ; short _307493; _307493 = *_304445; short _307499; _307499 = _307493; short _307495; _307495 = *_304454; short _307497; _307497 = _307495; *_304445 = _307497; *_304454 = _307499; goto l304773; l304773: ; short _304775; _304775 = *_304418; short _304779; _304779 = _304775; short _304777; _304777 = *_304454; short _304778; _304778 = _304777; bool _304780; _304780 = _304778 < _304779; bool _304781; _304781 = _304780 == true; if (_304781) goto l304782; else goto l307491; l307491: ; goto l304783; l304782: ; short _307483; _307483 = *_304418; short _307489; _307489 = _307483; short _307485; _307485 = *_304454; short _307487; _307487 = _307485; *_304418 = _307487; *_304454 = _307489; goto l304783; l304783: ; short _304785; _304785 = *_304427; short _304789; _304789 = _304785; short _304787; _304787 = *_304463; short _304788; _304788 = _304787; bool _304790; _304790 = _304788 < _304789; bool _304791; _304791 = _304790 == true; if (_304791) goto l304792; else goto l307481; l307481: ; goto l304793; l304792: ; short _307473; _307473 = *_304427; short _307479; _307479 = _307473; short _307475; _307475 = *_304463; short _307477; _307477 = _307475; *_304427 = _307477; *_304463 = _307479; goto l304793; l304793: ; short _304795; _304795 = *_304418; short _304799; _304799 = _304795; short _304797; _304797 = *_304436; short _304798; _304798 = _304797; bool _304800; _304800 = _304798 < _304799; bool _304801; _304801 = _304800 == true; if (_304801) goto l304802; else goto l307471; l307471: ; goto l304803; l304802: ; short _307463; _307463 = *_304418; short _307469; _307469 = _307463; short _307465; _307465 = *_304436; short _307467; _307467 = _307465; *_304418 = _307467; *_304436 = _307469; goto l304803; l304803: ; short _304805; _304805 = *_304427; short _304807; _304807 = *_304445; short _304809; _304809 = _304805; short _304808; _304808 = _304807; bool _304810; _304810 = _304808 < _304809; bool _304811; _304811 = _304810 == true; if (_304811) goto l304812; else goto l307461; l307461: ; goto l304813; l304812: ; short _307453; _307453 = *_304427; short _307459; _307459 = _307453; short _307455; _307455 = *_304445; short _307457; _307457 = _307455; *_304427 = _307457; *_304445 = _307459; goto l304813; l304813: ; short _304815; _304815 = *_304418; short _304819; _304819 = _304815; short _304817; _304817 = *_304427; short _304818; _304818 = _304817; bool _304820; _304820 = _304818 < _304819; bool _304821; _304821 = _304820 == true; if (_304821) goto l304822; else goto l307451; l307451: ; goto l304823; l304822: ; short _307443; _307443 = *_304418; short _307449; _307449 = _307443; short _307445; _307445 = *_304427; short _307447; _307447 = _307445; *_304418 = _307447; *_304427 = _307449; goto l304823; l304823: ; short _304825; _304825 = *_304436; short _304829; _304829 = _304825; short _304827; _304827 = *_304445; short _304828; _304828 = _304827; bool _304830; _304830 = _304828 < _304829; bool _304831; _304831 = _304830 == true; if (_304831) goto l304832; else goto l307441; l307441: ; goto l304833; l304832: ; short _307433; _307433 = *_304436; short _307439; _307439 = _307433; short _307435; _307435 = *_304445; short _307437; _307437 = _307435; *_304436 = _307437; *_304445 = _307439; goto l304833; l304833: ; short _304835; _304835 = *_304454; short _304839; _304839 = _304835; short _304837; _304837 = *_304463; short _304838; _304838 = _304837; bool _304840; _304840 = _304838 < _304839; bool _304841; _304841 = _304840 == true; if (_304841) goto l304842; else goto l307431; l307431: ; goto l304843; l304842: ; short _307423; _307423 = *_304454; short _307429; _307429 = _307423; short _307425; _307425 = *_304463; short _307427; _307427 = _307425; *_304454 = _307427; *_304463 = _307429; goto l304843; l304843: ; short _304845; _304845 = *_304368; short _304849; _304849 = _304845; short _304847; _304847 = *_304436; short _304848; _304848 = _304847; bool _304850; _304850 = _304848 < _304849; bool _304851; _304851 = _304850 == true; if (_304851) goto l304852; else goto l307421; l307421: ; goto l304853; l304852: ; short _307413; _307413 = *_304368; short _307419; _307419 = _307413; short _307415; _307415 = *_304436; short _307417; _307417 = _307415; *_304368 = _307417; *_304436 = _307419; goto l304853; l304853: ; short _304855; _304855 = *_304376; short _304859; _304859 = _304855; short _304857; _304857 = *_304445; short _304858; _304858 = _304857; bool _304860; _304860 = _304858 < _304859; bool _304861; _304861 = _304860 == true; if (_304861) goto l304862; else goto l307411; l307411: ; goto l304863; l304862: ; short _307403; _307403 = *_304376; short _307409; _307409 = _307403; short _307405; _307405 = *_304445; short _307407; _307407 = _307405; *_304376 = _307407; *_304445 = _307409; goto l304863; l304863: ; short _304865; _304865 = *_304384; short _304869; _304869 = _304865; short _304867; _304867 = *_304454; short _304868; _304868 = _304867; bool _304870; _304870 = _304868 < _304869; bool _304871; _304871 = _304870 == true; if (_304871) goto l304872; else goto l307401; l307401: ; goto l304873; l304872: ; short _307393; _307393 = *_304384; short _307399; _307399 = _307393; short _307395; _307395 = *_304454; short _307397; _307397 = _307395; *_304384 = _307397; *_304454 = _307399; goto l304873; l304873: ; short _304875; _304875 = *_304392; short _304879; _304879 = _304875; short _304877; _304877 = *_304463; short _304878; _304878 = _304877; bool _304880; _304880 = _304878 < _304879; bool _304881; _304881 = _304880 == true; if (_304881) goto l304882; else goto l307391; l307391: ; goto l304883; l304882: ; short _307383; _307383 = *_304392; short _307389; _307389 = _307383; short _307385; _307385 = *_304463; short _307387; _307387 = _307385; *_304392 = _307387; *_304463 = _307389; goto l304883; l304883: ; short _304885; _304885 = *_304368; short _304889; _304889 = _304885; short _304887; _304887 = *_304400; short _304888; _304888 = _304887; bool _304890; _304890 = _304888 < _304889; bool _304891; _304891 = _304890 == true; if (_304891) goto l304892; else goto l307381; l307381: ; goto l304893; l304892: ; short _307373; _307373 = *_304368; short _307379; _307379 = _307373; short _307375; _307375 = *_304400; short _307377; _307377 = _307375; *_304368 = _307377; *_304400 = _307379; goto l304893; l304893: ; short _304895; _304895 = *_304376; short _304899; _304899 = _304895; short _304897; _304897 = *_304409; short _304898; _304898 = _304897; bool _304900; _304900 = _304898 < _304899; bool _304901; _304901 = _304900 == true; if (_304901) goto l304902; else goto l307371; l307371: ; goto l304903; l304902: ; short _307363; _307363 = *_304376; short _307369; _307369 = _307363; short _307365; _307365 = *_304409; short _307367; _307367 = _307365; *_304376 = _307367; *_304409 = _307369; goto l304903; l304903: ; short _304905; _304905 = *_304384; short _304909; _304909 = _304905; short _304907; _304907 = *_304418; short _304908; _304908 = _304907; bool _304910; _304910 = _304908 < _304909; bool _304911; _304911 = _304910 == true; if (_304911) goto l304912; else goto l307361; l307361: ; goto l304913; l304912: ; short _307353; _307353 = *_304384; short _307359; _307359 = _307353; short _307355; _307355 = *_304418; short _307357; _307357 = _307355; *_304384 = _307357; *_304418 = _307359; goto l304913; l304913: ; short _304915; _304915 = *_304392; short _304919; _304919 = _304915; short _304917; _304917 = *_304427; short _304918; _304918 = _304917; bool _304920; _304920 = _304918 < _304919; bool _304921; _304921 = _304920 == true; if (_304921) goto l304922; else goto l307351; l307351: ; goto l304923; l304922: ; short _307343; _307343 = *_304392; short _307349; _307349 = _307343; short _307345; _307345 = *_304427; short _307347; _307347 = _307345; *_304392 = _307347; *_304427 = _307349; goto l304923; l304923: ; short _304925; _304925 = *_304368; short _304929; _304929 = _304925; short _304927; _304927 = *_304384; short _304928; _304928 = _304927; bool _304930; _304930 = _304928 < _304929; bool _304931; _304931 = _304930 == true; if (_304931) goto l304932; else goto l307341; l307341: ; goto l304933; l304932: ; short _307333; _307333 = *_304368; short _307339; _307339 = _307333; short _307335; _307335 = *_304384; short _307337; _307337 = _307335; *_304368 = _307337; *_304384 = _307339; goto l304933; l304933: ; short _304935; _304935 = *_304376; short _304937; _304937 = *_304392; short _304938; _304938 = _304937; short _304939; _304939 = _304935; bool _304940; _304940 = _304938 < _304939; bool _304941; _304941 = _304940 == true; if (_304941) goto l304942; else goto l307331; l307331: ; goto l304943; l304942: ; short _307323; _307323 = *_304376; short _307329; _307329 = _307323; short _307325; _307325 = *_304392; short _307327; _307327 = _307325; *_304376 = _307327; *_304392 = _307329; goto l304943; l304943: ; short _304945; _304945 = *_304368; short _304949; _304949 = _304945; short _304947; _304947 = *_304376; short _304948; _304948 = _304947; bool _304950; _304950 = _304948 < _304949; bool _304951; _304951 = _304950 == true; if (_304951) goto l304952; else goto l307321; l307321: ; goto l304953; l304952: ; short _307313; _307313 = *_304368; short _307319; _307319 = _307313; short _307315; _307315 = *_304376; short _307317; _307317 = _307315; *_304368 = _307317; *_304376 = _307319; goto l304953; l304953: ; short _304955; _304955 = *_304384; short _304959; _304959 = _304955; short _304957; _304957 = *_304392; short _304958; _304958 = _304957; bool _304960; _304960 = _304958 < _304959; bool _304961; _304961 = _304960 == true; if (_304961) goto l304962; else goto l307311; l307311: ; goto l304963; l304962: ; short _307303; _307303 = *_304384; short _307309; _307309 = _307303; short _307305; _307305 = *_304392; short _307307; _307307 = _307305; *_304384 = _307307; *_304392 = _307309; goto l304963; l304963: ; short _304965; _304965 = *_304400; short _304969; _304969 = _304965; short _304967; _304967 = *_304418; short _304968; _304968 = _304967; bool _304970; _304970 = _304968 < _304969; bool _304971; _304971 = _304970 == true; if (_304971) goto l304972; else goto l307301; l307301: ; goto l304973; l304972: ; short _307293; _307293 = *_304400; short _307299; _307299 = _307293; short _307295; _307295 = *_304418; short _307297; _307297 = _307295; *_304400 = _307297; *_304418 = _307299; goto l304973; l304973: ; short _304975; _304975 = *_304409; short _304979; _304979 = _304975; short _304977; _304977 = *_304427; short _304978; _304978 = _304977; bool _304980; _304980 = _304978 < _304979; bool _304981; _304981 = _304980 == true; if (_304981) goto l304982; else goto l307291; l307291: ; goto l304983; l304982: ; short _307283; _307283 = *_304409; short _307289; _307289 = _307283; short _307285; _307285 = *_304427; short _307287; _307287 = _307285; *_304409 = _307287; *_304427 = _307289; goto l304983; l304983: ; short _304985; _304985 = *_304400; short _304989; _304989 = _304985; short _304987; _304987 = *_304409; short _304988; _304988 = _304987; bool _304990; _304990 = _304988 < _304989; bool _304991; _304991 = _304990 == true; if (_304991) goto l304992; else goto l307281; l307281: ; goto l304993; l304992: ; short _307273; _307273 = *_304400; short _307279; _307279 = _307273; short _307275; _307275 = *_304409; short _307277; _307277 = _307275; *_304400 = _307277; *_304409 = _307279; goto l304993; l304993: ; short _304995; _304995 = *_304418; short _304999; _304999 = _304995; short _304997; _304997 = *_304427; short _304998; _304998 = _304997; bool _305000; _305000 = _304998 < _304999; bool _305001; _305001 = _305000 == true; if (_305001) goto l305002; else goto l307271; l307271: ; goto l305003; l305002: ; short _307263; _307263 = *_304418; short _307269; _307269 = _307263; short _307265; _307265 = *_304427; short _307267; _307267 = _307265; *_304418 = _307267; *_304427 = _307269; goto l305003; l305003: ; short _305005; _305005 = *_304436; short _305009; _305009 = _305005; short _305007; _305007 = *_304454; short _305008; _305008 = _305007; bool _305010; _305010 = _305008 < _305009; bool _305011; _305011 = _305010 == true; if (_305011) goto l305012; else goto l307261; l307261: ; goto l305013; l305012: ; short _307253; _307253 = *_304436; short _307259; _307259 = _307253; short _307255; _307255 = *_304454; short _307257; _307257 = _307255; *_304436 = _307257; *_304454 = _307259; goto l305013; l305013: ; short _305015; _305015 = *_304445; short _305019; _305019 = _305015; short _305017; _305017 = *_304463; short _305018; _305018 = _305017; bool _305020; _305020 = _305018 < _305019; bool _305021; _305021 = _305020 == true; if (_305021) goto l305022; else goto l307251; l307251: ; goto l305023; l305022: ; short _307243; _307243 = *_304445; short _307249; _307249 = _307243; short _307245; _307245 = *_304463; short _307247; _307247 = _307245; *_304445 = _307247; *_304463 = _307249; goto l305023; l305023: ; short _305025; _305025 = *_304436; short _305029; _305029 = _305025; short _305027; _305027 = *_304445; short _305028; _305028 = _305027; bool _305030; _305030 = _305028 < _305029; bool _305031; _305031 = _305030 == true; if (_305031) goto l305032; else goto l307241; l307241: ; goto l305033; l305032: ; short _307233; _307233 = *_304436; short _307239; _307239 = _307233; short _307235; _307235 = *_304445; short _307237; _307237 = _307235; *_304436 = _307237; *_304445 = _307239; goto l305033; l305033: ; short _305035; _305035 = *_304454; short _305039; _305039 = _305035; short _305037; _305037 = *_304463; short _305038; _305038 = _305037; bool _305040; _305040 = _305038 < _305039; bool _305041; _305041 = _305040 == true; if (_305041) goto l305042; else goto l307231; l307231: ; goto l305043; l305042: ; short _307223; _307223 = *_304454; short _307229; _307229 = _307223; short _307225; _307225 = *_304463; short _307227; _307227 = _307225; *_304454 = _307227; *_304463 = _307229; goto l305043; l305043: ; short _305045; _305045 = *_304481; short _305049; _305049 = _305045; short _305047; _305047 = *_304490; short _305048; _305048 = _305047; bool _305050; _305050 = _305048 < _305049; bool _305051; _305051 = _305050 == true; if (_305051) goto l305052; else goto l307221; l307221: ; goto l305053; l305052: ; short _307213; _307213 = *_304481; short _307219; _307219 = _307213; short _307215; _307215 = *_304490; short _307217; _307217 = _307215; *_304481 = _307217; *_304490 = _307219; goto l305053; l305053: ; short _305055; _305055 = *_304472; short _305059; _305059 = _305055; short _305057; _305057 = *_304490; short _305058; _305058 = _305057; bool _305060; _305060 = _305058 < _305059; bool _305061; _305061 = _305060 == true; if (_305061) goto l305062; else goto l307211; l307211: ; goto l305063; l305062: ; short _307203; _307203 = *_304472; short _307209; _307209 = _307203; short _307205; _307205 = *_304490; short _307207; _307207 = _307205; *_304472 = _307207; *_304490 = _307209; goto l305063; l305063: ; short _305065; _305065 = *_304472; short _305069; _305069 = _305065; short _305067; _305067 = *_304481; short _305068; _305068 = _305067; bool _305070; _305070 = _305068 < _305069; bool _305071; _305071 = _305070 == true; if (_305071) goto l305072; else goto l307201; l307201: ; goto l305073; l305072: ; short _307193; _307193 = *_304472; short _307199; _307199 = _307193; short _307195; _307195 = *_304481; short _307197; _307197 = _307195; *_304472 = _307197; *_304481 = _307199; goto l305073; l305073: ; short _305075; _305075 = *_304508; short _305079; _305079 = _305075; short _305077; _305077 = *_304517; short _305078; _305078 = _305077; bool _305080; _305080 = _305078 < _305079; bool _305081; _305081 = _305080 == true; if (_305081) goto l305082; else goto l307191; l307191: ; goto l305083; l305082: ; short _307183; _307183 = *_304508; short _307189; _307189 = _307183; short _307185; _307185 = *_304517; short _307187; _307187 = _307185; *_304508 = _307187; *_304517 = _307189; goto l305083; l305083: ; short _305085; _305085 = *_304499; short _305089; _305089 = _305085; short _305087; _305087 = *_304517; short _305088; _305088 = _305087; bool _305090; _305090 = _305088 < _305089; bool _305091; _305091 = _305090 == true; if (_305091) goto l305092; else goto l307181; l307181: ; goto l305093; l305092: ; short _307173; _307173 = *_304499; short _307179; _307179 = _307173; short _307175; _307175 = *_304517; short _307177; _307177 = _307175; *_304499 = _307177; *_304517 = _307179; goto l305093; l305093: ; short _305095; _305095 = *_304499; short _305099; _305099 = _305095; short _305097; _305097 = *_304508; short _305098; _305098 = _305097; bool _305100; _305100 = _305098 < _305099; bool _305101; _305101 = _305100 == true; if (_305101) goto l305102; else goto l307171; l307171: ; goto l305103; l305102: ; short _307163; _307163 = *_304499; short _307169; _307169 = _307163; short _307165; _307165 = *_304508; short _307167; _307167 = _307165; *_304499 = _307167; *_304508 = _307169; goto l305103; l305103: ; short _305105; _305105 = *_304472; short _305109; _305109 = _305105; short _305107; _305107 = *_304508; short _305108; _305108 = _305107; bool _305110; _305110 = _305108 < _305109; bool _305111; _305111 = _305110 == true; if (_305111) goto l305112; else goto l307161; l307161: ; goto l305113; l305112: ; short _307153; _307153 = *_304472; short _307159; _307159 = _307153; short _307155; _307155 = *_304508; short _307157; _307157 = _307155; *_304472 = _307157; *_304508 = _307159; goto l305113; l305113: ; short _305115; _305115 = *_304481; short _305119; _305119 = _305115; short _305117; _305117 = *_304517; short _305118; _305118 = _305117; bool _305120; _305120 = _305118 < _305119; bool _305121; _305121 = _305120 == true; if (_305121) goto l305122; else goto l307151; l307151: ; goto l305123; l305122: ; short _307143; _307143 = *_304481; short _307149; _307149 = _307143; short _307145; _307145 = *_304517; short _307147; _307147 = _307145; *_304481 = _307147; *_304517 = _307149; goto l305123; l305123: ; short _305125; _305125 = *_304472; short _305129; _305129 = _305125; short _305127; _305127 = *_304490; short _305128; _305128 = _305127; bool _305130; _305130 = _305128 < _305129; bool _305131; _305131 = _305130 == true; if (_305131) goto l305132; else goto l307141; l307141: ; goto l305133; l305132: ; short _307133; _307133 = *_304472; short _307139; _307139 = _307133; short _307135; _307135 = *_304490; short _307137; _307137 = _307135; *_304472 = _307137; *_304490 = _307139; goto l305133; l305133: ; short _305135; _305135 = *_304481; short _305139; _305139 = _305135; short _305137; _305137 = *_304499; short _305138; _305138 = _305137; bool _305140; _305140 = _305138 < _305139; bool _305141; _305141 = _305140 == true; if (_305141) goto l305142; else goto l307131; l307131: ; goto l305143; l305142: ; short _307123; _307123 = *_304481; short _307129; _307129 = _307123; short _307125; _307125 = *_304499; short _307127; _307127 = _307125; *_304481 = _307127; *_304499 = _307129; goto l305143; l305143: ; short _305145; _305145 = *_304472; short _305149; _305149 = _305145; short _305147; _305147 = *_304481; short _305148; _305148 = _305147; bool _305150; _305150 = _305148 < _305149; bool _305151; _305151 = _305150 == true; if (_305151) goto l305152; else goto l307121; l307121: ; goto l305153; l305152: ; short _307113; _307113 = *_304472; short _307119; _307119 = _307113; short _307115; _307115 = *_304481; short _307117; _307117 = _307115; *_304472 = _307117; *_304481 = _307119; goto l305153; l305153: ; short _305155; _305155 = *_304490; short _305159; _305159 = _305155; short _305157; _305157 = *_304499; short _305158; _305158 = _305157; bool _305160; _305160 = _305158 < _305159; bool _305161; _305161 = _305160 == true; if (_305161) goto l305162; else goto l307111; l307111: ; goto l305163; l305162: ; short _307103; _307103 = *_304490; short _307109; _307109 = _307103; short _307105; _307105 = *_304499; short _307107; _307107 = _307105; *_304490 = _307107; *_304499 = _307109; goto l305163; l305163: ; short _305165; _305165 = *_304508; short _305169; _305169 = _305165; short _305167; _305167 = *_304517; short _305168; _305168 = _305167; bool _305170; _305170 = _305168 < _305169; bool _305171; _305171 = _305170 == true; if (_305171) goto l305172; else goto l307101; l307101: ; goto l305173; l305172: ; short _307093; _307093 = *_304508; short _307099; _307099 = _307093; short _307095; _307095 = *_304517; short _307097; _307097 = _307095; *_304508 = _307097; *_304517 = _307099; goto l305173; l305173: ; short _305175; _305175 = *_304535; short _305179; _305179 = _305175; short _305177; _305177 = *_304544; short _305178; _305178 = _305177; bool _305180; _305180 = _305178 < _305179; bool _305181; _305181 = _305180 == true; if (_305181) goto l305182; else goto l307091; l307091: ; goto l305183; l305182: ; short _307083; _307083 = *_304535; short _307085; _307085 = *_304544; short _307089; _307089 = _307083; short _307087; _307087 = _307085; *_304535 = _307087; *_304544 = _307089; goto l305183; l305183: ; short _305185; _305185 = *_304526; short _305189; _305189 = _305185; short _305187; _305187 = *_304544; short _305188; _305188 = _305187; bool _305190; _305190 = _305188 < _305189; bool _305191; _305191 = _305190 == true; if (_305191) goto l305192; else goto l307081; l307081: ; goto l305193; l305192: ; short _307073; _307073 = *_304526; short _307079; _307079 = _307073; short _307075; _307075 = *_304544; short _307077; _307077 = _307075; *_304526 = _307077; *_304544 = _307079; goto l305193; l305193: ; short _305195; _305195 = *_304526; short _305199; _305199 = _305195; short _305197; _305197 = *_304535; short _305198; _305198 = _305197; bool _305200; _305200 = _305198 < _305199; bool _305201; _305201 = _305200 == true; if (_305201) goto l305202; else goto l307071; l307071: ; goto l305203; l305202: ; short _307063; _307063 = *_304526; short _307069; _307069 = _307063; short _307065; _307065 = *_304535; short _307067; _307067 = _307065; *_304526 = _307067; *_304535 = _307069; goto l305203; l305203: ; short _305205; _305205 = *_304553; short _305209; _305209 = _305205; short _305207; _305207 = *_304562; short _305208; _305208 = _305207; bool _305210; _305210 = _305208 < _305209; bool _305211; _305211 = _305210 == true; if (_305211) goto l305212; else goto l307061; l307061: ; goto l305213; l305212: ; short _307053; _307053 = *_304553; short _307059; _307059 = _307053; short _307055; _307055 = *_304562; short _307057; _307057 = _307055; *_304553 = _307057; *_304562 = _307059; goto l305213; l305213: ; short _305215; _305215 = *_304571; short _305219; _305219 = _305215; short _305217; _305217 = *_304580; short _305218; _305218 = _305217; bool _305220; _305220 = _305218 < _305219; bool _305221; _305221 = _305220 == true; if (_305221) goto l305222; else goto l307051; l307051: ; goto l305223; l305222: ; short _307043; _307043 = *_304571; short _307049; _307049 = _307043; short _307045; _307045 = *_304580; short _307047; _307047 = _307045; *_304571 = _307047; *_304580 = _307049; goto l305223; l305223: ; short _305225; _305225 = *_304553; short _305229; _305229 = _305225; short _305227; _305227 = *_304571; short _305228; _305228 = _305227; bool _305230; _305230 = _305228 < _305229; bool _305231; _305231 = _305230 == true; if (_305231) goto l305232; else goto l307041; l307041: ; goto l305233; l305232: ; short _307033; _307033 = *_304553; short _307039; _307039 = _307033; short _307035; _307035 = *_304571; short _307037; _307037 = _307035; *_304553 = _307037; *_304571 = _307039; goto l305233; l305233: ; short _305235; _305235 = *_304562; short _305239; _305239 = _305235; short _305237; _305237 = *_304580; short _305238; _305238 = _305237; bool _305240; _305240 = _305238 < _305239; bool _305241; _305241 = _305240 == true; if (_305241) goto l305242; else goto l307031; l307031: ; goto l305243; l305242: ; short _307023; _307023 = *_304562; short _307029; _307029 = _307023; short _307025; _307025 = *_304580; short _307027; _307027 = _307025; *_304562 = _307027; *_304580 = _307029; goto l305243; l305243: ; short _305245; _305245 = *_304553; short _305249; _305249 = _305245; short _305247; _305247 = *_304562; short _305248; _305248 = _305247; bool _305250; _305250 = _305248 < _305249; bool _305251; _305251 = _305250 == true; if (_305251) goto l305252; else goto l307021; l307021: ; goto l305253; l305252: ; short _307013; _307013 = *_304553; short _307019; _307019 = _307013; short _307015; _307015 = *_304562; short _307017; _307017 = _307015; *_304553 = _307017; *_304562 = _307019; goto l305253; l305253: ; short _305255; _305255 = *_304571; short _305259; _305259 = _305255; short _305257; _305257 = *_304580; short _305258; _305258 = _305257; bool _305260; _305260 = _305258 < _305259; bool _305261; _305261 = _305260 == true; if (_305261) goto l305262; else goto l307011; l307011: ; goto l305263; l305262: ; short _307003; _307003 = *_304571; short _307009; _307009 = _307003; short _307005; _307005 = *_304580; short _307007; _307007 = _307005; *_304571 = _307007; *_304580 = _307009; goto l305263; l305263: ; short _305265; _305265 = *_304526; short _305269; _305269 = _305265; short _305267; _305267 = *_304562; short _305268; _305268 = _305267; bool _305270; _305270 = _305268 < _305269; bool _305271; _305271 = _305270 == true; if (_305271) goto l305272; else goto l307001; l307001: ; goto l305273; l305272: ; short _306993; _306993 = *_304526; short _306999; _306999 = _306993; short _306995; _306995 = *_304562; short _306997; _306997 = _306995; *_304526 = _306997; *_304562 = _306999; goto l305273; l305273: ; short _305275; _305275 = *_304535; short _305279; _305279 = _305275; short _305277; _305277 = *_304571; short _305278; _305278 = _305277; bool _305280; _305280 = _305278 < _305279; bool _305281; _305281 = _305280 == true; if (_305281) goto l305282; else goto l306991; l306991: ; goto l305283; l305282: ; short _306983; _306983 = *_304535; short _306989; _306989 = _306983; short _306985; _306985 = *_304571; short _306987; _306987 = _306985; *_304535 = _306987; *_304571 = _306989; goto l305283; l305283: ; short _305285; _305285 = *_304544; short _305289; _305289 = _305285; short _305287; _305287 = *_304580; short _305288; _305288 = _305287; bool _305290; _305290 = _305288 < _305289; bool _305291; _305291 = _305290 == true; if (_305291) goto l305292; else goto l306981; l306981: ; goto l305293; l305292: ; short _306973; _306973 = *_304544; short _306979; _306979 = _306973; short _306975; _306975 = *_304580; short _306977; _306977 = _306975; *_304544 = _306977; *_304580 = _306979; goto l305293; l305293: ; short _305295; _305295 = *_304526; short _305297; _305297 = *_304544; short _305299; _305299 = _305295; short _305298; _305298 = _305297; bool _305300; _305300 = _305298 < _305299; bool _305301; _305301 = _305300 == true; if (_305301) goto l305302; else goto l306971; l306971: ; goto l305303; l305302: ; short _306963; _306963 = *_304526; short _306969; _306969 = _306963; short _306965; _306965 = *_304544; short _306967; _306967 = _306965; *_304526 = _306967; *_304544 = _306969; goto l305303; l305303: ; short _305305; _305305 = *_304535; short _305309; _305309 = _305305; short _305307; _305307 = *_304553; short _305308; _305308 = _305307; bool _305310; _305310 = _305308 < _305309; bool _305311; _305311 = _305310 == true; if (_305311) goto l305312; else goto l306961; l306961: ; goto l305313; l305312: ; short _306953; _306953 = *_304535; short _306959; _306959 = _306953; short _306955; _306955 = *_304553; short _306957; _306957 = _306955; *_304535 = _306957; *_304553 = _306959; goto l305313; l305313: ; short _305315; _305315 = *_304526; short _305319; _305319 = _305315; short _305317; _305317 = *_304535; short _305318; _305318 = _305317; bool _305320; _305320 = _305318 < _305319; bool _305321; _305321 = _305320 == true; if (_305321) goto l305322; else goto l306951; l306951: ; goto l305323; l305322: ; short _306943; _306943 = *_304526; short _306945; _306945 = *_304535; short _306949; _306949 = _306943; short _306947; _306947 = _306945; *_304526 = _306947; *_304535 = _306949; goto l305323; l305323: ; short _305325; _305325 = *_304544; short _305329; _305329 = _305325; short _305327; _305327 = *_304553; short _305328; _305328 = _305327; bool _305330; _305330 = _305328 < _305329; bool _305331; _305331 = _305330 == true; if (_305331) goto l305332; else goto l306941; l306941: ; goto l305333; l305332: ; short _306933; _306933 = *_304544; short _306939; _306939 = _306933; short _306935; _306935 = *_304553; short _306937; _306937 = _306935; *_304544 = _306937; *_304553 = _306939; goto l305333; l305333: ; short _305335; _305335 = *_304562; short _305339; _305339 = _305335; short _305337; _305337 = *_304580; short _305338; _305338 = _305337; bool _305340; _305340 = _305338 < _305339; bool _305341; _305341 = _305340 == true; if (_305341) goto l305342; else goto l306931; l306931: ; goto l305343; l305342: ; short _306923; _306923 = *_304562; short _306929; _306929 = _306923; short _306925; _306925 = *_304580; short _306927; _306927 = _306925; *_304562 = _306927; *_304580 = _306929; goto l305343; l305343: ; short _305345; _305345 = *_304562; short _305349; _305349 = _305345; short _305347; _305347 = *_304571; short _305348; _305348 = _305347; bool _305350; _305350 = _305348 < _305349; bool _305351; _305351 = _305350 == true; if (_305351) goto l305352; else goto l306921; l306921: ; goto l305353; l305352: ; short _306913; _306913 = *_304562; short _306919; _306919 = _306913; short _306915; _306915 = *_304571; short _306917; _306917 = _306915; *_304562 = _306917; *_304571 = _306919; goto l305353; l305353: ; short _305355; _305355 = *_304472; short _305359; _305359 = _305355; short _305357; _305357 = *_304544; short _305358; _305358 = _305357; bool _305360; _305360 = _305358 < _305359; bool _305361; _305361 = _305360 == true; if (_305361) goto l305362; else goto l306911; l306911: ; goto l305363; l305362: ; short _306903; _306903 = *_304472; short _306909; _306909 = _306903; short _306905; _306905 = *_304544; short _306907; _306907 = _306905; *_304472 = _306907; *_304544 = _306909; goto l305363; l305363: ; short _305365; _305365 = *_304481; short _305369; _305369 = _305365; short _305367; _305367 = *_304553; short _305368; _305368 = _305367; bool _305370; _305370 = _305368 < _305369; bool _305371; _305371 = _305370 == true; if (_305371) goto l305372; else goto l306901; l306901: ; goto l305373; l305372: ; short _306893; _306893 = *_304481; short _306895; _306895 = *_304553; short _306897; _306897 = _306895; short _306899; _306899 = _306893; *_304481 = _306897; *_304553 = _306899; goto l305373; l305373: ; short _305375; _305375 = *_304490; short _305379; _305379 = _305375; short _305377; _305377 = *_304562; short _305378; _305378 = _305377; bool _305380; _305380 = _305378 < _305379; bool _305381; _305381 = _305380 == true; if (_305381) goto l305382; else goto l306891; l306891: ; goto l305383; l305382: ; short _306883; _306883 = *_304490; short _306889; _306889 = _306883; short _306885; _306885 = *_304562; short _306887; _306887 = _306885; *_304490 = _306887; *_304562 = _306889; goto l305383; l305383: ; short _305385; _305385 = *_304499; short _305389; _305389 = _305385; short _305387; _305387 = *_304571; short _305388; _305388 = _305387; bool _305390; _305390 = _305388 < _305389; bool _305391; _305391 = _305390 == true; if (_305391) goto l305392; else goto l306881; l306881: ; goto l305393; l305392: ; short _306873; _306873 = *_304499; short _306879; _306879 = _306873; short _306875; _306875 = *_304571; short _306877; _306877 = _306875; *_304499 = _306877; *_304571 = _306879; goto l305393; l305393: ; short _305395; _305395 = *_304508; short _305399; _305399 = _305395; short _305397; _305397 = *_304580; short _305398; _305398 = _305397; bool _305400; _305400 = _305398 < _305399; bool _305401; _305401 = _305400 == true; if (_305401) goto l305402; else goto l306871; l306871: ; goto l305403; l305402: ; short _306863; _306863 = *_304508; short _306869; _306869 = _306863; short _306865; _306865 = *_304580; short _306867; _306867 = _306865; *_304508 = _306867; *_304580 = _306869; goto l305403; l305403: ; short _305405; _305405 = *_304472; short _305409; _305409 = _305405; short _305407; _305407 = *_304508; short _305408; _305408 = _305407; bool _305410; _305410 = _305408 < _305409; bool _305411; _305411 = _305410 == true; if (_305411) goto l305412; else goto l306861; l306861: ; goto l305413; l305412: ; short _306853; _306853 = *_304472; short _306859; _306859 = _306853; short _306855; _306855 = *_304508; short _306857; _306857 = _306855; *_304472 = _306857; *_304508 = _306859; goto l305413; l305413: ; short _305415; _305415 = *_304481; short _305419; _305419 = _305415; short _305417; _305417 = *_304517; short _305418; _305418 = _305417; bool _305420; _305420 = _305418 < _305419; bool _305421; _305421 = _305420 == true; if (_305421) goto l305422; else goto l306851; l306851: ; goto l305423; l305422: ; short _306843; _306843 = *_304481; short _306849; _306849 = _306843; short _306845; _306845 = *_304517; short _306847; _306847 = _306845; *_304481 = _306847; *_304517 = _306849; goto l305423; l305423: ; short _305425; _305425 = *_304490; short _305429; _305429 = _305425; short _305427; _305427 = *_304526; short _305428; _305428 = _305427; bool _305430; _305430 = _305428 < _305429; bool _305431; _305431 = _305430 == true; if (_305431) goto l305432; else goto l306841; l306841: ; goto l305433; l305432: ; short _306833; _306833 = *_304490; short _306839; _306839 = _306833; short _306835; _306835 = *_304526; short _306837; _306837 = _306835; *_304490 = _306837; *_304526 = _306839; goto l305433; l305433: ; short _305435; _305435 = *_304499; short _305437; _305437 = *_304535; short _305438; _305438 = _305437; short _305439; _305439 = _305435; bool _305440; _305440 = _305438 < _305439; bool _305441; _305441 = _305440 == true; if (_305441) goto l305442; else goto l306831; l306831: ; goto l305443; l305442: ; short _306823; _306823 = *_304499; short _306829; _306829 = _306823; short _306825; _306825 = *_304535; short _306827; _306827 = _306825; *_304499 = _306827; *_304535 = _306829; goto l305443; l305443: ; short _305445; _305445 = *_304472; short _305449; _305449 = _305445; short _305447; _305447 = *_304490; short _305448; _305448 = _305447; bool _305450; _305450 = _305448 < _305449; bool _305451; _305451 = _305450 == true; if (_305451) goto l305452; else goto l306821; l306821: ; goto l305453; l305452: ; short _306813; _306813 = *_304472; short _306819; _306819 = _306813; short _306815; _306815 = *_304490; short _306817; _306817 = _306815; *_304472 = _306817; *_304490 = _306819; goto l305453; l305453: ; short _305455; _305455 = *_304481; short _305459; _305459 = _305455; short _305457; _305457 = *_304499; short _305458; _305458 = _305457; bool _305460; _305460 = _305458 < _305459; bool _305461; _305461 = _305460 == true; if (_305461) goto l305462; else goto l306811; l306811: ; goto l305463; l305462: ; short _306803; _306803 = *_304481; short _306809; _306809 = _306803; short _306805; _306805 = *_304499; short _306807; _306807 = _306805; *_304481 = _306807; *_304499 = _306809; goto l305463; l305463: ; short _305465; _305465 = *_304472; short _305469; _305469 = _305465; short _305467; _305467 = *_304481; short _305468; _305468 = _305467; bool _305470; _305470 = _305468 < _305469; bool _305471; _305471 = _305470 == true; if (_305471) goto l305472; else goto l306801; l306801: ; goto l305473; l305472: ; short _306793; _306793 = *_304472; short _306799; _306799 = _306793; short _306795; _306795 = *_304481; short _306797; _306797 = _306795; *_304472 = _306797; *_304481 = _306799; goto l305473; l305473: ; short _305475; _305475 = *_304490; short _305479; _305479 = _305475; short _305477; _305477 = *_304499; short _305478; _305478 = _305477; bool _305480; _305480 = _305478 < _305479; bool _305481; _305481 = _305480 == true; if (_305481) goto l305482; else goto l306791; l306791: ; goto l305483; l305482: ; short _306783; _306783 = *_304490; short _306789; _306789 = _306783; short _306785; _306785 = *_304499; short _306787; _306787 = _306785; *_304490 = _306787; *_304499 = _306789; goto l305483; l305483: ; short _305485; _305485 = *_304508; short _305489; _305489 = _305485; short _305487; _305487 = *_304526; short _305488; _305488 = _305487; bool _305490; _305490 = _305488 < _305489; bool _305491; _305491 = _305490 == true; if (_305491) goto l305492; else goto l306781; l306781: ; goto l305493; l305492: ; short _306773; _306773 = *_304508; short _306775; _306775 = *_304526; short _306779; _306779 = _306773; short _306777; _306777 = _306775; *_304508 = _306777; *_304526 = _306779; goto l305493; l305493: ; short _305495; _305495 = *_304517; short _305499; _305499 = _305495; short _305497; _305497 = *_304535; short _305498; _305498 = _305497; bool _305500; _305500 = _305498 < _305499; bool _305501; _305501 = _305500 == true; if (_305501) goto l305502; else goto l306771; l306771: ; goto l305503; l305502: ; short _306763; _306763 = *_304517; short _306769; _306769 = _306763; short _306765; _306765 = *_304535; short _306767; _306767 = _306765; *_304517 = _306767; *_304535 = _306769; goto l305503; l305503: ; short _305505; _305505 = *_304508; short _305509; _305509 = _305505; short _305507; _305507 = *_304517; short _305508; _305508 = _305507; bool _305510; _305510 = _305508 < _305509; bool _305511; _305511 = _305510 == true; if (_305511) goto l305512; else goto l306761; l306761: ; goto l305513; l305512: ; short _306753; _306753 = *_304508; short _306759; _306759 = _306753; short _306755; _306755 = *_304517; short _306757; _306757 = _306755; *_304508 = _306757; *_304517 = _306759; goto l305513; l305513: ; short _305515; _305515 = *_304526; short _305519; _305519 = _305515; short _305517; _305517 = *_304535; short _305518; _305518 = _305517; bool _305520; _305520 = _305518 < _305519; bool _305521; _305521 = _305520 == true; if (_305521) goto l305522; else goto l306751; l306751: ; goto l305523; l305522: ; short _306743; _306743 = *_304526; short _306749; _306749 = _306743; short _306745; _306745 = *_304535; short _306747; _306747 = _306745; *_304526 = _306747; *_304535 = _306749; goto l305523; l305523: ; short _305525; _305525 = *_304544; short _305529; _305529 = _305525; short _305527; _305527 = *_304580; short _305528; _305528 = _305527; bool _305530; _305530 = _305528 < _305529; bool _305531; _305531 = _305530 == true; if (_305531) goto l305532; else goto l306741; l306741: ; goto l305533; l305532: ; short _306733; _306733 = *_304544; short _306739; _306739 = _306733; short _306735; _306735 = *_304580; short _306737; _306737 = _306735; *_304544 = _306737; *_304580 = _306739; goto l305533; l305533: ; short _305535; _305535 = *_304544; short _305539; _305539 = _305535; short _305537; _305537 = *_304562; short _305538; _305538 = _305537; bool _305540; _305540 = _305538 < _305539; bool _305541; _305541 = _305540 == true; if (_305541) goto l305542; else goto l306731; l306731: ; goto l305543; l305542: ; short _306723; _306723 = *_304544; short _306729; _306729 = _306723; short _306725; _306725 = *_304562; short _306727; _306727 = _306725; *_304544 = _306727; *_304562 = _306729; goto l305543; l305543: ; short _305545; _305545 = *_304553; short _305549; _305549 = _305545; short _305547; _305547 = *_304571; short _305548; _305548 = _305547; bool _305550; _305550 = _305548 < _305549; bool _305551; _305551 = _305550 == true; if (_305551) goto l305552; else goto l306721; l306721: ; goto l305553; l305552: ; short _306713; _306713 = *_304553; short _306719; _306719 = _306713; short _306715; _306715 = *_304571; short _306717; _306717 = _306715; *_304553 = _306717; *_304571 = _306719; goto l305553; l305553: ; short _305555; _305555 = *_304544; short _305559; _305559 = _305555; short _305557; _305557 = *_304553; short _305558; _305558 = _305557; bool _305560; _305560 = _305558 < _305559; bool _305561; _305561 = _305560 == true; if (_305561) goto l305562; else goto l306711; l306711: ; goto l305563; l305562: ; short _306703; _306703 = *_304544; short _306709; _306709 = _306703; short _306705; _306705 = *_304553; short _306707; _306707 = _306705; *_304544 = _306707; *_304553 = _306709; goto l305563; l305563: ; short _305565; _305565 = *_304562; short _305569; _305569 = _305565; short _305567; _305567 = *_304571; short _305568; _305568 = _305567; bool _305570; _305570 = _305568 < _305569; bool _305571; _305571 = _305570 == true; if (_305571) goto l305572; else goto l306701; l306701: ; goto l305573; l305572: ; short _306693; _306693 = *_304562; short _306699; _306699 = _306693; short _306695; _306695 = *_304571; short _306697; _306697 = _306695; *_304562 = _306697; *_304571 = _306699; goto l305573; l305573: ; short _305575; _305575 = *_304368; short _305579; _305579 = _305575; short _305577; _305577 = *_304508; short _305578; _305578 = _305577; bool _305580; _305580 = _305578 < _305579; bool _305581; _305581 = _305580 == true; if (_305581) goto l305582; else goto l306691; l306691: ; goto l305583; l305582: ; short _306683; _306683 = *_304368; short _306685; _306685 = *_304508; short _306689; _306689 = _306683; short _306687; _306687 = _306685; *_304368 = _306687; *_304508 = _306689; goto l305583; l305583: ; short _305585; _305585 = *_304376; short _305589; _305589 = _305585; short _305587; _305587 = *_304517; short _305588; _305588 = _305587; bool _305590; _305590 = _305588 < _305589; bool _305591; _305591 = _305590 == true; if (_305591) goto l305592; else goto l306681; l306681: ; goto l305593; l305592: ; short _306673; _306673 = *_304376; short _306679; _306679 = _306673; short _306675; _306675 = *_304517; short _306677; _306677 = _306675; *_304376 = _306677; *_304517 = _306679; goto l305593; l305593: ; short _305595; _305595 = *_304384; short _305599; _305599 = _305595; short _305597; _305597 = *_304526; short _305598; _305598 = _305597; bool _305600; _305600 = _305598 < _305599; bool _305601; _305601 = _305600 == true; if (_305601) goto l305602; else goto l306671; l306671: ; goto l305603; l305602: ; short _306663; _306663 = *_304384; short _306669; _306669 = _306663; short _306665; _306665 = *_304526; short _306667; _306667 = _306665; *_304384 = _306667; *_304526 = _306669; goto l305603; l305603: ; short _305605; _305605 = *_304392; short _305609; _305609 = _305605; short _305607; _305607 = *_304535; short _305608; _305608 = _305607; bool _305610; _305610 = _305608 < _305609; bool _305611; _305611 = _305610 == true; if (_305611) goto l305612; else goto l306661; l306661: ; goto l305613; l305612: ; short _306653; _306653 = *_304392; short _306659; _306659 = _306653; short _306655; _306655 = *_304535; short _306657; _306657 = _306655; *_304392 = _306657; *_304535 = _306659; goto l305613; l305613: ; short _305615; _305615 = *_304400; short _305619; _305619 = _305615; short _305617; _305617 = *_304544; short _305618; _305618 = _305617; bool _305620; _305620 = _305618 < _305619; bool _305621; _305621 = _305620 == true; if (_305621) goto l305622; else goto l306651; l306651: ; goto l305623; l305622: ; short _306643; _306643 = *_304400; short _306649; _306649 = _306643; short _306645; _306645 = *_304544; short _306647; _306647 = _306645; *_304400 = _306647; *_304544 = _306649; goto l305623; l305623: ; short _305625; _305625 = *_304409; short _305629; _305629 = _305625; short _305627; _305627 = *_304553; short _305628; _305628 = _305627; bool _305630; _305630 = _305628 < _305629; bool _305631; _305631 = _305630 == true; if (_305631) goto l305632; else goto l306641; l306641: ; goto l305633; l305632: ; short _306633; _306633 = *_304409; short _306639; _306639 = _306633; short _306635; _306635 = *_304553; short _306637; _306637 = _306635; *_304409 = _306637; *_304553 = _306639; goto l305633; l305633: ; short _305635; _305635 = *_304418; short _305639; _305639 = _305635; short _305637; _305637 = *_304562; short _305638; _305638 = _305637; bool _305640; _305640 = _305638 < _305639; bool _305641; _305641 = _305640 == true; if (_305641) goto l305642; else goto l306631; l306631: ; goto l305643; l305642: ; short _306623; _306623 = *_304418; short _306629; _306629 = _306623; short _306625; _306625 = *_304562; short _306627; _306627 = _306625; *_304418 = _306627; *_304562 = _306629; goto l305643; l305643: ; short _305645; _305645 = *_304427; short _305649; _305649 = _305645; short _305647; _305647 = *_304571; short _305648; _305648 = _305647; bool _305650; _305650 = _305648 < _305649; bool _305651; _305651 = _305650 == true; if (_305651) goto l305652; else goto l306621; l306621: ; goto l305653; l305652: ; short _306613; _306613 = *_304427; short _306619; _306619 = _306613; short _306615; _306615 = *_304571; short _306617; _306617 = _306615; *_304427 = _306617; *_304571 = _306619; goto l305653; l305653: ; short _305655; _305655 = *_304436; short _305659; _305659 = _305655; short _305657; _305657 = *_304580; short _305658; _305658 = _305657; bool _305660; _305660 = _305658 < _305659; bool _305661; _305661 = _305660 == true; if (_305661) goto l305662; else goto l306611; l306611: ; goto l305663; l305662: ; short _306603; _306603 = *_304436; short _306609; _306609 = _306603; short _306605; _306605 = *_304580; short _306607; _306607 = _306605; *_304436 = _306607; *_304580 = _306609; goto l305663; l305663: ; short _305665; _305665 = *_304368; short _305669; _305669 = _305665; short _305667; _305667 = *_304436; short _305668; _305668 = _305667; bool _305670; _305670 = _305668 < _305669; bool _305671; _305671 = _305670 == true; if (_305671) goto l305672; else goto l306601; l306601: ; goto l305673; l305672: ; short _306593; _306593 = *_304368; short _306599; _306599 = _306593; short _306595; _306595 = *_304436; short _306597; _306597 = _306595; *_304368 = _306597; *_304436 = _306599; goto l305673; l305673: ; short _305675; _305675 = *_304376; short _305679; _305679 = _305675; short _305677; _305677 = *_304445; short _305678; _305678 = _305677; bool _305680; _305680 = _305678 < _305679; bool _305681; _305681 = _305680 == true; if (_305681) goto l305682; else goto l306591; l306591: ; goto l305683; l305682: ; short _306583; _306583 = *_304376; short _306589; _306589 = _306583; short _306585; _306585 = *_304445; short _306587; _306587 = _306585; *_304376 = _306587; *_304445 = _306589; goto l305683; l305683: ; short _305685; _305685 = *_304384; short _305689; _305689 = _305685; short _305687; _305687 = *_304454; short _305688; _305688 = _305687; bool _305690; _305690 = _305688 < _305689; bool _305691; _305691 = _305690 == true; if (_305691) goto l305692; else goto l306581; l306581: ; goto l305693; l305692: ; short _306573; _306573 = *_304384; short _306579; _306579 = _306573; short _306575; _306575 = *_304454; short _306577; _306577 = _306575; *_304384 = _306577; *_304454 = _306579; goto l305693; l305693: ; short _305695; _305695 = *_304392; short _305699; _305699 = _305695; short _305697; _305697 = *_304463; short _305698; _305698 = _305697; bool _305700; _305700 = _305698 < _305699; bool _305701; _305701 = _305700 == true; if (_305701) goto l305702; else goto l306571; l306571: ; goto l305703; l305702: ; short _306563; _306563 = *_304392; short _306569; _306569 = _306563; short _306565; _306565 = *_304463; short _306567; _306567 = _306565; *_304392 = _306567; *_304463 = _306569; goto l305703; l305703: ; short _305705; _305705 = *_304400; short _305709; _305709 = _305705; short _305707; _305707 = *_304472; short _305708; _305708 = _305707; bool _305710; _305710 = _305708 < _305709; bool _305711; _305711 = _305710 == true; if (_305711) goto l305712; else goto l306561; l306561: ; goto l305713; l305712: ; short _306553; _306553 = *_304400; short _306559; _306559 = _306553; short _306555; _306555 = *_304472; short _306557; _306557 = _306555; *_304400 = _306557; *_304472 = _306559; goto l305713; l305713: ; short _305715; _305715 = *_304409; short _305719; _305719 = _305715; short _305717; _305717 = *_304481; short _305718; _305718 = _305717; bool _305720; _305720 = _305718 < _305719; bool _305721; _305721 = _305720 == true; if (_305721) goto l305722; else goto l306551; l306551: ; goto l305723; l305722: ; short _306543; _306543 = *_304409; short _306545; _306545 = *_304481; short _306549; _306549 = _306543; short _306547; _306547 = _306545; *_304409 = _306547; *_304481 = _306549; goto l305723; l305723: ; short _305725; _305725 = *_304418; short _305729; _305729 = _305725; short _305727; _305727 = *_304490; short _305728; _305728 = _305727; bool _305730; _305730 = _305728 < _305729; bool _305731; _305731 = _305730 == true; if (_305731) goto l305732; else goto l306541; l306541: ; goto l305733; l305732: ; short _306533; _306533 = *_304418; short _306539; _306539 = _306533; short _306535; _306535 = *_304490; short _306537; _306537 = _306535; *_304418 = _306537; *_304490 = _306539; goto l305733; l305733: ; short _305735; _305735 = *_304427; short _305739; _305739 = _305735; short _305737; _305737 = *_304499; short _305738; _305738 = _305737; bool _305740; _305740 = _305738 < _305739; bool _305741; _305741 = _305740 == true; if (_305741) goto l305742; else goto l306531; l306531: ; goto l305743; l305742: ; short _306523; _306523 = *_304427; short _306525; _306525 = *_304499; short _306527; _306527 = _306525; short _306529; _306529 = _306523; *_304427 = _306527; *_304499 = _306529; goto l305743; l305743: ; short _305745; _305745 = *_304368; short _305749; _305749 = _305745; short _305747; _305747 = *_304400; short _305748; _305748 = _305747; bool _305750; _305750 = _305748 < _305749; bool _305751; _305751 = _305750 == true; if (_305751) goto l305752; else goto l306521; l306521: ; goto l305753; l305752: ; short _306513; _306513 = *_304368; short _306515; _306515 = *_304400; short _306519; _306519 = _306513; short _306517; _306517 = _306515; *_304368 = _306517; *_304400 = _306519; goto l305753; l305753: ; short _305755; _305755 = *_304376; short _305759; _305759 = _305755; short _305757; _305757 = *_304409; short _305758; _305758 = _305757; bool _305760; _305760 = _305758 < _305759; bool _305761; _305761 = _305760 == true; if (_305761) goto l305762; else goto l306511; l306511: ; goto l305763; l305762: ; short _306503; _306503 = *_304376; short _306509; _306509 = _306503; short _306505; _306505 = *_304409; short _306507; _306507 = _306505; *_304376 = _306507; *_304409 = _306509; goto l305763; l305763: ; short _305765; _305765 = *_304384; short _305769; _305769 = _305765; short _305767; _305767 = *_304418; short _305768; _305768 = _305767; bool _305770; _305770 = _305768 < _305769; bool _305771; _305771 = _305770 == true; if (_305771) goto l305772; else goto l306501; l306501: ; goto l305773; l305772: ; short _306493; _306493 = *_304384; short _306499; _306499 = _306493; short _306495; _306495 = *_304418; short _306497; _306497 = _306495; *_304384 = _306497; *_304418 = _306499; goto l305773; l305773: ; short _305775; _305775 = *_304392; short _305779; _305779 = _305775; short _305777; _305777 = *_304427; short _305778; _305778 = _305777; bool _305780; _305780 = _305778 < _305779; bool _305781; _305781 = _305780 == true; if (_305781) goto l305782; else goto l306491; l306491: ; goto l305783; l305782: ; short _306483; _306483 = *_304392; short _306489; _306489 = _306483; short _306485; _306485 = *_304427; short _306487; _306487 = _306485; *_304392 = _306487; *_304427 = _306489; goto l305783; l305783: ; short _305785; _305785 = *_304368; short _305787; _305787 = *_304384; short _305789; _305789 = _305785; short _305788; _305788 = _305787; bool _305790; _305790 = _305788 < _305789; bool _305791; _305791 = _305790 == true; if (_305791) goto l305792; else goto l306481; l306481: ; goto l305793; l305792: ; short _306473; _306473 = *_304368; short _306479; _306479 = _306473; short _306475; _306475 = *_304384; short _306477; _306477 = _306475; *_304368 = _306477; *_304384 = _306479; goto l305793; l305793: ; short _305795; _305795 = *_304376; short _305799; _305799 = _305795; short _305797; _305797 = *_304392; short _305798; _305798 = _305797; bool _305800; _305800 = _305798 < _305799; bool _305801; _305801 = _305800 == true; if (_305801) goto l305802; else goto l306471; l306471: ; goto l305803; l305802: ; short _306463; _306463 = *_304376; short _306469; _306469 = _306463; short _306465; _306465 = *_304392; short _306467; _306467 = _306465; *_304376 = _306467; *_304392 = _306469; goto l305803; l305803: ; short _305805; _305805 = *_304368; short _305809; _305809 = _305805; short _305807; _305807 = *_304376; short _305808; _305808 = _305807; bool _305810; _305810 = _305808 < _305809; bool _305811; _305811 = _305810 == true; if (_305811) goto l305812; else goto l306461; l306461: ; goto l305813; l305812: ; short _306453; _306453 = *_304368; short _306459; _306459 = _306453; short _306455; _306455 = *_304376; short _306457; _306457 = _306455; *_304368 = _306457; *_304376 = _306459; goto l305813; l305813: ; short _305815; _305815 = *_304384; short _305819; _305819 = _305815; short _305817; _305817 = *_304392; short _305818; _305818 = _305817; bool _305820; _305820 = _305818 < _305819; bool _305821; _305821 = _305820 == true; if (_305821) goto l305822; else goto l306451; l306451: ; goto l305823; l305822: ; short _306443; _306443 = *_304384; short _306449; _306449 = _306443; short _306445; _306445 = *_304392; short _306447; _306447 = _306445; *_304384 = _306447; *_304392 = _306449; goto l305823; l305823: ; short _305825; _305825 = *_304400; short _305829; _305829 = _305825; short _305827; _305827 = *_304418; short _305828; _305828 = _305827; bool _305830; _305830 = _305828 < _305829; bool _305831; _305831 = _305830 == true; if (_305831) goto l305832; else goto l306441; l306441: ; goto l305833; l305832: ; short _306433; _306433 = *_304400; short _306439; _306439 = _306433; short _306435; _306435 = *_304418; short _306437; _306437 = _306435; *_304400 = _306437; *_304418 = _306439; goto l305833; l305833: ; short _305835; _305835 = *_304409; short _305839; _305839 = _305835; short _305837; _305837 = *_304427; short _305838; _305838 = _305837; bool _305840; _305840 = _305838 < _305839; bool _305841; _305841 = _305840 == true; if (_305841) goto l305842; else goto l306431; l306431: ; goto l305843; l305842: ; short _306423; _306423 = *_304409; short _306429; _306429 = _306423; short _306425; _306425 = *_304427; short _306427; _306427 = _306425; *_304409 = _306427; *_304427 = _306429; goto l305843; l305843: ; short _305845; _305845 = *_304400; short _305849; _305849 = _305845; short _305847; _305847 = *_304409; short _305848; _305848 = _305847; bool _305850; _305850 = _305848 < _305849; bool _305851; _305851 = _305850 == true; if (_305851) goto l305852; else goto l306421; l306421: ; goto l305853; l305852: ; short _306413; _306413 = *_304400; short _306419; _306419 = _306413; short _306415; _306415 = *_304409; short _306417; _306417 = _306415; *_304400 = _306417; *_304409 = _306419; goto l305853; l305853: ; short _305855; _305855 = *_304418; short _305859; _305859 = _305855; short _305857; _305857 = *_304427; short _305858; _305858 = _305857; bool _305860; _305860 = _305858 < _305859; bool _305861; _305861 = _305860 == true; if (_305861) goto l305862; else goto l306411; l306411: ; goto l305863; l305862: ; short _306403; _306403 = *_304418; short _306409; _306409 = _306403; short _306405; _306405 = *_304427; short _306407; _306407 = _306405; *_304418 = _306407; *_304427 = _306409; goto l305863; l305863: ; short _305865; _305865 = *_304436; short _305869; _305869 = _305865; short _305867; _305867 = *_304472; short _305868; _305868 = _305867; bool _305870; _305870 = _305868 < _305869; bool _305871; _305871 = _305870 == true; if (_305871) goto l305872; else goto l306401; l306401: ; goto l305873; l305872: ; short _306393; _306393 = *_304436; short _306399; _306399 = _306393; short _306395; _306395 = *_304472; short _306397; _306397 = _306395; *_304436 = _306397; *_304472 = _306399; goto l305873; l305873: ; short _305875; _305875 = *_304445; short _305879; _305879 = _305875; short _305877; _305877 = *_304481; short _305878; _305878 = _305877; bool _305880; _305880 = _305878 < _305879; bool _305881; _305881 = _305880 == true; if (_305881) goto l305882; else goto l306391; l306391: ; goto l305883; l305882: ; short _306383; _306383 = *_304445; short _306385; _306385 = *_304481; short _306389; _306389 = _306383; short _306387; _306387 = _306385; *_304445 = _306387; *_304481 = _306389; goto l305883; l305883: ; short _305885; _305885 = *_304454; short _305887; _305887 = *_304490; short _305889; _305889 = _305885; short _305888; _305888 = _305887; bool _305890; _305890 = _305888 < _305889; bool _305891; _305891 = _305890 == true; if (_305891) goto l305892; else goto l306381; l306381: ; goto l305893; l305892: ; short _306373; _306373 = *_304454; short _306375; _306375 = *_304490; short _306379; _306379 = _306373; short _306377; _306377 = _306375; *_304454 = _306377; *_304490 = _306379; goto l305893; l305893: ; short _305895; _305895 = *_304463; short _305899; _305899 = _305895; short _305897; _305897 = *_304499; short _305898; _305898 = _305897; bool _305900; _305900 = _305898 < _305899; bool _305901; _305901 = _305900 == true; if (_305901) goto l305902; else goto l306371; l306371: ; goto l305903; l305902: ; short _306363; _306363 = *_304463; short _306369; _306369 = _306363; short _306365; _306365 = *_304499; short _306367; _306367 = _306365; *_304463 = _306367; *_304499 = _306369; goto l305903; l305903: ; short _305905; _305905 = *_304436; short _305909; _305909 = _305905; short _305907; _305907 = *_304454; short _305908; _305908 = _305907; bool _305910; _305910 = _305908 < _305909; bool _305911; _305911 = _305910 == true; if (_305911) goto l305912; else goto l306361; l306361: ; goto l305913; l305912: ; short _306353; _306353 = *_304436; short _306359; _306359 = _306353; short _306355; _306355 = *_304454; short _306357; _306357 = _306355; *_304436 = _306357; *_304454 = _306359; goto l305913; l305913: ; short _305915; _305915 = *_304445; short _305917; _305917 = *_304463; short _305919; _305919 = _305915; short _305918; _305918 = _305917; bool _305920; _305920 = _305918 < _305919; bool _305921; _305921 = _305920 == true; if (_305921) goto l305922; else goto l306351; l306351: ; goto l305923; l305922: ; short _306343; _306343 = *_304445; short _306349; _306349 = _306343; short _306345; _306345 = *_304463; short _306347; _306347 = _306345; *_304445 = _306347; *_304463 = _306349; goto l305923; l305923: ; short _305925; _305925 = *_304436; short _305929; _305929 = _305925; short _305927; _305927 = *_304445; short _305928; _305928 = _305927; bool _305930; _305930 = _305928 < _305929; bool _305931; _305931 = _305930 == true; if (_305931) goto l305932; else goto l306341; l306341: ; goto l305933; l305932: ; short _306333; _306333 = *_304436; short _306339; _306339 = _306333; short _306335; _306335 = *_304445; short _306337; _306337 = _306335; *_304436 = _306337; *_304445 = _306339; goto l305933; l305933: ; short _305935; _305935 = *_304454; short _305939; _305939 = _305935; short _305937; _305937 = *_304463; short _305938; _305938 = _305937; bool _305940; _305940 = _305938 < _305939; bool _305941; _305941 = _305940 == true; if (_305941) goto l305942; else goto l306331; l306331: ; goto l305943; l305942: ; short _306323; _306323 = *_304454; short _306329; _306329 = _306323; short _306325; _306325 = *_304463; short _306327; _306327 = _306325; *_304454 = _306327; *_304463 = _306329; goto l305943; l305943: ; short _305945; _305945 = *_304472; short _305949; _305949 = _305945; short _305947; _305947 = *_304490; short _305948; _305948 = _305947; bool _305950; _305950 = _305948 < _305949; bool _305951; _305951 = _305950 == true; if (_305951) goto l305952; else goto l306321; l306321: ; goto l305953; l305952: ; short _306313; _306313 = *_304472; short _306319; _306319 = _306313; short _306315; _306315 = *_304490; short _306317; _306317 = _306315; *_304472 = _306317; *_304490 = _306319; goto l305953; l305953: ; short _305955; _305955 = *_304481; short _305959; _305959 = _305955; short _305957; _305957 = *_304499; short _305958; _305958 = _305957; bool _305960; _305960 = _305958 < _305959; bool _305961; _305961 = _305960 == true; if (_305961) goto l305962; else goto l306311; l306311: ; goto l305963; l305962: ; short _306303; _306303 = *_304481; short _306309; _306309 = _306303; short _306305; _306305 = *_304499; short _306307; _306307 = _306305; *_304481 = _306307; *_304499 = _306309; goto l305963; l305963: ; short _305965; _305965 = *_304472; short _305969; _305969 = _305965; short _305967; _305967 = *_304481; short _305968; _305968 = _305967; bool _305970; _305970 = _305968 < _305969; bool _305971; _305971 = _305970 == true; if (_305971) goto l305972; else goto l306301; l306301: ; goto l305973; l305972: ; short _306293; _306293 = *_304472; short _306299; _306299 = _306293; short _306295; _306295 = *_304481; short _306297; _306297 = _306295; *_304472 = _306297; *_304481 = _306299; goto l305973; l305973: ; short _305975; _305975 = *_304490; short _305979; _305979 = _305975; short _305977; _305977 = *_304499; short _305978; _305978 = _305977; bool _305980; _305980 = _305978 < _305979; bool _305981; _305981 = _305980 == true; if (_305981) goto l305982; else goto l306291; l306291: ; goto l305983; l305982: ; short _306283; _306283 = *_304490; short _306289; _306289 = _306283; short _306285; _306285 = *_304499; short _306287; _306287 = _306285; *_304490 = _306287; *_304499 = _306289; goto l305983; l305983: ; short _305985; _305985 = *_304508; short _305989; _305989 = _305985; short _305987; _305987 = *_304580; short _305988; _305988 = _305987; bool _305990; _305990 = _305988 < _305989; bool _305991; _305991 = _305990 == true; if (_305991) goto l305992; else goto l306281; l306281: ; goto l305993; l305992: ; short _306273; _306273 = *_304508; short _306279; _306279 = _306273; short _306275; _306275 = *_304580; short _306277; _306277 = _306275; *_304508 = _306277; *_304580 = _306279; goto l305993; l305993: ; short _305995; _305995 = *_304508; short _305999; _305999 = _305995; short _305997; _305997 = *_304544; short _305998; _305998 = _305997; bool _306000; _306000 = _305998 < _305999; bool _306001; _306001 = _306000 == true; if (_306001) goto l306002; else goto l306271; l306271: ; goto l306003; l306002: ; short _306263; _306263 = *_304508; short _306269; _306269 = _306263; short _306265; _306265 = *_304544; short _306267; _306267 = _306265; *_304508 = _306267; *_304544 = _306269; goto l306003; l306003: ; short _306005; _306005 = *_304517; short _306009; _306009 = _306005; short _306007; _306007 = *_304553; short _306008; _306008 = _306007; bool _306010; _306010 = _306008 < _306009; bool _306011; _306011 = _306010 == true; if (_306011) goto l306012; else goto l306261; l306261: ; goto l306013; l306012: ; short _306253; _306253 = *_304517; short _306259; _306259 = _306253; short _306255; _306255 = *_304553; short _306257; _306257 = _306255; *_304517 = _306257; *_304553 = _306259; goto l306013; l306013: ; short _306015; _306015 = *_304526; short _306019; _306019 = _306015; short _306017; _306017 = *_304562; short _306018; _306018 = _306017; bool _306020; _306020 = _306018 < _306019; bool _306021; _306021 = _306020 == true; if (_306021) goto l306022; else goto l306251; l306251: ; goto l306023; l306022: ; short _306243; _306243 = *_304526; short _306245; _306245 = *_304562; short _306247; _306247 = _306245; short _306249; _306249 = _306243; *_304526 = _306247; *_304562 = _306249; goto l306023; l306023: ; short _306025; _306025 = *_304535; short _306029; _306029 = _306025; short _306027; _306027 = *_304571; short _306028; _306028 = _306027; bool _306030; _306030 = _306028 < _306029; bool _306031; _306031 = _306030 == true; if (_306031) goto l306032; else goto l306241; l306241: ; goto l306033; l306032: ; short _306233; _306233 = *_304535; short _306239; _306239 = _306233; short _306235; _306235 = *_304571; short _306237; _306237 = _306235; *_304535 = _306237; *_304571 = _306239; goto l306033; l306033: ; short _306035; _306035 = *_304508; short _306039; _306039 = _306035; short _306037; _306037 = *_304526; short _306038; _306038 = _306037; bool _306040; _306040 = _306038 < _306039; bool _306041; _306041 = _306040 == true; if (_306041) goto l306042; else goto l306231; l306231: ; goto l306043; l306042: ; short _306223; _306223 = *_304508; short _306229; _306229 = _306223; short _306225; _306225 = *_304526; short _306227; _306227 = _306225; *_304508 = _306227; *_304526 = _306229; goto l306043; l306043: ; short _306045; _306045 = *_304517; short _306049; _306049 = _306045; short _306047; _306047 = *_304535; short _306048; _306048 = _306047; bool _306050; _306050 = _306048 < _306049; bool _306051; _306051 = _306050 == true; if (_306051) goto l306052; else goto l306221; l306221: ; goto l306053; l306052: ; short _306213; _306213 = *_304517; short _306219; _306219 = _306213; short _306215; _306215 = *_304535; short _306217; _306217 = _306215; *_304517 = _306217; *_304535 = _306219; goto l306053; l306053: ; short _306055; _306055 = *_304508; short _306059; _306059 = _306055; short _306057; _306057 = *_304517; short _306058; _306058 = _306057; bool _306060; _306060 = _306058 < _306059; bool _306061; _306061 = _306060 == true; if (_306061) goto l306062; else goto l306211; l306211: ; goto l306063; l306062: ; short _306203; _306203 = *_304508; short _306209; _306209 = _306203; short _306205; _306205 = *_304517; short _306207; _306207 = _306205; *_304508 = _306207; *_304517 = _306209; goto l306063; l306063: ; short _306065; _306065 = *_304526; short _306069; _306069 = _306065; short _306067; _306067 = *_304535; short _306068; _306068 = _306067; bool _306070; _306070 = _306068 < _306069; bool _306071; _306071 = _306070 == true; if (_306071) goto l306072; else goto l306201; l306201: ; goto l306073; l306072: ; short _306193; _306193 = *_304526; short _306199; _306199 = _306193; short _306195; _306195 = *_304535; short _306197; _306197 = _306195; *_304526 = _306197; *_304535 = _306199; goto l306073; l306073: ; short _306075; _306075 = *_304544; short _306079; _306079 = _306075; short _306077; _306077 = *_304562; short _306078; _306078 = _306077; bool _306080; _306080 = _306078 < _306079; bool _306081; _306081 = _306080 == true; if (_306081) goto l306082; else goto l306191; l306191: ; goto l306083; l306082: ; short _306183; _306183 = *_304544; short _306189; _306189 = _306183; short _306185; _306185 = *_304562; short _306187; _306187 = _306185; *_304544 = _306187; *_304562 = _306189; goto l306083; l306083: ; short _306085; _306085 = *_304553; short _306089; _306089 = _306085; short _306087; _306087 = *_304571; short _306088; _306088 = _306087; bool _306090; _306090 = _306088 < _306089; bool _306091; _306091 = _306090 == true; if (_306091) goto l306092; else goto l306181; l306181: ; goto l306093; l306092: ; short _306173; _306173 = *_304553; short _306179; _306179 = _306173; short _306175; _306175 = *_304571; short _306177; _306177 = _306175; *_304553 = _306177; *_304571 = _306179; goto l306093; l306093: ; short _306095; _306095 = *_304544; short _306099; _306099 = _306095; short _306097; _306097 = *_304553; short _306098; _306098 = _306097; bool _306100; _306100 = _306098 < _306099; bool _306101; _306101 = _306100 == true; if (_306101) goto l306102; else goto l306171; l306171: ; goto l306103; l306102: ; short _306163; _306163 = *_304544; short _306169; _306169 = _306163; short _306165; _306165 = *_304553; short _306167; _306167 = _306165; *_304544 = _306167; *_304553 = _306169; goto l306103; l306103: ; short _306105; _306105 = *_304562; short _306109; _306109 = _306105; short _306107; _306107 = *_304571; short _306108; _306108 = _306107; bool _306110; _306110 = _306108 < _306109; bool _306111; _306111 = _306110 == true; if (_306111) goto l306112; else goto l306161; l306161: ; goto l306113; l306112: ; short _306153; _306153 = *_304562; short _306159; _306159 = _306153; short _306155; _306155 = *_304571; short _306157; _306157 = _306155; *_304562 = _306157; *_304571 = _306159; goto l306113; l306113: ; short _306115; _306115 = *_304409; int _306123; _306123 = _304185 * _304191; int gid_y_306124; gid_y_306124 = _304179 + _306123; int _306126; _306126 = 4 * _231615_304150; short _306143; _306143 = _306115; short _306117; _306117 = *_304418; int _306133; _306133 = blockDim_x_304167 * blockIdx_x_304173; int _306127; _306127 = 64 + _306126; short _306144; _306144 = _306117; int _306134; _306134 = threadIdx_x_304161 + _306133; int _306128; _306128 = _306127 - 1; short _306119; _306119 = *_304526; short _306145; _306145 = _306143 + _306144; int _306129; _306129 = _306128 / 64; short _306137; _306137 = _306119; float _306146; _306146 = (float)_306145; int _306130; _306130 = 64 * _306129; short _306121; _306121 = *_304535; float Q1_306147; Q1_306147 = _306146 / 2.000000e+00f; int stride_306131; stride_306131 = _306130 / 4; short _306138; _306138 = _306121; int _306132; _306132 = gid_y_306124 * stride_306131; short _306139; _306139 = _306137 + _306138; int _306135; _306135 = _306132 + _306134; float _306140; _306140 = (float)_306139; float* idx_306136; idx_306136 = _231617_304152 + _306135; float Q3_306142; Q3_306142 = _306140 / 2.000000e+00f; float _306148; _306148 = Q3_306142 - Q1_306147; float _306149; _306149 = Q3_306142 + Q1_306147; float _306150; _306150 = _306148 / _306149; *idx_306136 = _306150; return ; } __global__ __launch_bounds__ (32 * 4 * 1) void lambda_238321(short* _238324_307973, int _238325_307974, int _238326_307975, short* _238327_307976, int _238328_307977, float* _238329_307978) { int threadIdx_x_307981; int pthreadIdx_x_307981; int blockDim_x_307984; int pblockDim_x_307984; int blockIdx_x_307987; int pblockIdx_x_307987; int _307990; int p_307990; int _307993; int p_307993; int _307996; int p_307996; int _307999; int p_307999; int converge_309710; int pconverge_309710; int converge_309714; int pconverge_309714; int converge_309717; int pconverge_309717; int converge_309721; int pconverge_309721; int converge_308025; int pconverge_308025; int converge_308029; int pconverge_308029; int converge_308034; int pconverge_308034; int converge_308038; int pconverge_308038; int converge_308044; int pconverge_308044; int converge_308048; int pconverge_308048; int converge_308051; int pconverge_308051; int converge_308055; int pconverge_308055; int converge_308059; int pconverge_308059; int converge_308063; int pconverge_308063; int converge_308066; int pconverge_308066; int converge_308070; int pconverge_308070; int converge_308075; int pconverge_308075; int converge_308079; int pconverge_308079; int converge_308082; int pconverge_308082; int converge_308086; int pconverge_308086; int converge_308091; int pconverge_308091; int converge_308095; int pconverge_308095; int converge_308098; int pconverge_308098; int converge_308102; int pconverge_308102; int converge_308105; int pconverge_308105; int converge_308109; int pconverge_308109; int converge_308114; int pconverge_308114; int converge_308118; int pconverge_308118; int converge_308121; int pconverge_308121; int converge_308125; int pconverge_308125; int converge_308128; int pconverge_308128; int converge_308132; int pconverge_308132; int converge_308135; int pconverge_308135; int converge_308139; int pconverge_308139; int converge_308142; int pconverge_308142; int converge_308146; int pconverge_308146; int converge_308149; int pconverge_308149; int converge_308153; int pconverge_308153; int converge_308156; int pconverge_308156; int converge_308160; int pconverge_308160; int converge_308163; int pconverge_308163; int converge_308167; int pconverge_308167; int converge_308170; int pconverge_308170; int converge_308174; int pconverge_308174; int converge_308177; int pconverge_308177; int converge_308181; int pconverge_308181; int converge_308185; int pconverge_308185; int converge_308189; int pconverge_308189; int converge_308192; int pconverge_308192; int converge_308196; int pconverge_308196; int converge_308199; int pconverge_308199; int converge_308203; int pconverge_308203; int converge_308206; int pconverge_308206; int converge_308210; int pconverge_308210; int converge_308213; int pconverge_308213; int converge_308217; int pconverge_308217; int converge_308220; int pconverge_308220; int converge_308224; int pconverge_308224; int converge_308227; int pconverge_308227; int converge_308231; int pconverge_308231; int converge_308234; int pconverge_308234; int converge_308238; int pconverge_308238; int converge_308241; int pconverge_308241; int converge_308245; int pconverge_308245; int converge_308248; int pconverge_308248; int converge_308252; int pconverge_308252; int converge_308257; int pconverge_308257; int converge_308261; int pconverge_308261; int converge_308264; int pconverge_308264; int converge_308268; int pconverge_308268; int converge_308271; int pconverge_308271; int converge_308275; int pconverge_308275; int converge_308278; int pconverge_308278; int converge_308282; int pconverge_308282; int converge_308285; int pconverge_308285; int converge_308289; int pconverge_308289; int converge_308292; int pconverge_308292; int converge_308296; int pconverge_308296; int converge_308299; int pconverge_308299; int converge_308303; int pconverge_308303; int converge_308306; int pconverge_308306; int converge_308310; int pconverge_308310; int converge_308313; int pconverge_308313; int converge_308317; int pconverge_308317; int converge_308320; int pconverge_308320; int converge_308324; int pconverge_308324; int converge_308329; int pconverge_308329; int converge_308333; int pconverge_308333; int converge_308336; int pconverge_308336; int converge_308340; int pconverge_308340; int converge_308343; int pconverge_308343; int converge_308347; int pconverge_308347; int converge_308350; int pconverge_308350; int converge_308354; int pconverge_308354; int converge_308357; int pconverge_308357; int converge_308361; int pconverge_308361; int converge_308364; int pconverge_308364; int converge_308368; int pconverge_308368; int converge_308371; int pconverge_308371; int converge_308375; int pconverge_308375; int converge_308378; int pconverge_308378; int converge_308382; int pconverge_308382; int converge_308385; int pconverge_308385; int converge_308389; int pconverge_308389; int lower_308394; int plower_308394; int upper_308395; int pupper_308395; int step_308396; int pstep_308396; int _308401; int p_308401; int converge_309235; int pconverge_309235; int converge_309239; int pconverge_309239; int converge_309242; int pconverge_309242; int converge_309246; int pconverge_309246; int converge_308413; int pconverge_308413; int converge_308417; int pconverge_308417; int converge_308422; int pconverge_308422; int converge_308426; int pconverge_308426; int converge_308429; int pconverge_308429; int converge_308433; int pconverge_308433; int converge_308436; int pconverge_308436; int converge_308440; int pconverge_308440; int converge_308443; int pconverge_308443; int converge_308447; int pconverge_308447; int converge_308450; int pconverge_308450; int converge_308454; int pconverge_308454; int converge_308457; int pconverge_308457; int converge_308461; int pconverge_308461; int converge_308464; int pconverge_308464; int converge_308468; int pconverge_308468; int converge_308471; int pconverge_308471; int converge_308475; int pconverge_308475; int converge_308478; int pconverge_308478; int converge_308482; int pconverge_308482; int converge_308485; int pconverge_308485; int converge_308489; int pconverge_308489; int converge_308494; int pconverge_308494; int converge_308498; int pconverge_308498; int converge_308501; int pconverge_308501; int converge_308505; int pconverge_308505; int converge_308508; int pconverge_308508; int converge_308512; int pconverge_308512; int converge_308515; int pconverge_308515; int converge_308519; int pconverge_308519; int converge_308522; int pconverge_308522; int converge_308526; int pconverge_308526; int converge_308529; int pconverge_308529; int converge_308533; int pconverge_308533; int converge_308536; int pconverge_308536; int converge_308540; int pconverge_308540; int converge_308543; int pconverge_308543; int converge_308547; int pconverge_308547; int converge_308550; int pconverge_308550; int converge_308554; int pconverge_308554; int converge_308557; int pconverge_308557; int converge_308561; int pconverge_308561; int converge_308565; int pconverge_308565; int converge_308569; int pconverge_308569; int converge_308572; int pconverge_308572; int converge_308576; int pconverge_308576; int converge_308579; int pconverge_308579; int converge_308583; int pconverge_308583; int converge_308586; int pconverge_308586; int converge_308590; int pconverge_308590; int converge_308593; int pconverge_308593; int converge_308597; int pconverge_308597; int converge_308600; int pconverge_308600; int converge_308604; int pconverge_308604; int converge_308607; int pconverge_308607; int converge_308611; int pconverge_308611; int converge_308614; int pconverge_308614; int converge_308618; int pconverge_308618; int converge_308621; int pconverge_308621; int converge_308625; int pconverge_308625; int converge_308628; int pconverge_308628; int converge_308632; int pconverge_308632; int converge_308637; int pconverge_308637; int converge_308641; int pconverge_308641; int converge_308644; int pconverge_308644; int converge_308648; int pconverge_308648; int converge_308651; int pconverge_308651; int converge_308655; int pconverge_308655; int converge_308658; int pconverge_308658; int converge_308662; int pconverge_308662; int converge_308665; int pconverge_308665; int converge_308669; int pconverge_308669; int converge_308672; int pconverge_308672; int converge_308676; int pconverge_308676; int converge_308679; int pconverge_308679; int converge_308683; int pconverge_308683; int converge_308686; int pconverge_308686; int converge_308690; int pconverge_308690; int converge_308693; int pconverge_308693; int converge_308697; int pconverge_308697; int converge_308700; int pconverge_308700; int converge_308704; int pconverge_308704; int converge_308709; int pconverge_308709; int converge_308713; int pconverge_308713; int converge_308716; int pconverge_308716; int converge_308720; int pconverge_308720; int converge_308723; int pconverge_308723; int converge_308727; int pconverge_308727; int converge_308730; int pconverge_308730; int converge_308734; int pconverge_308734; int converge_308737; int pconverge_308737; int converge_308741; int pconverge_308741; int converge_308744; int pconverge_308744; int converge_308748; int pconverge_308748; int converge_308751; int pconverge_308751; int converge_308755; int pconverge_308755; int converge_308758; int pconverge_308758; int converge_308762; int pconverge_308762; int converge_308765; int pconverge_308765; int converge_308769; int pconverge_308769; threadIdx_x_307981 = threadIdx_x(); pthreadIdx_x_307981 = threadIdx_x_307981; l307979: ; threadIdx_x_307981 = pthreadIdx_x_307981; blockDim_x_307984 = blockDim_x(); pblockDim_x_307984 = blockDim_x_307984; l307982: ; blockDim_x_307984 = pblockDim_x_307984; blockIdx_x_307987 = blockIdx_x(); pblockIdx_x_307987 = blockIdx_x_307987; l307985: ; blockIdx_x_307987 = pblockIdx_x_307987; _307990 = threadIdx_y(); p_307990 = _307990; l307988: ; _307990 = p_307990; _307993 = blockDim_y(); p_307993 = _307993; l307991: ; _307993 = p_307993; _307996 = blockIdx_y(); p_307996 = _307996; l307994: ; _307996 = p_307996; _307999 = blockDim_y(); p_307999 = _307999; l307997: ; _307999 = p_307999; int _308899; _308899 = 2 * _238325_307974; int _308005; _308005 = 4 * _238325_307974; int _308006; _308006 = 64 + _308005; int _308003; _308003 = _307993 * _307996; int _308900; _308900 = 64 + _308899; int _308012; _308012 = blockDim_x_307984 * blockIdx_x_307987; float _308000; _308000 = (float)_238328_307977; int _308013; _308013 = threadIdx_x_307981 + _308012; int _308007; _308007 = _308006 - 1; int gid_y_308004; gid_y_308004 = _307990 + _308003; int _308901; _308901 = _308900 - 1; float threshold_308002; threshold_308002 = _308000 / 2.560000e+02f; int _308021; _308021 = -2 + _308013; bool _308056; _308056 = _308013 < 0; int _308087; _308087 = 2 + _308013; int _308997; _308997 = 0 - _308013; int _308040; _308040 = -1 + _308013; int _308071; _308071 = 1 + _308013; int _308008; _308008 = _308007 / 64; bool _308182; _308182 = gid_y_308004 < 0; int _309555; _309555 = 0 - gid_y_308004; int _308902; _308902 = _308901 / 64; bool _308022; _308022 = _308021 < 0; int _309021; _309021 = 0 - _308021; bool _308088; _308088 = _308087 < 0; int _308973; _308973 = 0 - _308087; int _308998; _308998 = _308997 - 1; bool _308041; _308041 = _308040 < 0; int _309009; _309009 = 0 - _308040; int _308985; _308985 = 0 - _308071; bool _308072; _308072 = _308071 < 0; int _308009; _308009 = 64 * _308008; int _309556; _309556 = _309555 - 1; int _308903; _308903 = 64 * _308902; int _309022; _309022 = _309021 - 1; int _308974; _308974 = _308973 - 1; int _309010; _309010 = _309009 - 1; int _308986; _308986 = _308985 - 1; int stride_308010; stride_308010 = _308009 / 4; int stride_308904; stride_308904 = _308903 / 2; int _308011; _308011 = gid_y_308004 * stride_308010; int _309391; _309391 = gid_y_308004 * stride_308904; int _308014; _308014 = _308011 + _308013; int _309392; _309392 = _309391 + _308013; float* idx_308015; idx_308015 = _238329_307978 + _308014; short* idx_309393; idx_309393 = _238324_307973 + _309392; float _308016; _308016 = *idx_308015; float _308017; _308017 = _308016; bool _308018; _308018 = threshold_308002 < _308017; if (_308018) goto l308019; else goto l309707; l309707: ; if (_308056) goto l309708; else goto l309738; l309738: ; pconverge_309710 = _308013; goto l309709; l309708: ; pconverge_309710 = _308998; goto l309709; l309709: ; converge_309710 = pconverge_309710; bool _309711; _309711 = _238325_307974 <= converge_309710; if (_309711) goto l309712; else goto l309737; l309737: ; pconverge_309714 = converge_309710; goto l309713; l309712: ; int _309734; _309734 = 1 + converge_309710; int _309735; _309735 = _309734 - _238325_307974; int _309736; _309736 = _238325_307974 - _309735; pconverge_309714 = _309736; goto l309713; l309713: ; converge_309714 = pconverge_309714; if (_308182) goto l309715; else goto l309733; l309733: ; pconverge_309717 = gid_y_308004; goto l309716; l309715: ; pconverge_309717 = _309556; goto l309716; l309716: ; converge_309717 = pconverge_309717; bool _309718; _309718 = _238326_307975 <= converge_309717; if (_309718) goto l309719; else goto l309732; l309732: ; pconverge_309721 = converge_309717; goto l309720; l309719: ; int _309729; _309729 = 1 + converge_309717; int _309730; _309730 = _309729 - _238326_307975; int _309731; _309731 = _238326_307975 - _309730; pconverge_309721 = _309731; goto l309720; l309720: ; converge_309721 = pconverge_309721; int _309722; _309722 = converge_309721 * _238325_307974; int _309723; _309723 = _309722 + converge_309714; short* idx_309724; idx_309724 = _238327_307976 + _309723; short _309725; _309725 = *idx_309724; short _309727; _309727 = _309725; *idx_309393 = _309727; goto l308390; l308019: ; if (_308022) goto l308023; else goto l309706; l309706: ; pconverge_308025 = _308021; goto l308024; l308023: ; pconverge_308025 = _309022; goto l308024; l308024: ; converge_308025 = pconverge_308025; bool _308026; _308026 = _238325_307974 <= converge_308025; if (_308026) goto l308027; else goto l309705; l309705: ; pconverge_308029 = converge_308025; goto l308028; l308027: ; int _309702; _309702 = 1 + converge_308025; int _309703; _309703 = _309702 - _238325_307974; int _309704; _309704 = _238325_307974 - _309703; pconverge_308029 = _309704; goto l308028; l308028: ; converge_308029 = pconverge_308029; int _308030; _308030 = -2 + gid_y_308004; int _309659; _309659 = 0 - _308030; bool _308031; _308031 = _308030 < 0; int _309660; _309660 = _309659 - 1; if (_308031) goto l308032; else goto l309701; l309701: ; pconverge_308034 = _308030; goto l308033; l308032: ; pconverge_308034 = _309660; goto l308033; l308033: ; converge_308034 = pconverge_308034; bool _308035; _308035 = _238326_307975 <= converge_308034; if (_308035) goto l308036; else goto l309700; l309700: ; pconverge_308038 = converge_308034; goto l308037; l308036: ; int _309697; _309697 = 1 + converge_308034; int _309698; _309698 = _309697 - _238326_307975; int _309699; _309699 = _238326_307975 - _309698; pconverge_308038 = _309699; goto l308037; l308037: ; converge_308038 = pconverge_308038; if (_308041) goto l308042; else goto l309696; l309696: ; pconverge_308044 = _308040; goto l308043; l308042: ; pconverge_308044 = _309010; goto l308043; l308043: ; converge_308044 = pconverge_308044; bool _308045; _308045 = _238325_307974 <= converge_308044; if (_308045) goto l308046; else goto l309695; l309695: ; pconverge_308048 = converge_308044; goto l308047; l308046: ; int _309692; _309692 = 1 + converge_308044; int _309693; _309693 = _309692 - _238325_307974; int _309694; _309694 = _238325_307974 - _309693; pconverge_308048 = _309694; goto l308047; l308047: ; converge_308048 = pconverge_308048; if (_308031) goto l308049; else goto l309691; l309691: ; pconverge_308051 = _308030; goto l308050; l308049: ; pconverge_308051 = _309660; goto l308050; l308050: ; converge_308051 = pconverge_308051; bool _308052; _308052 = _238326_307975 <= converge_308051; if (_308052) goto l308053; else goto l309690; l309690: ; pconverge_308055 = converge_308051; goto l308054; l308053: ; int _309687; _309687 = 1 + converge_308051; int _309688; _309688 = _309687 - _238326_307975; int _309689; _309689 = _238326_307975 - _309688; pconverge_308055 = _309689; goto l308054; l308054: ; converge_308055 = pconverge_308055; if (_308056) goto l308057; else goto l309686; l309686: ; pconverge_308059 = _308013; goto l308058; l308057: ; pconverge_308059 = _308998; goto l308058; l308058: ; converge_308059 = pconverge_308059; bool _308060; _308060 = _238325_307974 <= converge_308059; if (_308060) goto l308061; else goto l309685; l309685: ; pconverge_308063 = converge_308059; goto l308062; l308061: ; int _309682; _309682 = 1 + converge_308059; int _309683; _309683 = _309682 - _238325_307974; int _309684; _309684 = _238325_307974 - _309683; pconverge_308063 = _309684; goto l308062; l308062: ; converge_308063 = pconverge_308063; if (_308031) goto l308064; else goto l309681; l309681: ; pconverge_308066 = _308030; goto l308065; l308064: ; pconverge_308066 = _309660; goto l308065; l308065: ; converge_308066 = pconverge_308066; bool _308067; _308067 = _238326_307975 <= converge_308066; if (_308067) goto l308068; else goto l309680; l309680: ; pconverge_308070 = converge_308066; goto l308069; l308068: ; int _309677; _309677 = 1 + converge_308066; int _309678; _309678 = _309677 - _238326_307975; int _309679; _309679 = _238326_307975 - _309678; pconverge_308070 = _309679; goto l308069; l308069: ; converge_308070 = pconverge_308070; if (_308072) goto l308073; else goto l309676; l309676: ; pconverge_308075 = _308071; goto l308074; l308073: ; pconverge_308075 = _308986; goto l308074; l308074: ; converge_308075 = pconverge_308075; bool _308076; _308076 = _238325_307974 <= converge_308075; if (_308076) goto l308077; else goto l309675; l309675: ; pconverge_308079 = converge_308075; goto l308078; l308077: ; int _309672; _309672 = 1 + converge_308075; int _309673; _309673 = _309672 - _238325_307974; int _309674; _309674 = _238325_307974 - _309673; pconverge_308079 = _309674; goto l308078; l308078: ; converge_308079 = pconverge_308079; if (_308031) goto l308080; else goto l309671; l309671: ; pconverge_308082 = _308030; goto l308081; l308080: ; pconverge_308082 = _309660; goto l308081; l308081: ; converge_308082 = pconverge_308082; bool _308083; _308083 = _238326_307975 <= converge_308082; if (_308083) goto l308084; else goto l309670; l309670: ; pconverge_308086 = converge_308082; goto l308085; l308084: ; int _309667; _309667 = 1 + converge_308082; int _309668; _309668 = _309667 - _238326_307975; int _309669; _309669 = _238326_307975 - _309668; pconverge_308086 = _309669; goto l308085; l308085: ; converge_308086 = pconverge_308086; if (_308088) goto l308089; else goto l309666; l309666: ; pconverge_308091 = _308087; goto l308090; l308089: ; pconverge_308091 = _308974; goto l308090; l308090: ; converge_308091 = pconverge_308091; bool _308092; _308092 = _238325_307974 <= converge_308091; if (_308092) goto l308093; else goto l309665; l309665: ; pconverge_308095 = converge_308091; goto l308094; l308093: ; int _309662; _309662 = 1 + converge_308091; int _309663; _309663 = _309662 - _238325_307974; int _309664; _309664 = _238325_307974 - _309663; pconverge_308095 = _309664; goto l308094; l308094: ; converge_308095 = pconverge_308095; if (_308031) goto l308096; else goto l309661; l309661: ; pconverge_308098 = _308030; goto l308097; l308096: ; pconverge_308098 = _309660; goto l308097; l308097: ; converge_308098 = pconverge_308098; bool _308099; _308099 = _238326_307975 <= converge_308098; if (_308099) goto l308100; else goto l309658; l309658: ; pconverge_308102 = converge_308098; goto l308101; l308100: ; int _309655; _309655 = 1 + converge_308098; int _309656; _309656 = _309655 - _238326_307975; int _309657; _309657 = _238326_307975 - _309656; pconverge_308102 = _309657; goto l308101; l308101: ; converge_308102 = pconverge_308102; if (_308022) goto l308103; else goto l309654; l309654: ; pconverge_308105 = _308021; goto l308104; l308103: ; pconverge_308105 = _309022; goto l308104; l308104: ; converge_308105 = pconverge_308105; bool _308106; _308106 = _238325_307974 <= converge_308105; if (_308106) goto l308107; else goto l309653; l309653: ; pconverge_308109 = converge_308105; goto l308108; l308107: ; int _309650; _309650 = 1 + converge_308105; int _309651; _309651 = _309650 - _238325_307974; int _309652; _309652 = _238325_307974 - _309651; pconverge_308109 = _309652; goto l308108; l308108: ; converge_308109 = pconverge_308109; int _308110; _308110 = -1 + gid_y_308004; int _309607; _309607 = 0 - _308110; bool _308111; _308111 = _308110 < 0; int _309608; _309608 = _309607 - 1; if (_308111) goto l308112; else goto l309649; l309649: ; pconverge_308114 = _308110; goto l308113; l308112: ; pconverge_308114 = _309608; goto l308113; l308113: ; converge_308114 = pconverge_308114; bool _308115; _308115 = _238326_307975 <= converge_308114; if (_308115) goto l308116; else goto l309648; l309648: ; pconverge_308118 = converge_308114; goto l308117; l308116: ; int _309645; _309645 = 1 + converge_308114; int _309646; _309646 = _309645 - _238326_307975; int _309647; _309647 = _238326_307975 - _309646; pconverge_308118 = _309647; goto l308117; l308117: ; converge_308118 = pconverge_308118; if (_308041) goto l308119; else goto l309644; l309644: ; pconverge_308121 = _308040; goto l308120; l308119: ; pconverge_308121 = _309010; goto l308120; l308120: ; converge_308121 = pconverge_308121; bool _308122; _308122 = _238325_307974 <= converge_308121; if (_308122) goto l308123; else goto l309643; l309643: ; pconverge_308125 = converge_308121; goto l308124; l308123: ; int _309640; _309640 = 1 + converge_308121; int _309641; _309641 = _309640 - _238325_307974; int _309642; _309642 = _238325_307974 - _309641; pconverge_308125 = _309642; goto l308124; l308124: ; converge_308125 = pconverge_308125; if (_308111) goto l308126; else goto l309639; l309639: ; pconverge_308128 = _308110; goto l308127; l308126: ; pconverge_308128 = _309608; goto l308127; l308127: ; converge_308128 = pconverge_308128; bool _308129; _308129 = _238326_307975 <= converge_308128; if (_308129) goto l308130; else goto l309638; l309638: ; pconverge_308132 = converge_308128; goto l308131; l308130: ; int _309635; _309635 = 1 + converge_308128; int _309636; _309636 = _309635 - _238326_307975; int _309637; _309637 = _238326_307975 - _309636; pconverge_308132 = _309637; goto l308131; l308131: ; converge_308132 = pconverge_308132; if (_308056) goto l308133; else goto l309634; l309634: ; pconverge_308135 = _308013; goto l308134; l308133: ; pconverge_308135 = _308998; goto l308134; l308134: ; converge_308135 = pconverge_308135; bool _308136; _308136 = _238325_307974 <= converge_308135; if (_308136) goto l308137; else goto l309633; l309633: ; pconverge_308139 = converge_308135; goto l308138; l308137: ; int _309630; _309630 = 1 + converge_308135; int _309631; _309631 = _309630 - _238325_307974; int _309632; _309632 = _238325_307974 - _309631; pconverge_308139 = _309632; goto l308138; l308138: ; converge_308139 = pconverge_308139; if (_308111) goto l308140; else goto l309629; l309629: ; pconverge_308142 = _308110; goto l308141; l308140: ; pconverge_308142 = _309608; goto l308141; l308141: ; converge_308142 = pconverge_308142; bool _308143; _308143 = _238326_307975 <= converge_308142; if (_308143) goto l308144; else goto l309628; l309628: ; pconverge_308146 = converge_308142; goto l308145; l308144: ; int _309625; _309625 = 1 + converge_308142; int _309626; _309626 = _309625 - _238326_307975; int _309627; _309627 = _238326_307975 - _309626; pconverge_308146 = _309627; goto l308145; l308145: ; converge_308146 = pconverge_308146; if (_308072) goto l308147; else goto l309624; l309624: ; pconverge_308149 = _308071; goto l308148; l308147: ; pconverge_308149 = _308986; goto l308148; l308148: ; converge_308149 = pconverge_308149; bool _308150; _308150 = _238325_307974 <= converge_308149; if (_308150) goto l308151; else goto l309623; l309623: ; pconverge_308153 = converge_308149; goto l308152; l308151: ; int _309620; _309620 = 1 + converge_308149; int _309621; _309621 = _309620 - _238325_307974; int _309622; _309622 = _238325_307974 - _309621; pconverge_308153 = _309622; goto l308152; l308152: ; converge_308153 = pconverge_308153; if (_308111) goto l308154; else goto l309619; l309619: ; pconverge_308156 = _308110; goto l308155; l308154: ; pconverge_308156 = _309608; goto l308155; l308155: ; converge_308156 = pconverge_308156; bool _308157; _308157 = _238326_307975 <= converge_308156; if (_308157) goto l308158; else goto l309618; l309618: ; pconverge_308160 = converge_308156; goto l308159; l308158: ; int _309615; _309615 = 1 + converge_308156; int _309616; _309616 = _309615 - _238326_307975; int _309617; _309617 = _238326_307975 - _309616; pconverge_308160 = _309617; goto l308159; l308159: ; converge_308160 = pconverge_308160; if (_308088) goto l308161; else goto l309614; l309614: ; pconverge_308163 = _308087; goto l308162; l308161: ; pconverge_308163 = _308974; goto l308162; l308162: ; converge_308163 = pconverge_308163; bool _308164; _308164 = _238325_307974 <= converge_308163; if (_308164) goto l308165; else goto l309613; l309613: ; pconverge_308167 = converge_308163; goto l308166; l308165: ; int _309610; _309610 = 1 + converge_308163; int _309611; _309611 = _309610 - _238325_307974; int _309612; _309612 = _238325_307974 - _309611; pconverge_308167 = _309612; goto l308166; l308166: ; converge_308167 = pconverge_308167; if (_308111) goto l308168; else goto l309609; l309609: ; pconverge_308170 = _308110; goto l308169; l308168: ; pconverge_308170 = _309608; goto l308169; l308169: ; converge_308170 = pconverge_308170; bool _308171; _308171 = _238326_307975 <= converge_308170; if (_308171) goto l308172; else goto l309606; l309606: ; pconverge_308174 = converge_308170; goto l308173; l308172: ; int _309603; _309603 = 1 + converge_308170; int _309604; _309604 = _309603 - _238326_307975; int _309605; _309605 = _238326_307975 - _309604; pconverge_308174 = _309605; goto l308173; l308173: ; converge_308174 = pconverge_308174; if (_308022) goto l308175; else goto l309602; l309602: ; pconverge_308177 = _308021; goto l308176; l308175: ; pconverge_308177 = _309022; goto l308176; l308176: ; converge_308177 = pconverge_308177; bool _308178; _308178 = _238325_307974 <= converge_308177; if (_308178) goto l308179; else goto l309601; l309601: ; pconverge_308181 = converge_308177; goto l308180; l308179: ; int _309598; _309598 = 1 + converge_308177; int _309599; _309599 = _309598 - _238325_307974; int _309600; _309600 = _238325_307974 - _309599; pconverge_308181 = _309600; goto l308180; l308180: ; converge_308181 = pconverge_308181; if (_308182) goto l308183; else goto l309597; l309597: ; pconverge_308185 = gid_y_308004; goto l308184; l308183: ; pconverge_308185 = _309556; goto l308184; l308184: ; converge_308185 = pconverge_308185; bool _308186; _308186 = _238326_307975 <= converge_308185; if (_308186) goto l308187; else goto l309596; l309596: ; pconverge_308189 = converge_308185; goto l308188; l308187: ; int _309593; _309593 = 1 + converge_308185; int _309594; _309594 = _309593 - _238326_307975; int _309595; _309595 = _238326_307975 - _309594; pconverge_308189 = _309595; goto l308188; l308188: ; converge_308189 = pconverge_308189; if (_308041) goto l308190; else goto l309592; l309592: ; pconverge_308192 = _308040; goto l308191; l308190: ; pconverge_308192 = _309010; goto l308191; l308191: ; converge_308192 = pconverge_308192; bool _308193; _308193 = _238325_307974 <= converge_308192; if (_308193) goto l308194; else goto l309591; l309591: ; pconverge_308196 = converge_308192; goto l308195; l308194: ; int _309588; _309588 = 1 + converge_308192; int _309589; _309589 = _309588 - _238325_307974; int _309590; _309590 = _238325_307974 - _309589; pconverge_308196 = _309590; goto l308195; l308195: ; converge_308196 = pconverge_308196; if (_308182) goto l308197; else goto l309587; l309587: ; pconverge_308199 = gid_y_308004; goto l308198; l308197: ; pconverge_308199 = _309556; goto l308198; l308198: ; converge_308199 = pconverge_308199; bool _308200; _308200 = _238326_307975 <= converge_308199; if (_308200) goto l308201; else goto l309586; l309586: ; pconverge_308203 = converge_308199; goto l308202; l308201: ; int _309583; _309583 = 1 + converge_308199; int _309584; _309584 = _309583 - _238326_307975; int _309585; _309585 = _238326_307975 - _309584; pconverge_308203 = _309585; goto l308202; l308202: ; converge_308203 = pconverge_308203; if (_308056) goto l308204; else goto l309582; l309582: ; pconverge_308206 = _308013; goto l308205; l308204: ; pconverge_308206 = _308998; goto l308205; l308205: ; converge_308206 = pconverge_308206; bool _308207; _308207 = _238325_307974 <= converge_308206; if (_308207) goto l308208; else goto l309581; l309581: ; pconverge_308210 = converge_308206; goto l308209; l308208: ; int _309578; _309578 = 1 + converge_308206; int _309579; _309579 = _309578 - _238325_307974; int _309580; _309580 = _238325_307974 - _309579; pconverge_308210 = _309580; goto l308209; l308209: ; converge_308210 = pconverge_308210; if (_308182) goto l308211; else goto l309577; l309577: ; pconverge_308213 = gid_y_308004; goto l308212; l308211: ; pconverge_308213 = _309556; goto l308212; l308212: ; converge_308213 = pconverge_308213; bool _308214; _308214 = _238326_307975 <= converge_308213; if (_308214) goto l308215; else goto l309576; l309576: ; pconverge_308217 = converge_308213; goto l308216; l308215: ; int _309573; _309573 = 1 + converge_308213; int _309574; _309574 = _309573 - _238326_307975; int _309575; _309575 = _238326_307975 - _309574; pconverge_308217 = _309575; goto l308216; l308216: ; converge_308217 = pconverge_308217; if (_308072) goto l308218; else goto l309572; l309572: ; pconverge_308220 = _308071; goto l308219; l308218: ; pconverge_308220 = _308986; goto l308219; l308219: ; converge_308220 = pconverge_308220; bool _308221; _308221 = _238325_307974 <= converge_308220; if (_308221) goto l308222; else goto l309571; l309571: ; pconverge_308224 = converge_308220; goto l308223; l308222: ; int _309568; _309568 = 1 + converge_308220; int _309569; _309569 = _309568 - _238325_307974; int _309570; _309570 = _238325_307974 - _309569; pconverge_308224 = _309570; goto l308223; l308223: ; converge_308224 = pconverge_308224; if (_308182) goto l308225; else goto l309567; l309567: ; pconverge_308227 = gid_y_308004; goto l308226; l308225: ; pconverge_308227 = _309556; goto l308226; l308226: ; converge_308227 = pconverge_308227; bool _308228; _308228 = _238326_307975 <= converge_308227; if (_308228) goto l308229; else goto l309566; l309566: ; pconverge_308231 = converge_308227; goto l308230; l308229: ; int _309563; _309563 = 1 + converge_308227; int _309564; _309564 = _309563 - _238326_307975; int _309565; _309565 = _238326_307975 - _309564; pconverge_308231 = _309565; goto l308230; l308230: ; converge_308231 = pconverge_308231; if (_308088) goto l308232; else goto l309562; l309562: ; pconverge_308234 = _308087; goto l308233; l308232: ; pconverge_308234 = _308974; goto l308233; l308233: ; converge_308234 = pconverge_308234; bool _308235; _308235 = _238325_307974 <= converge_308234; if (_308235) goto l308236; else goto l309561; l309561: ; pconverge_308238 = converge_308234; goto l308237; l308236: ; int _309558; _309558 = 1 + converge_308234; int _309559; _309559 = _309558 - _238325_307974; int _309560; _309560 = _238325_307974 - _309559; pconverge_308238 = _309560; goto l308237; l308237: ; converge_308238 = pconverge_308238; if (_308182) goto l308239; else goto l309557; l309557: ; pconverge_308241 = gid_y_308004; goto l308240; l308239: ; pconverge_308241 = _309556; goto l308240; l308240: ; converge_308241 = pconverge_308241; bool _308242; _308242 = _238326_307975 <= converge_308241; if (_308242) goto l308243; else goto l309554; l309554: ; pconverge_308245 = converge_308241; goto l308244; l308243: ; int _309551; _309551 = 1 + converge_308241; int _309552; _309552 = _309551 - _238326_307975; int _309553; _309553 = _238326_307975 - _309552; pconverge_308245 = _309553; goto l308244; l308244: ; converge_308245 = pconverge_308245; if (_308022) goto l308246; else goto l309550; l309550: ; pconverge_308248 = _308021; goto l308247; l308246: ; pconverge_308248 = _309022; goto l308247; l308247: ; converge_308248 = pconverge_308248; bool _308249; _308249 = _238325_307974 <= converge_308248; if (_308249) goto l308250; else goto l309549; l309549: ; pconverge_308252 = converge_308248; goto l308251; l308250: ; int _309546; _309546 = 1 + converge_308248; int _309547; _309547 = _309546 - _238325_307974; int _309548; _309548 = _238325_307974 - _309547; pconverge_308252 = _309548; goto l308251; l308251: ; converge_308252 = pconverge_308252; int _308253; _308253 = 1 + gid_y_308004; bool _308254; _308254 = _308253 < 0; int _309503; _309503 = 0 - _308253; int _309504; _309504 = _309503 - 1; if (_308254) goto l308255; else goto l309545; l309545: ; pconverge_308257 = _308253; goto l308256; l308255: ; pconverge_308257 = _309504; goto l308256; l308256: ; converge_308257 = pconverge_308257; bool _308258; _308258 = _238326_307975 <= converge_308257; if (_308258) goto l308259; else goto l309544; l309544: ; pconverge_308261 = converge_308257; goto l308260; l308259: ; int _309541; _309541 = 1 + converge_308257; int _309542; _309542 = _309541 - _238326_307975; int _309543; _309543 = _238326_307975 - _309542; pconverge_308261 = _309543; goto l308260; l308260: ; converge_308261 = pconverge_308261; if (_308041) goto l308262; else goto l309540; l309540: ; pconverge_308264 = _308040; goto l308263; l308262: ; pconverge_308264 = _309010; goto l308263; l308263: ; converge_308264 = pconverge_308264; bool _308265; _308265 = _238325_307974 <= converge_308264; if (_308265) goto l308266; else goto l309539; l309539: ; pconverge_308268 = converge_308264; goto l308267; l308266: ; int _309536; _309536 = 1 + converge_308264; int _309537; _309537 = _309536 - _238325_307974; int _309538; _309538 = _238325_307974 - _309537; pconverge_308268 = _309538; goto l308267; l308267: ; converge_308268 = pconverge_308268; if (_308254) goto l308269; else goto l309535; l309535: ; pconverge_308271 = _308253; goto l308270; l308269: ; pconverge_308271 = _309504; goto l308270; l308270: ; converge_308271 = pconverge_308271; bool _308272; _308272 = _238326_307975 <= converge_308271; if (_308272) goto l308273; else goto l309534; l309534: ; pconverge_308275 = converge_308271; goto l308274; l308273: ; int _309531; _309531 = 1 + converge_308271; int _309532; _309532 = _309531 - _238326_307975; int _309533; _309533 = _238326_307975 - _309532; pconverge_308275 = _309533; goto l308274; l308274: ; converge_308275 = pconverge_308275; if (_308056) goto l308276; else goto l309530; l309530: ; pconverge_308278 = _308013; goto l308277; l308276: ; pconverge_308278 = _308998; goto l308277; l308277: ; converge_308278 = pconverge_308278; bool _308279; _308279 = _238325_307974 <= converge_308278; if (_308279) goto l308280; else goto l309529; l309529: ; pconverge_308282 = converge_308278; goto l308281; l308280: ; int _309526; _309526 = 1 + converge_308278; int _309527; _309527 = _309526 - _238325_307974; int _309528; _309528 = _238325_307974 - _309527; pconverge_308282 = _309528; goto l308281; l308281: ; converge_308282 = pconverge_308282; if (_308254) goto l308283; else goto l309525; l309525: ; pconverge_308285 = _308253; goto l308284; l308283: ; pconverge_308285 = _309504; goto l308284; l308284: ; converge_308285 = pconverge_308285; bool _308286; _308286 = _238326_307975 <= converge_308285; if (_308286) goto l308287; else goto l309524; l309524: ; pconverge_308289 = converge_308285; goto l308288; l308287: ; int _309521; _309521 = 1 + converge_308285; int _309522; _309522 = _309521 - _238326_307975; int _309523; _309523 = _238326_307975 - _309522; pconverge_308289 = _309523; goto l308288; l308288: ; converge_308289 = pconverge_308289; if (_308072) goto l308290; else goto l309520; l309520: ; pconverge_308292 = _308071; goto l308291; l308290: ; pconverge_308292 = _308986; goto l308291; l308291: ; converge_308292 = pconverge_308292; bool _308293; _308293 = _238325_307974 <= converge_308292; if (_308293) goto l308294; else goto l309519; l309519: ; pconverge_308296 = converge_308292; goto l308295; l308294: ; int _309516; _309516 = 1 + converge_308292; int _309517; _309517 = _309516 - _238325_307974; int _309518; _309518 = _238325_307974 - _309517; pconverge_308296 = _309518; goto l308295; l308295: ; converge_308296 = pconverge_308296; if (_308254) goto l308297; else goto l309515; l309515: ; pconverge_308299 = _308253; goto l308298; l308297: ; pconverge_308299 = _309504; goto l308298; l308298: ; converge_308299 = pconverge_308299; bool _308300; _308300 = _238326_307975 <= converge_308299; if (_308300) goto l308301; else goto l309514; l309514: ; pconverge_308303 = converge_308299; goto l308302; l308301: ; int _309511; _309511 = 1 + converge_308299; int _309512; _309512 = _309511 - _238326_307975; int _309513; _309513 = _238326_307975 - _309512; pconverge_308303 = _309513; goto l308302; l308302: ; converge_308303 = pconverge_308303; if (_308088) goto l308304; else goto l309510; l309510: ; pconverge_308306 = _308087; goto l308305; l308304: ; pconverge_308306 = _308974; goto l308305; l308305: ; converge_308306 = pconverge_308306; bool _308307; _308307 = _238325_307974 <= converge_308306; if (_308307) goto l308308; else goto l309509; l309509: ; pconverge_308310 = converge_308306; goto l308309; l308308: ; int _309506; _309506 = 1 + converge_308306; int _309507; _309507 = _309506 - _238325_307974; int _309508; _309508 = _238325_307974 - _309507; pconverge_308310 = _309508; goto l308309; l308309: ; converge_308310 = pconverge_308310; if (_308254) goto l308311; else goto l309505; l309505: ; pconverge_308313 = _308253; goto l308312; l308311: ; pconverge_308313 = _309504; goto l308312; l308312: ; converge_308313 = pconverge_308313; bool _308314; _308314 = _238326_307975 <= converge_308313; if (_308314) goto l308315; else goto l309502; l309502: ; pconverge_308317 = converge_308313; goto l308316; l308315: ; int _309499; _309499 = 1 + converge_308313; int _309500; _309500 = _309499 - _238326_307975; int _309501; _309501 = _238326_307975 - _309500; pconverge_308317 = _309501; goto l308316; l308316: ; converge_308317 = pconverge_308317; if (_308022) goto l308318; else goto l309498; l309498: ; pconverge_308320 = _308021; goto l308319; l308318: ; pconverge_308320 = _309022; goto l308319; l308319: ; converge_308320 = pconverge_308320; bool _308321; _308321 = _238325_307974 <= converge_308320; if (_308321) goto l308322; else goto l309497; l309497: ; pconverge_308324 = converge_308320; goto l308323; l308322: ; int _309494; _309494 = 1 + converge_308320; int _309495; _309495 = _309494 - _238325_307974; int _309496; _309496 = _238325_307974 - _309495; pconverge_308324 = _309496; goto l308323; l308323: ; converge_308324 = pconverge_308324; int _308325; _308325 = 2 + gid_y_308004; int _309451; _309451 = 0 - _308325; bool _308326; _308326 = _308325 < 0; int _309452; _309452 = _309451 - 1; if (_308326) goto l308327; else goto l309493; l309493: ; pconverge_308329 = _308325; goto l308328; l308327: ; pconverge_308329 = _309452; goto l308328; l308328: ; converge_308329 = pconverge_308329; bool _308330; _308330 = _238326_307975 <= converge_308329; if (_308330) goto l308331; else goto l309492; l309492: ; pconverge_308333 = converge_308329; goto l308332; l308331: ; int _309489; _309489 = 1 + converge_308329; int _309490; _309490 = _309489 - _238326_307975; int _309491; _309491 = _238326_307975 - _309490; pconverge_308333 = _309491; goto l308332; l308332: ; converge_308333 = pconverge_308333; if (_308041) goto l308334; else goto l309488; l309488: ; pconverge_308336 = _308040; goto l308335; l308334: ; pconverge_308336 = _309010; goto l308335; l308335: ; converge_308336 = pconverge_308336; bool _308337; _308337 = _238325_307974 <= converge_308336; if (_308337) goto l308338; else goto l309487; l309487: ; pconverge_308340 = converge_308336; goto l308339; l308338: ; int _309484; _309484 = 1 + converge_308336; int _309485; _309485 = _309484 - _238325_307974; int _309486; _309486 = _238325_307974 - _309485; pconverge_308340 = _309486; goto l308339; l308339: ; converge_308340 = pconverge_308340; if (_308326) goto l308341; else goto l309483; l309483: ; pconverge_308343 = _308325; goto l308342; l308341: ; pconverge_308343 = _309452; goto l308342; l308342: ; converge_308343 = pconverge_308343; bool _308344; _308344 = _238326_307975 <= converge_308343; if (_308344) goto l308345; else goto l309482; l309482: ; pconverge_308347 = converge_308343; goto l308346; l308345: ; int _309479; _309479 = 1 + converge_308343; int _309480; _309480 = _309479 - _238326_307975; int _309481; _309481 = _238326_307975 - _309480; pconverge_308347 = _309481; goto l308346; l308346: ; converge_308347 = pconverge_308347; if (_308056) goto l308348; else goto l309478; l309478: ; pconverge_308350 = _308013; goto l308349; l308348: ; pconverge_308350 = _308998; goto l308349; l308349: ; converge_308350 = pconverge_308350; bool _308351; _308351 = _238325_307974 <= converge_308350; if (_308351) goto l308352; else goto l309477; l309477: ; pconverge_308354 = converge_308350; goto l308353; l308352: ; int _309474; _309474 = 1 + converge_308350; int _309475; _309475 = _309474 - _238325_307974; int _309476; _309476 = _238325_307974 - _309475; pconverge_308354 = _309476; goto l308353; l308353: ; converge_308354 = pconverge_308354; if (_308326) goto l308355; else goto l309473; l309473: ; pconverge_308357 = _308325; goto l308356; l308355: ; pconverge_308357 = _309452; goto l308356; l308356: ; converge_308357 = pconverge_308357; bool _308358; _308358 = _238326_307975 <= converge_308357; if (_308358) goto l308359; else goto l309472; l309472: ; pconverge_308361 = converge_308357; goto l308360; l308359: ; int _309469; _309469 = 1 + converge_308357; int _309470; _309470 = _309469 - _238326_307975; int _309471; _309471 = _238326_307975 - _309470; pconverge_308361 = _309471; goto l308360; l308360: ; converge_308361 = pconverge_308361; if (_308072) goto l308362; else goto l309468; l309468: ; pconverge_308364 = _308071; goto l308363; l308362: ; pconverge_308364 = _308986; goto l308363; l308363: ; converge_308364 = pconverge_308364; bool _308365; _308365 = _238325_307974 <= converge_308364; if (_308365) goto l308366; else goto l309467; l309467: ; pconverge_308368 = converge_308364; goto l308367; l308366: ; int _309464; _309464 = 1 + converge_308364; int _309465; _309465 = _309464 - _238325_307974; int _309466; _309466 = _238325_307974 - _309465; pconverge_308368 = _309466; goto l308367; l308367: ; converge_308368 = pconverge_308368; if (_308326) goto l308369; else goto l309463; l309463: ; pconverge_308371 = _308325; goto l308370; l308369: ; pconverge_308371 = _309452; goto l308370; l308370: ; converge_308371 = pconverge_308371; bool _308372; _308372 = _238326_307975 <= converge_308371; if (_308372) goto l308373; else goto l309462; l309462: ; pconverge_308375 = converge_308371; goto l308374; l308373: ; int _309459; _309459 = 1 + converge_308371; int _309460; _309460 = _309459 - _238326_307975; int _309461; _309461 = _238326_307975 - _309460; pconverge_308375 = _309461; goto l308374; l308374: ; converge_308375 = pconverge_308375; if (_308088) goto l308376; else goto l309458; l309458: ; pconverge_308378 = _308087; goto l308377; l308376: ; pconverge_308378 = _308974; goto l308377; l308377: ; converge_308378 = pconverge_308378; bool _308379; _308379 = _238325_307974 <= converge_308378; if (_308379) goto l308380; else goto l309457; l309457: ; pconverge_308382 = converge_308378; goto l308381; l308380: ; int _309454; _309454 = 1 + converge_308378; int _309455; _309455 = _309454 - _238325_307974; int _309456; _309456 = _238325_307974 - _309455; pconverge_308382 = _309456; goto l308381; l308381: ; converge_308382 = pconverge_308382; if (_308326) goto l308383; else goto l309453; l309453: ; pconverge_308385 = _308325; goto l308384; l308383: ; pconverge_308385 = _309452; goto l308384; l308384: ; converge_308385 = pconverge_308385; bool _308386; _308386 = _238326_307975 <= converge_308385; if (_308386) goto l308387; else goto l309450; l309450: ; pconverge_308389 = converge_308385; goto l308388; l308387: ; int _309447; _309447 = 1 + converge_308385; int _309448; _309448 = _309447 - _238326_307975; int _309449; _309449 = _238326_307975 - _309448; pconverge_308389 = _309449; goto l308388; l308388: ; converge_308389 = pconverge_308389; int _309346; _309346 = converge_308275 * _238325_307974; int _309296; _309296 = converge_308132 * _238325_307974; int _309291; _309291 = converge_308118 * _238325_307974; int _309321; _309321 = converge_308203 * _238325_307974; int _309376; _309376 = converge_308361 * _238325_307974; int _309322; _309322 = _309321 + converge_308196; int _309341; _309341 = converge_308261 * _238325_307974; int _309351; _309351 = converge_308289 * _238325_307974; int _309366; _309366 = converge_308333 * _238325_307974; int _309331; _309331 = converge_308231 * _238325_307974; int _309306; _309306 = converge_308160 * _238325_307974; int _309352; _309352 = _309351 + converge_308282; int _309342; _309342 = _309341 + converge_308252; int _309316; _309316 = converge_308189 * _238325_307974; int _309347; _309347 = _309346 + converge_308268; int _309377; _309377 = _309376 + converge_308354; short* idx_309343; idx_309343 = _238327_307976 + _309342; int _309266; _309266 = converge_308038 * _238325_307974; short* idx_309378; idx_309378 = _238327_307976 + _309377; int _309367; _309367 = _309366 + converge_308324; int _309371; _309371 = converge_308347 * _238325_307974; int _309317; _309317 = _309316 + converge_308181; int _309361; _309361 = converge_308317 * _238325_307974; int _309276; _309276 = converge_308070 * _238325_307974; int _309386; _309386 = converge_308389 * _238325_307974; int _309292; _309292 = _309291 + converge_308109; int _309372; _309372 = _309371 + converge_308340; int _309286; _309286 = converge_308102 * _238325_307974; int _309307; _309307 = _309306 + converge_308153; int _309271; _309271 = converge_308055 * _238325_307974; int _309336; _309336 = converge_308245 * _238325_307974; int _309297; _309297 = _309296 + converge_308125; int _309326; _309326 = converge_308217 * _238325_307974; short* idx_309368; idx_309368 = _238327_307976 + _309367; int _309356; _309356 = converge_308303 * _238325_307974; int _309272; _309272 = _309271 + converge_308048; int _309277; _309277 = _309276 + converge_308063; int _309301; _309301 = converge_308146 * _238325_307974; int _309311; _309311 = converge_308174 * _238325_307974; int _309381; _309381 = converge_308375 * _238325_307974; int _309387; _309387 = _309386 + converge_308382; int _309281; _309281 = converge_308086 * _238325_307974; short* idx_309353; idx_309353 = _238327_307976 + _309352; short* idx_309323; idx_309323 = _238327_307976 + _309322; int _309332; _309332 = _309331 + converge_308224; short* idx_309348; idx_309348 = _238327_307976 + _309347; int _309267; _309267 = _309266 + converge_308029; short* idx_309318; idx_309318 = _238327_307976 + _309317; int _309362; _309362 = _309361 + converge_308310; short* idx_309293; idx_309293 = _238327_307976 + _309292; short* idx_309373; idx_309373 = _238327_307976 + _309372; int _309287; _309287 = _309286 + converge_308095; short* idx_309308; idx_309308 = _238327_307976 + _309307; int _309337; _309337 = _309336 + converge_308238; short* idx_309298; idx_309298 = _238327_307976 + _309297; int _309327; _309327 = _309326 + converge_308210; int _309357; _309357 = _309356 + converge_308296; short* idx_309273; idx_309273 = _238327_307976 + _309272; short* idx_309278; idx_309278 = _238327_307976 + _309277; int _309302; _309302 = _309301 + converge_308139; int _309312; _309312 = _309311 + converge_308167; int _309382; _309382 = _309381 + converge_308368; short* idx_309388; idx_309388 = _238327_307976 + _309387; int _309282; _309282 = _309281 + converge_308079; short* idx_309333; idx_309333 = _238327_307976 + _309332; short* idx_309268; idx_309268 = _238327_307976 + _309267; short* idx_309363; idx_309363 = _238327_307976 + _309362; short* idx_309288; idx_309288 = _238327_307976 + _309287; short* idx_309338; idx_309338 = _238327_307976 + _309337; short* idx_309328; idx_309328 = _238327_307976 + _309327; short* idx_309358; idx_309358 = _238327_307976 + _309357; short* idx_309303; idx_309303 = _238327_307976 + _309302; short* idx_309313; idx_309313 = _238327_307976 + _309312; short* idx_309383; idx_309383 = _238327_307976 + _309382; short* idx_309283; idx_309283 = _238327_307976 + _309282; short _309269; _309269 = *idx_309268; short _309394; _309394 = _309269; short _309274; _309274 = *idx_309273; short _309395; _309395 = _309274; short _309396; _309396 = _309394 + _309395; short _309279; _309279 = *idx_309278; short _309397; _309397 = _309279; short _309398; _309398 = _309396 + _309397; short _309284; _309284 = *idx_309283; short _309399; _309399 = _309284; short _309400; _309400 = _309398 + _309399; short _309289; _309289 = *idx_309288; short _309401; _309401 = _309289; short _309402; _309402 = _309400 + _309401; short _309294; _309294 = *idx_309293; short _309403; _309403 = _309294; short _309404; _309404 = _309402 + _309403; short _309299; _309299 = *idx_309298; short _309405; _309405 = _309299; short _309406; _309406 = _309404 + _309405; short _309304; _309304 = *idx_309303; short _309407; _309407 = _309304; short _309408; _309408 = _309406 + _309407; short _309309; _309309 = *idx_309308; short _309409; _309409 = _309309; short _309410; _309410 = _309408 + _309409; short _309314; _309314 = *idx_309313; short _309411; _309411 = _309314; short _309412; _309412 = _309410 + _309411; short _309319; _309319 = *idx_309318; short _309413; _309413 = _309319; short _309414; _309414 = _309412 + _309413; short _309324; _309324 = *idx_309323; short _309415; _309415 = _309324; short _309416; _309416 = _309414 + _309415; short _309329; _309329 = *idx_309328; short _309417; _309417 = _309329; short _309418; _309418 = _309416 + _309417; short _309334; _309334 = *idx_309333; short _309419; _309419 = _309334; short _309420; _309420 = _309418 + _309419; short _309339; _309339 = *idx_309338; short _309421; _309421 = _309339; short _309422; _309422 = _309420 + _309421; short _309344; _309344 = *idx_309343; short _309423; _309423 = _309344; short _309424; _309424 = _309422 + _309423; short _309349; _309349 = *idx_309348; short _309425; _309425 = _309349; short _309426; _309426 = _309424 + _309425; short _309354; _309354 = *idx_309353; short _309427; _309427 = _309354; short _309428; _309428 = _309426 + _309427; short _309359; _309359 = *idx_309358; short _309429; _309429 = _309359; short _309430; _309430 = _309428 + _309429; short _309364; _309364 = *idx_309363; short _309431; _309431 = _309364; short _309432; _309432 = _309430 + _309431; short _309369; _309369 = *idx_309368; short _309433; _309433 = _309369; short _309374; _309374 = *idx_309373; short _309434; _309434 = _309432 + _309433; short _309435; _309435 = _309374; short _309436; _309436 = _309434 + _309435; short _309379; _309379 = *idx_309378; short _309437; _309437 = _309379; short _309384; _309384 = *idx_309383; short _309438; _309438 = _309436 + _309437; short _309439; _309439 = _309384; short _309440; _309440 = _309438 + _309439; short _309389; _309389 = *idx_309388; short _309441; _309441 = _309389; short _309442; _309442 = _309440 + _309441; float _309443; _309443 = (float)_309442; float _309444; _309444 = _309443 / 2.500000e+01f; short _309445; _309445 = (short)_309444; *idx_309393 = _309445; goto l308390; l308390: ; plower_308394 = 1; pupper_308395 = 1; pstep_308396 = 1; goto l308392; l308392: ; lower_308394 = plower_308394; upper_308395 = pupper_308395; step_308396 = pstep_308396; bool _308397; _308397 = lower_308394 < upper_308395; if (_308397) goto l308398; else goto l309264; l309264: ; return ; l308398: ; _308401 = blockDim_y(); p_308401 = _308401; l308399: ; _308401 = p_308401; int _308402; _308402 = lower_308394 * _308401; int _308403; _308403 = gid_y_308004 + _308402; int _309080; _309080 = 0 - _308403; bool _308562; _308562 = _308403 < 0; int _308905; _308905 = _308403 * stride_308904; int _308404; _308404 = _308403 * stride_308010; int _309081; _309081 = _309080 - 1; int _308906; _308906 = _308905 + _308013; int _308405; _308405 = _308404 + _308013; short* idx_308907; idx_308907 = _238324_307973 + _308906; float* idx_308406; idx_308406 = _238329_307978 + _308405; float _308407; _308407 = *idx_308406; float _308408; _308408 = _308407; bool _308409; _308409 = threshold_308002 < _308408; if (_308409) goto l308410; else goto l309232; l309232: ; if (_308056) goto l309233; else goto l309263; l309263: ; pconverge_309235 = _308013; goto l309234; l309233: ; pconverge_309235 = _308998; goto l309234; l309234: ; converge_309235 = pconverge_309235; bool _309236; _309236 = _238325_307974 <= converge_309235; if (_309236) goto l309237; else goto l309262; l309262: ; pconverge_309239 = converge_309235; goto l309238; l309237: ; int _309259; _309259 = 1 + converge_309235; int _309260; _309260 = _309259 - _238325_307974; int _309261; _309261 = _238325_307974 - _309260; pconverge_309239 = _309261; goto l309238; l309238: ; converge_309239 = pconverge_309239; if (_308562) goto l309240; else goto l309258; l309258: ; pconverge_309242 = _308403; goto l309241; l309240: ; pconverge_309242 = _309081; goto l309241; l309241: ; converge_309242 = pconverge_309242; bool _309243; _309243 = _238326_307975 <= converge_309242; if (_309243) goto l309244; else goto l309257; l309257: ; pconverge_309246 = converge_309242; goto l309245; l309244: ; int _309254; _309254 = 1 + converge_309242; int _309255; _309255 = _309254 - _238326_307975; int _309256; _309256 = _238326_307975 - _309255; pconverge_309246 = _309256; goto l309245; l309245: ; converge_309246 = pconverge_309246; int _309247; _309247 = converge_309246 * _238325_307974; int _309248; _309248 = _309247 + converge_309239; short* idx_309249; idx_309249 = _238327_307976 + _309248; short _309250; _309250 = *idx_309249; short _309252; _309252 = _309250; *idx_308907 = _309252; goto l308770; l308410: ; if (_308022) goto l308411; else goto l309231; l309231: ; pconverge_308413 = _308021; goto l308412; l308411: ; pconverge_308413 = _309022; goto l308412; l308412: ; converge_308413 = pconverge_308413; bool _308414; _308414 = _238325_307974 <= converge_308413; if (_308414) goto l308415; else goto l309230; l309230: ; pconverge_308417 = converge_308413; goto l308416; l308415: ; int _309227; _309227 = 1 + converge_308413; int _309228; _309228 = _309227 - _238325_307974; int _309229; _309229 = _238325_307974 - _309228; pconverge_308417 = _309229; goto l308416; l308416: ; converge_308417 = pconverge_308417; int _308418; _308418 = -2 + _308403; int _309184; _309184 = 0 - _308418; bool _308419; _308419 = _308418 < 0; int _309185; _309185 = _309184 - 1; if (_308419) goto l308420; else goto l309226; l309226: ; pconverge_308422 = _308418; goto l308421; l308420: ; pconverge_308422 = _309185; goto l308421; l308421: ; converge_308422 = pconverge_308422; bool _308423; _308423 = _238326_307975 <= converge_308422; if (_308423) goto l308424; else goto l309225; l309225: ; pconverge_308426 = converge_308422; goto l308425; l308424: ; int _309222; _309222 = 1 + converge_308422; int _309223; _309223 = _309222 - _238326_307975; int _309224; _309224 = _238326_307975 - _309223; pconverge_308426 = _309224; goto l308425; l308425: ; converge_308426 = pconverge_308426; if (_308041) goto l308427; else goto l309221; l309221: ; pconverge_308429 = _308040; goto l308428; l308427: ; pconverge_308429 = _309010; goto l308428; l308428: ; converge_308429 = pconverge_308429; bool _308430; _308430 = _238325_307974 <= converge_308429; if (_308430) goto l308431; else goto l309220; l309220: ; pconverge_308433 = converge_308429; goto l308432; l308431: ; int _309217; _309217 = 1 + converge_308429; int _309218; _309218 = _309217 - _238325_307974; int _309219; _309219 = _238325_307974 - _309218; pconverge_308433 = _309219; goto l308432; l308432: ; converge_308433 = pconverge_308433; if (_308419) goto l308434; else goto l309216; l309216: ; pconverge_308436 = _308418; goto l308435; l308434: ; pconverge_308436 = _309185; goto l308435; l308435: ; converge_308436 = pconverge_308436; bool _308437; _308437 = _238326_307975 <= converge_308436; if (_308437) goto l308438; else goto l309215; l309215: ; pconverge_308440 = converge_308436; goto l308439; l308438: ; int _309212; _309212 = 1 + converge_308436; int _309213; _309213 = _309212 - _238326_307975; int _309214; _309214 = _238326_307975 - _309213; pconverge_308440 = _309214; goto l308439; l308439: ; converge_308440 = pconverge_308440; if (_308056) goto l308441; else goto l309211; l309211: ; pconverge_308443 = _308013; goto l308442; l308441: ; pconverge_308443 = _308998; goto l308442; l308442: ; converge_308443 = pconverge_308443; bool _308444; _308444 = _238325_307974 <= converge_308443; if (_308444) goto l308445; else goto l309210; l309210: ; pconverge_308447 = converge_308443; goto l308446; l308445: ; int _309207; _309207 = 1 + converge_308443; int _309208; _309208 = _309207 - _238325_307974; int _309209; _309209 = _238325_307974 - _309208; pconverge_308447 = _309209; goto l308446; l308446: ; converge_308447 = pconverge_308447; if (_308419) goto l308448; else goto l309206; l309206: ; pconverge_308450 = _308418; goto l308449; l308448: ; pconverge_308450 = _309185; goto l308449; l308449: ; converge_308450 = pconverge_308450; bool _308451; _308451 = _238326_307975 <= converge_308450; if (_308451) goto l308452; else goto l309205; l309205: ; pconverge_308454 = converge_308450; goto l308453; l308452: ; int _309202; _309202 = 1 + converge_308450; int _309203; _309203 = _309202 - _238326_307975; int _309204; _309204 = _238326_307975 - _309203; pconverge_308454 = _309204; goto l308453; l308453: ; converge_308454 = pconverge_308454; if (_308072) goto l308455; else goto l309201; l309201: ; pconverge_308457 = _308071; goto l308456; l308455: ; pconverge_308457 = _308986; goto l308456; l308456: ; converge_308457 = pconverge_308457; bool _308458; _308458 = _238325_307974 <= converge_308457; if (_308458) goto l308459; else goto l309200; l309200: ; pconverge_308461 = converge_308457; goto l308460; l308459: ; int _309197; _309197 = 1 + converge_308457; int _309198; _309198 = _309197 - _238325_307974; int _309199; _309199 = _238325_307974 - _309198; pconverge_308461 = _309199; goto l308460; l308460: ; converge_308461 = pconverge_308461; if (_308419) goto l308462; else goto l309196; l309196: ; pconverge_308464 = _308418; goto l308463; l308462: ; pconverge_308464 = _309185; goto l308463; l308463: ; converge_308464 = pconverge_308464; bool _308465; _308465 = _238326_307975 <= converge_308464; if (_308465) goto l308466; else goto l309195; l309195: ; pconverge_308468 = converge_308464; goto l308467; l308466: ; int _309192; _309192 = 1 + converge_308464; int _309193; _309193 = _309192 - _238326_307975; int _309194; _309194 = _238326_307975 - _309193; pconverge_308468 = _309194; goto l308467; l308467: ; converge_308468 = pconverge_308468; if (_308088) goto l308469; else goto l309191; l309191: ; pconverge_308471 = _308087; goto l308470; l308469: ; pconverge_308471 = _308974; goto l308470; l308470: ; converge_308471 = pconverge_308471; bool _308472; _308472 = _238325_307974 <= converge_308471; if (_308472) goto l308473; else goto l309190; l309190: ; pconverge_308475 = converge_308471; goto l308474; l308473: ; int _309187; _309187 = 1 + converge_308471; int _309188; _309188 = _309187 - _238325_307974; int _309189; _309189 = _238325_307974 - _309188; pconverge_308475 = _309189; goto l308474; l308474: ; converge_308475 = pconverge_308475; if (_308419) goto l308476; else goto l309186; l309186: ; pconverge_308478 = _308418; goto l308477; l308476: ; pconverge_308478 = _309185; goto l308477; l308477: ; converge_308478 = pconverge_308478; bool _308479; _308479 = _238326_307975 <= converge_308478; if (_308479) goto l308480; else goto l309183; l309183: ; pconverge_308482 = converge_308478; goto l308481; l308480: ; int _309180; _309180 = 1 + converge_308478; int _309181; _309181 = _309180 - _238326_307975; int _309182; _309182 = _238326_307975 - _309181; pconverge_308482 = _309182; goto l308481; l308481: ; converge_308482 = pconverge_308482; if (_308022) goto l308483; else goto l309179; l309179: ; pconverge_308485 = _308021; goto l308484; l308483: ; pconverge_308485 = _309022; goto l308484; l308484: ; converge_308485 = pconverge_308485; bool _308486; _308486 = _238325_307974 <= converge_308485; if (_308486) goto l308487; else goto l309178; l309178: ; pconverge_308489 = converge_308485; goto l308488; l308487: ; int _309175; _309175 = 1 + converge_308485; int _309176; _309176 = _309175 - _238325_307974; int _309177; _309177 = _238325_307974 - _309176; pconverge_308489 = _309177; goto l308488; l308488: ; converge_308489 = pconverge_308489; int _308490; _308490 = -1 + _308403; bool _308491; _308491 = _308490 < 0; int _309132; _309132 = 0 - _308490; int _309133; _309133 = _309132 - 1; if (_308491) goto l308492; else goto l309174; l309174: ; pconverge_308494 = _308490; goto l308493; l308492: ; pconverge_308494 = _309133; goto l308493; l308493: ; converge_308494 = pconverge_308494; bool _308495; _308495 = _238326_307975 <= converge_308494; if (_308495) goto l308496; else goto l309173; l309173: ; pconverge_308498 = converge_308494; goto l308497; l308496: ; int _309170; _309170 = 1 + converge_308494; int _309171; _309171 = _309170 - _238326_307975; int _309172; _309172 = _238326_307975 - _309171; pconverge_308498 = _309172; goto l308497; l308497: ; converge_308498 = pconverge_308498; if (_308041) goto l308499; else goto l309169; l309169: ; pconverge_308501 = _308040; goto l308500; l308499: ; pconverge_308501 = _309010; goto l308500; l308500: ; converge_308501 = pconverge_308501; bool _308502; _308502 = _238325_307974 <= converge_308501; if (_308502) goto l308503; else goto l309168; l309168: ; pconverge_308505 = converge_308501; goto l308504; l308503: ; int _309165; _309165 = 1 + converge_308501; int _309166; _309166 = _309165 - _238325_307974; int _309167; _309167 = _238325_307974 - _309166; pconverge_308505 = _309167; goto l308504; l308504: ; converge_308505 = pconverge_308505; if (_308491) goto l308506; else goto l309164; l309164: ; pconverge_308508 = _308490; goto l308507; l308506: ; pconverge_308508 = _309133; goto l308507; l308507: ; converge_308508 = pconverge_308508; bool _308509; _308509 = _238326_307975 <= converge_308508; if (_308509) goto l308510; else goto l309163; l309163: ; pconverge_308512 = converge_308508; goto l308511; l308510: ; int _309160; _309160 = 1 + converge_308508; int _309161; _309161 = _309160 - _238326_307975; int _309162; _309162 = _238326_307975 - _309161; pconverge_308512 = _309162; goto l308511; l308511: ; converge_308512 = pconverge_308512; if (_308056) goto l308513; else goto l309159; l309159: ; pconverge_308515 = _308013; goto l308514; l308513: ; pconverge_308515 = _308998; goto l308514; l308514: ; converge_308515 = pconverge_308515; bool _308516; _308516 = _238325_307974 <= converge_308515; if (_308516) goto l308517; else goto l309158; l309158: ; pconverge_308519 = converge_308515; goto l308518; l308517: ; int _309155; _309155 = 1 + converge_308515; int _309156; _309156 = _309155 - _238325_307974; int _309157; _309157 = _238325_307974 - _309156; pconverge_308519 = _309157; goto l308518; l308518: ; converge_308519 = pconverge_308519; if (_308491) goto l308520; else goto l309154; l309154: ; pconverge_308522 = _308490; goto l308521; l308520: ; pconverge_308522 = _309133; goto l308521; l308521: ; converge_308522 = pconverge_308522; bool _308523; _308523 = _238326_307975 <= converge_308522; if (_308523) goto l308524; else goto l309153; l309153: ; pconverge_308526 = converge_308522; goto l308525; l308524: ; int _309150; _309150 = 1 + converge_308522; int _309151; _309151 = _309150 - _238326_307975; int _309152; _309152 = _238326_307975 - _309151; pconverge_308526 = _309152; goto l308525; l308525: ; converge_308526 = pconverge_308526; if (_308072) goto l308527; else goto l309149; l309149: ; pconverge_308529 = _308071; goto l308528; l308527: ; pconverge_308529 = _308986; goto l308528; l308528: ; converge_308529 = pconverge_308529; bool _308530; _308530 = _238325_307974 <= converge_308529; if (_308530) goto l308531; else goto l309148; l309148: ; pconverge_308533 = converge_308529; goto l308532; l308531: ; int _309145; _309145 = 1 + converge_308529; int _309146; _309146 = _309145 - _238325_307974; int _309147; _309147 = _238325_307974 - _309146; pconverge_308533 = _309147; goto l308532; l308532: ; converge_308533 = pconverge_308533; if (_308491) goto l308534; else goto l309144; l309144: ; pconverge_308536 = _308490; goto l308535; l308534: ; pconverge_308536 = _309133; goto l308535; l308535: ; converge_308536 = pconverge_308536; bool _308537; _308537 = _238326_307975 <= converge_308536; if (_308537) goto l308538; else goto l309143; l309143: ; pconverge_308540 = converge_308536; goto l308539; l308538: ; int _309140; _309140 = 1 + converge_308536; int _309141; _309141 = _309140 - _238326_307975; int _309142; _309142 = _238326_307975 - _309141; pconverge_308540 = _309142; goto l308539; l308539: ; converge_308540 = pconverge_308540; if (_308088) goto l308541; else goto l309139; l309139: ; pconverge_308543 = _308087; goto l308542; l308541: ; pconverge_308543 = _308974; goto l308542; l308542: ; converge_308543 = pconverge_308543; bool _308544; _308544 = _238325_307974 <= converge_308543; if (_308544) goto l308545; else goto l309138; l309138: ; pconverge_308547 = converge_308543; goto l308546; l308545: ; int _309135; _309135 = 1 + converge_308543; int _309136; _309136 = _309135 - _238325_307974; int _309137; _309137 = _238325_307974 - _309136; pconverge_308547 = _309137; goto l308546; l308546: ; converge_308547 = pconverge_308547; if (_308491) goto l308548; else goto l309134; l309134: ; pconverge_308550 = _308490; goto l308549; l308548: ; pconverge_308550 = _309133; goto l308549; l308549: ; converge_308550 = pconverge_308550; bool _308551; _308551 = _238326_307975 <= converge_308550; if (_308551) goto l308552; else goto l309131; l309131: ; pconverge_308554 = converge_308550; goto l308553; l308552: ; int _309128; _309128 = 1 + converge_308550; int _309129; _309129 = _309128 - _238326_307975; int _309130; _309130 = _238326_307975 - _309129; pconverge_308554 = _309130; goto l308553; l308553: ; converge_308554 = pconverge_308554; if (_308022) goto l308555; else goto l309127; l309127: ; pconverge_308557 = _308021; goto l308556; l308555: ; pconverge_308557 = _309022; goto l308556; l308556: ; converge_308557 = pconverge_308557; bool _308558; _308558 = _238325_307974 <= converge_308557; if (_308558) goto l308559; else goto l309126; l309126: ; pconverge_308561 = converge_308557; goto l308560; l308559: ; int _309123; _309123 = 1 + converge_308557; int _309124; _309124 = _309123 - _238325_307974; int _309125; _309125 = _238325_307974 - _309124; pconverge_308561 = _309125; goto l308560; l308560: ; converge_308561 = pconverge_308561; if (_308562) goto l308563; else goto l309122; l309122: ; pconverge_308565 = _308403; goto l308564; l308563: ; pconverge_308565 = _309081; goto l308564; l308564: ; converge_308565 = pconverge_308565; bool _308566; _308566 = _238326_307975 <= converge_308565; if (_308566) goto l308567; else goto l309121; l309121: ; pconverge_308569 = converge_308565; goto l308568; l308567: ; int _309118; _309118 = 1 + converge_308565; int _309119; _309119 = _309118 - _238326_307975; int _309120; _309120 = _238326_307975 - _309119; pconverge_308569 = _309120; goto l308568; l308568: ; converge_308569 = pconverge_308569; if (_308041) goto l308570; else goto l309117; l309117: ; pconverge_308572 = _308040; goto l308571; l308570: ; pconverge_308572 = _309010; goto l308571; l308571: ; converge_308572 = pconverge_308572; bool _308573; _308573 = _238325_307974 <= converge_308572; if (_308573) goto l308574; else goto l309116; l309116: ; pconverge_308576 = converge_308572; goto l308575; l308574: ; int _309113; _309113 = 1 + converge_308572; int _309114; _309114 = _309113 - _238325_307974; int _309115; _309115 = _238325_307974 - _309114; pconverge_308576 = _309115; goto l308575; l308575: ; converge_308576 = pconverge_308576; if (_308562) goto l308577; else goto l309112; l309112: ; pconverge_308579 = _308403; goto l308578; l308577: ; pconverge_308579 = _309081; goto l308578; l308578: ; converge_308579 = pconverge_308579; bool _308580; _308580 = _238326_307975 <= converge_308579; if (_308580) goto l308581; else goto l309111; l309111: ; pconverge_308583 = converge_308579; goto l308582; l308581: ; int _309108; _309108 = 1 + converge_308579; int _309109; _309109 = _309108 - _238326_307975; int _309110; _309110 = _238326_307975 - _309109; pconverge_308583 = _309110; goto l308582; l308582: ; converge_308583 = pconverge_308583; if (_308056) goto l308584; else goto l309107; l309107: ; pconverge_308586 = _308013; goto l308585; l308584: ; pconverge_308586 = _308998; goto l308585; l308585: ; converge_308586 = pconverge_308586; bool _308587; _308587 = _238325_307974 <= converge_308586; if (_308587) goto l308588; else goto l309106; l309106: ; pconverge_308590 = converge_308586; goto l308589; l308588: ; int _309103; _309103 = 1 + converge_308586; int _309104; _309104 = _309103 - _238325_307974; int _309105; _309105 = _238325_307974 - _309104; pconverge_308590 = _309105; goto l308589; l308589: ; converge_308590 = pconverge_308590; if (_308562) goto l308591; else goto l309102; l309102: ; pconverge_308593 = _308403; goto l308592; l308591: ; pconverge_308593 = _309081; goto l308592; l308592: ; converge_308593 = pconverge_308593; bool _308594; _308594 = _238326_307975 <= converge_308593; if (_308594) goto l308595; else goto l309101; l309101: ; pconverge_308597 = converge_308593; goto l308596; l308595: ; int _309098; _309098 = 1 + converge_308593; int _309099; _309099 = _309098 - _238326_307975; int _309100; _309100 = _238326_307975 - _309099; pconverge_308597 = _309100; goto l308596; l308596: ; converge_308597 = pconverge_308597; if (_308072) goto l308598; else goto l309097; l309097: ; pconverge_308600 = _308071; goto l308599; l308598: ; pconverge_308600 = _308986; goto l308599; l308599: ; converge_308600 = pconverge_308600; bool _308601; _308601 = _238325_307974 <= converge_308600; if (_308601) goto l308602; else goto l309096; l309096: ; pconverge_308604 = converge_308600; goto l308603; l308602: ; int _309093; _309093 = 1 + converge_308600; int _309094; _309094 = _309093 - _238325_307974; int _309095; _309095 = _238325_307974 - _309094; pconverge_308604 = _309095; goto l308603; l308603: ; converge_308604 = pconverge_308604; if (_308562) goto l308605; else goto l309092; l309092: ; pconverge_308607 = _308403; goto l308606; l308605: ; pconverge_308607 = _309081; goto l308606; l308606: ; converge_308607 = pconverge_308607; bool _308608; _308608 = _238326_307975 <= converge_308607; if (_308608) goto l308609; else goto l309091; l309091: ; pconverge_308611 = converge_308607; goto l308610; l308609: ; int _309088; _309088 = 1 + converge_308607; int _309089; _309089 = _309088 - _238326_307975; int _309090; _309090 = _238326_307975 - _309089; pconverge_308611 = _309090; goto l308610; l308610: ; converge_308611 = pconverge_308611; if (_308088) goto l308612; else goto l309087; l309087: ; pconverge_308614 = _308087; goto l308613; l308612: ; pconverge_308614 = _308974; goto l308613; l308613: ; converge_308614 = pconverge_308614; bool _308615; _308615 = _238325_307974 <= converge_308614; if (_308615) goto l308616; else goto l309086; l309086: ; pconverge_308618 = converge_308614; goto l308617; l308616: ; int _309083; _309083 = 1 + converge_308614; int _309084; _309084 = _309083 - _238325_307974; int _309085; _309085 = _238325_307974 - _309084; pconverge_308618 = _309085; goto l308617; l308617: ; converge_308618 = pconverge_308618; if (_308562) goto l308619; else goto l309082; l309082: ; pconverge_308621 = _308403; goto l308620; l308619: ; pconverge_308621 = _309081; goto l308620; l308620: ; converge_308621 = pconverge_308621; bool _308622; _308622 = _238326_307975 <= converge_308621; if (_308622) goto l308623; else goto l309079; l309079: ; pconverge_308625 = converge_308621; goto l308624; l308623: ; int _309076; _309076 = 1 + converge_308621; int _309077; _309077 = _309076 - _238326_307975; int _309078; _309078 = _238326_307975 - _309077; pconverge_308625 = _309078; goto l308624; l308624: ; converge_308625 = pconverge_308625; if (_308022) goto l308626; else goto l309075; l309075: ; pconverge_308628 = _308021; goto l308627; l308626: ; pconverge_308628 = _309022; goto l308627; l308627: ; converge_308628 = pconverge_308628; bool _308629; _308629 = _238325_307974 <= converge_308628; if (_308629) goto l308630; else goto l309074; l309074: ; pconverge_308632 = converge_308628; goto l308631; l308630: ; int _309071; _309071 = 1 + converge_308628; int _309072; _309072 = _309071 - _238325_307974; int _309073; _309073 = _238325_307974 - _309072; pconverge_308632 = _309073; goto l308631; l308631: ; converge_308632 = pconverge_308632; int _308633; _308633 = 1 + _308403; int _309028; _309028 = 0 - _308633; bool _308634; _308634 = _308633 < 0; int _309029; _309029 = _309028 - 1; if (_308634) goto l308635; else goto l309070; l309070: ; pconverge_308637 = _308633; goto l308636; l308635: ; pconverge_308637 = _309029; goto l308636; l308636: ; converge_308637 = pconverge_308637; bool _308638; _308638 = _238326_307975 <= converge_308637; if (_308638) goto l308639; else goto l309069; l309069: ; pconverge_308641 = converge_308637; goto l308640; l308639: ; int _309066; _309066 = 1 + converge_308637; int _309067; _309067 = _309066 - _238326_307975; int _309068; _309068 = _238326_307975 - _309067; pconverge_308641 = _309068; goto l308640; l308640: ; converge_308641 = pconverge_308641; if (_308041) goto l308642; else goto l309065; l309065: ; pconverge_308644 = _308040; goto l308643; l308642: ; pconverge_308644 = _309010; goto l308643; l308643: ; converge_308644 = pconverge_308644; bool _308645; _308645 = _238325_307974 <= converge_308644; if (_308645) goto l308646; else goto l309064; l309064: ; pconverge_308648 = converge_308644; goto l308647; l308646: ; int _309061; _309061 = 1 + converge_308644; int _309062; _309062 = _309061 - _238325_307974; int _309063; _309063 = _238325_307974 - _309062; pconverge_308648 = _309063; goto l308647; l308647: ; converge_308648 = pconverge_308648; if (_308634) goto l308649; else goto l309060; l309060: ; pconverge_308651 = _308633; goto l308650; l308649: ; pconverge_308651 = _309029; goto l308650; l308650: ; converge_308651 = pconverge_308651; bool _308652; _308652 = _238326_307975 <= converge_308651; if (_308652) goto l308653; else goto l309059; l309059: ; pconverge_308655 = converge_308651; goto l308654; l308653: ; int _309056; _309056 = 1 + converge_308651; int _309057; _309057 = _309056 - _238326_307975; int _309058; _309058 = _238326_307975 - _309057; pconverge_308655 = _309058; goto l308654; l308654: ; converge_308655 = pconverge_308655; if (_308056) goto l308656; else goto l309055; l309055: ; pconverge_308658 = _308013; goto l308657; l308656: ; pconverge_308658 = _308998; goto l308657; l308657: ; converge_308658 = pconverge_308658; bool _308659; _308659 = _238325_307974 <= converge_308658; if (_308659) goto l308660; else goto l309054; l309054: ; pconverge_308662 = converge_308658; goto l308661; l308660: ; int _309051; _309051 = 1 + converge_308658; int _309052; _309052 = _309051 - _238325_307974; int _309053; _309053 = _238325_307974 - _309052; pconverge_308662 = _309053; goto l308661; l308661: ; converge_308662 = pconverge_308662; if (_308634) goto l308663; else goto l309050; l309050: ; pconverge_308665 = _308633; goto l308664; l308663: ; pconverge_308665 = _309029; goto l308664; l308664: ; converge_308665 = pconverge_308665; bool _308666; _308666 = _238326_307975 <= converge_308665; if (_308666) goto l308667; else goto l309049; l309049: ; pconverge_308669 = converge_308665; goto l308668; l308667: ; int _309046; _309046 = 1 + converge_308665; int _309047; _309047 = _309046 - _238326_307975; int _309048; _309048 = _238326_307975 - _309047; pconverge_308669 = _309048; goto l308668; l308668: ; converge_308669 = pconverge_308669; if (_308072) goto l308670; else goto l309045; l309045: ; pconverge_308672 = _308071; goto l308671; l308670: ; pconverge_308672 = _308986; goto l308671; l308671: ; converge_308672 = pconverge_308672; bool _308673; _308673 = _238325_307974 <= converge_308672; if (_308673) goto l308674; else goto l309044; l309044: ; pconverge_308676 = converge_308672; goto l308675; l308674: ; int _309041; _309041 = 1 + converge_308672; int _309042; _309042 = _309041 - _238325_307974; int _309043; _309043 = _238325_307974 - _309042; pconverge_308676 = _309043; goto l308675; l308675: ; converge_308676 = pconverge_308676; if (_308634) goto l308677; else goto l309040; l309040: ; pconverge_308679 = _308633; goto l308678; l308677: ; pconverge_308679 = _309029; goto l308678; l308678: ; converge_308679 = pconverge_308679; bool _308680; _308680 = _238326_307975 <= converge_308679; if (_308680) goto l308681; else goto l309039; l309039: ; pconverge_308683 = converge_308679; goto l308682; l308681: ; int _309036; _309036 = 1 + converge_308679; int _309037; _309037 = _309036 - _238326_307975; int _309038; _309038 = _238326_307975 - _309037; pconverge_308683 = _309038; goto l308682; l308682: ; converge_308683 = pconverge_308683; if (_308088) goto l308684; else goto l309035; l309035: ; pconverge_308686 = _308087; goto l308685; l308684: ; pconverge_308686 = _308974; goto l308685; l308685: ; converge_308686 = pconverge_308686; bool _308687; _308687 = _238325_307974 <= converge_308686; if (_308687) goto l308688; else goto l309034; l309034: ; pconverge_308690 = converge_308686; goto l308689; l308688: ; int _309031; _309031 = 1 + converge_308686; int _309032; _309032 = _309031 - _238325_307974; int _309033; _309033 = _238325_307974 - _309032; pconverge_308690 = _309033; goto l308689; l308689: ; converge_308690 = pconverge_308690; if (_308634) goto l308691; else goto l309030; l309030: ; pconverge_308693 = _308633; goto l308692; l308691: ; pconverge_308693 = _309029; goto l308692; l308692: ; converge_308693 = pconverge_308693; bool _308694; _308694 = _238326_307975 <= converge_308693; if (_308694) goto l308695; else goto l309027; l309027: ; pconverge_308697 = converge_308693; goto l308696; l308695: ; int _309024; _309024 = 1 + converge_308693; int _309025; _309025 = _309024 - _238326_307975; int _309026; _309026 = _238326_307975 - _309025; pconverge_308697 = _309026; goto l308696; l308696: ; converge_308697 = pconverge_308697; if (_308022) goto l308698; else goto l309023; l309023: ; pconverge_308700 = _308021; goto l308699; l308698: ; pconverge_308700 = _309022; goto l308699; l308699: ; converge_308700 = pconverge_308700; bool _308701; _308701 = _238325_307974 <= converge_308700; if (_308701) goto l308702; else goto l309020; l309020: ; pconverge_308704 = converge_308700; goto l308703; l308702: ; int _309017; _309017 = 1 + converge_308700; int _309018; _309018 = _309017 - _238325_307974; int _309019; _309019 = _238325_307974 - _309018; pconverge_308704 = _309019; goto l308703; l308703: ; converge_308704 = pconverge_308704; int _308705; _308705 = 2 + _308403; bool _308706; _308706 = _308705 < 0; int _308966; _308966 = 0 - _308705; int _308967; _308967 = _308966 - 1; if (_308706) goto l308707; else goto l309016; l309016: ; pconverge_308709 = _308705; goto l308708; l308707: ; pconverge_308709 = _308967; goto l308708; l308708: ; converge_308709 = pconverge_308709; bool _308710; _308710 = _238326_307975 <= converge_308709; if (_308710) goto l308711; else goto l309015; l309015: ; pconverge_308713 = converge_308709; goto l308712; l308711: ; int _309012; _309012 = 1 + converge_308709; int _309013; _309013 = _309012 - _238326_307975; int _309014; _309014 = _238326_307975 - _309013; pconverge_308713 = _309014; goto l308712; l308712: ; converge_308713 = pconverge_308713; if (_308041) goto l308714; else goto l309011; l309011: ; pconverge_308716 = _308040; goto l308715; l308714: ; pconverge_308716 = _309010; goto l308715; l308715: ; converge_308716 = pconverge_308716; bool _308717; _308717 = _238325_307974 <= converge_308716; if (_308717) goto l308718; else goto l309008; l309008: ; pconverge_308720 = converge_308716; goto l308719; l308718: ; int _309005; _309005 = 1 + converge_308716; int _309006; _309006 = _309005 - _238325_307974; int _309007; _309007 = _238325_307974 - _309006; pconverge_308720 = _309007; goto l308719; l308719: ; converge_308720 = pconverge_308720; if (_308706) goto l308721; else goto l309004; l309004: ; pconverge_308723 = _308705; goto l308722; l308721: ; pconverge_308723 = _308967; goto l308722; l308722: ; converge_308723 = pconverge_308723; bool _308724; _308724 = _238326_307975 <= converge_308723; if (_308724) goto l308725; else goto l309003; l309003: ; pconverge_308727 = converge_308723; goto l308726; l308725: ; int _309000; _309000 = 1 + converge_308723; int _309001; _309001 = _309000 - _238326_307975; int _309002; _309002 = _238326_307975 - _309001; pconverge_308727 = _309002; goto l308726; l308726: ; converge_308727 = pconverge_308727; if (_308056) goto l308728; else goto l308999; l308999: ; pconverge_308730 = _308013; goto l308729; l308728: ; pconverge_308730 = _308998; goto l308729; l308729: ; converge_308730 = pconverge_308730; bool _308731; _308731 = _238325_307974 <= converge_308730; if (_308731) goto l308732; else goto l308996; l308996: ; pconverge_308734 = converge_308730; goto l308733; l308732: ; int _308993; _308993 = 1 + converge_308730; int _308994; _308994 = _308993 - _238325_307974; int _308995; _308995 = _238325_307974 - _308994; pconverge_308734 = _308995; goto l308733; l308733: ; converge_308734 = pconverge_308734; if (_308706) goto l308735; else goto l308992; l308992: ; pconverge_308737 = _308705; goto l308736; l308735: ; pconverge_308737 = _308967; goto l308736; l308736: ; converge_308737 = pconverge_308737; bool _308738; _308738 = _238326_307975 <= converge_308737; if (_308738) goto l308739; else goto l308991; l308991: ; pconverge_308741 = converge_308737; goto l308740; l308739: ; int _308988; _308988 = 1 + converge_308737; int _308989; _308989 = _308988 - _238326_307975; int _308990; _308990 = _238326_307975 - _308989; pconverge_308741 = _308990; goto l308740; l308740: ; converge_308741 = pconverge_308741; if (_308072) goto l308742; else goto l308987; l308987: ; pconverge_308744 = _308071; goto l308743; l308742: ; pconverge_308744 = _308986; goto l308743; l308743: ; converge_308744 = pconverge_308744; bool _308745; _308745 = _238325_307974 <= converge_308744; if (_308745) goto l308746; else goto l308984; l308984: ; pconverge_308748 = converge_308744; goto l308747; l308746: ; int _308981; _308981 = 1 + converge_308744; int _308982; _308982 = _308981 - _238325_307974; int _308983; _308983 = _238325_307974 - _308982; pconverge_308748 = _308983; goto l308747; l308747: ; converge_308748 = pconverge_308748; if (_308706) goto l308749; else goto l308980; l308980: ; pconverge_308751 = _308705; goto l308750; l308749: ; pconverge_308751 = _308967; goto l308750; l308750: ; converge_308751 = pconverge_308751; bool _308752; _308752 = _238326_307975 <= converge_308751; if (_308752) goto l308753; else goto l308979; l308979: ; pconverge_308755 = converge_308751; goto l308754; l308753: ; int _308976; _308976 = 1 + converge_308751; int _308977; _308977 = _308976 - _238326_307975; int _308978; _308978 = _238326_307975 - _308977; pconverge_308755 = _308978; goto l308754; l308754: ; converge_308755 = pconverge_308755; if (_308088) goto l308756; else goto l308975; l308975: ; pconverge_308758 = _308087; goto l308757; l308756: ; pconverge_308758 = _308974; goto l308757; l308757: ; converge_308758 = pconverge_308758; bool _308759; _308759 = _238325_307974 <= converge_308758; if (_308759) goto l308760; else goto l308972; l308972: ; pconverge_308762 = converge_308758; goto l308761; l308760: ; int _308969; _308969 = 1 + converge_308758; int _308970; _308970 = _308969 - _238325_307974; int _308971; _308971 = _238325_307974 - _308970; pconverge_308762 = _308971; goto l308761; l308761: ; converge_308762 = pconverge_308762; if (_308706) goto l308763; else goto l308968; l308968: ; pconverge_308765 = _308705; goto l308764; l308763: ; pconverge_308765 = _308967; goto l308764; l308764: ; converge_308765 = pconverge_308765; bool _308766; _308766 = _238326_307975 <= converge_308765; if (_308766) goto l308767; else goto l308965; l308965: ; pconverge_308769 = converge_308765; goto l308768; l308767: ; int _308962; _308962 = 1 + converge_308765; int _308963; _308963 = _308962 - _238326_307975; int _308964; _308964 = _238326_307975 - _308963; pconverge_308769 = _308964; goto l308768; l308768: ; converge_308769 = pconverge_308769; int _308879; _308879 = converge_308727 * _238325_307974; int _308829; _308829 = converge_308583 * _238325_307974; int _308834; _308834 = converge_308597 * _238325_307974; int _308784; _308784 = converge_308454 * _238325_307974; int _308859; _308859 = converge_308669 * _238325_307974; int _308884; _308884 = converge_308741 * _238325_307974; int _308785; _308785 = _308784 + converge_308447; int _308854; _308854 = converge_308655 * _238325_307974; int _308864; _308864 = converge_308683 * _238325_307974; int _308849; _308849 = converge_308641 * _238325_307974; int _308850; _308850 = _308849 + converge_308632; int _308794; _308794 = converge_308482 * _238325_307974; int _308880; _308880 = _308879 + converge_308720; int _308894; _308894 = converge_308769 * _238325_307974; int _308774; _308774 = converge_308426 * _238325_307974; int _308889; _308889 = converge_308755 * _238325_307974; int _308869; _308869 = converge_308697 * _238325_307974; int _308855; _308855 = _308854 + converge_308648; int _308779; _308779 = converge_308440 * _238325_307974; int _308839; _308839 = converge_308611 * _238325_307974; int _308814; _308814 = converge_308540 * _238325_307974; int _308799; _308799 = converge_308498 * _238325_307974; int _308885; _308885 = _308884 + converge_308734; short* idx_308786; idx_308786 = _238327_307976 + _308785; int _308795; _308795 = _308794 + converge_308475; int _308840; _308840 = _308839 + converge_308604; int _308830; _308830 = _308829 + converge_308576; int _308804; _308804 = converge_308512 * _238325_307974; int _308815; _308815 = _308814 + converge_308533; int _308865; _308865 = _308864 + converge_308676; short* idx_308816; idx_308816 = _238327_307976 + _308815; int _308809; _308809 = converge_308526 * _238325_307974; int _308844; _308844 = converge_308625 * _238325_307974; short* idx_308881; idx_308881 = _238327_307976 + _308880; int _308874; _308874 = converge_308713 * _238325_307974; int _308824; _308824 = converge_308569 * _238325_307974; int _308819; _308819 = converge_308554 * _238325_307974; int _308780; _308780 = _308779 + converge_308433; int _308789; _308789 = converge_308468 * _238325_307974; int _308835; _308835 = _308834 + converge_308590; short* idx_308841; idx_308841 = _238327_307976 + _308840; int _308860; _308860 = _308859 + converge_308662; short* idx_308851; idx_308851 = _238327_307976 + _308850; int _308895; _308895 = _308894 + converge_308762; int _308775; _308775 = _308774 + converge_308417; int _308890; _308890 = _308889 + converge_308748; int _308870; _308870 = _308869 + converge_308690; short* idx_308856; idx_308856 = _238327_307976 + _308855; int _308800; _308800 = _308799 + converge_308489; short* idx_308886; idx_308886 = _238327_307976 + _308885; short* idx_308796; idx_308796 = _238327_307976 + _308795; short* idx_308831; idx_308831 = _238327_307976 + _308830; int _308805; _308805 = _308804 + converge_308505; short* idx_308866; idx_308866 = _238327_307976 + _308865; int _308810; _308810 = _308809 + converge_308519; int _308845; _308845 = _308844 + converge_308618; int _308875; _308875 = _308874 + converge_308704; int _308825; _308825 = _308824 + converge_308561; int _308820; _308820 = _308819 + converge_308547; short* idx_308781; idx_308781 = _238327_307976 + _308780; int _308790; _308790 = _308789 + converge_308461; short* idx_308836; idx_308836 = _238327_307976 + _308835; short* idx_308861; idx_308861 = _238327_307976 + _308860; short* idx_308896; idx_308896 = _238327_307976 + _308895; short* idx_308776; idx_308776 = _238327_307976 + _308775; short* idx_308891; idx_308891 = _238327_307976 + _308890; short* idx_308871; idx_308871 = _238327_307976 + _308870; short* idx_308801; idx_308801 = _238327_307976 + _308800; short* idx_308806; idx_308806 = _238327_307976 + _308805; short* idx_308811; idx_308811 = _238327_307976 + _308810; short* idx_308846; idx_308846 = _238327_307976 + _308845; short* idx_308876; idx_308876 = _238327_307976 + _308875; short* idx_308826; idx_308826 = _238327_307976 + _308825; short* idx_308821; idx_308821 = _238327_307976 + _308820; short* idx_308791; idx_308791 = _238327_307976 + _308790; short _308777; _308777 = *idx_308776; short _308908; _308908 = _308777; short _308782; _308782 = *idx_308781; short _308909; _308909 = _308782; short _308910; _308910 = _308908 + _308909; short _308787; _308787 = *idx_308786; short _308911; _308911 = _308787; short _308912; _308912 = _308910 + _308911; short _308792; _308792 = *idx_308791; short _308913; _308913 = _308792; short _308914; _308914 = _308912 + _308913; short _308797; _308797 = *idx_308796; short _308915; _308915 = _308797; short _308916; _308916 = _308914 + _308915; short _308802; _308802 = *idx_308801; short _308917; _308917 = _308802; short _308918; _308918 = _308916 + _308917; short _308807; _308807 = *idx_308806; short _308919; _308919 = _308807; short _308920; _308920 = _308918 + _308919; short _308812; _308812 = *idx_308811; short _308921; _308921 = _308812; short _308922; _308922 = _308920 + _308921; short _308817; _308817 = *idx_308816; short _308923; _308923 = _308817; short _308924; _308924 = _308922 + _308923; short _308822; _308822 = *idx_308821; short _308925; _308925 = _308822; short _308926; _308926 = _308924 + _308925; short _308827; _308827 = *idx_308826; short _308927; _308927 = _308827; short _308928; _308928 = _308926 + _308927; short _308832; _308832 = *idx_308831; short _308929; _308929 = _308832; short _308930; _308930 = _308928 + _308929; short _308837; _308837 = *idx_308836; short _308931; _308931 = _308837; short _308932; _308932 = _308930 + _308931; short _308842; _308842 = *idx_308841; short _308933; _308933 = _308842; short _308934; _308934 = _308932 + _308933; short _308847; _308847 = *idx_308846; short _308935; _308935 = _308847; short _308936; _308936 = _308934 + _308935; short _308852; _308852 = *idx_308851; short _308937; _308937 = _308852; short _308938; _308938 = _308936 + _308937; short _308857; _308857 = *idx_308856; short _308939; _308939 = _308857; short _308940; _308940 = _308938 + _308939; short _308862; _308862 = *idx_308861; short _308941; _308941 = _308862; short _308942; _308942 = _308940 + _308941; short _308867; _308867 = *idx_308866; short _308943; _308943 = _308867; short _308944; _308944 = _308942 + _308943; short _308872; _308872 = *idx_308871; short _308945; _308945 = _308872; short _308946; _308946 = _308944 + _308945; short _308877; _308877 = *idx_308876; short _308947; _308947 = _308877; short _308882; _308882 = *idx_308881; short _308948; _308948 = _308946 + _308947; short _308949; _308949 = _308882; short _308950; _308950 = _308948 + _308949; short _308887; _308887 = *idx_308886; short _308951; _308951 = _308887; short _308892; _308892 = *idx_308891; short _308952; _308952 = _308950 + _308951; short _308953; _308953 = _308892; short _308954; _308954 = _308952 + _308953; short _308897; _308897 = *idx_308896; short _308955; _308955 = _308897; short _308956; _308956 = _308954 + _308955; float _308957; _308957 = (float)_308956; float _308959; _308959 = _308957 / 2.500000e+01f; short _308960; _308960 = (short)_308959; *idx_308907 = _308960; goto l308770; l308770: ; int _308772; _308772 = lower_308394 + step_308396; plower_308394 = _308772; pupper_308395 = upper_308395; pstep_308396 = step_308396; goto l308392; } }
9,956
//pass //--blockDim=512 --gridDim=1 --no-inline #include <cuda.h> #include <assert.h> #include <stdio.h> #define N 2//512 __global__ void helloCUDA(volatile int* p) { //__assert(__no_read(p)); p[threadIdx.x] = threadIdx.x; } int main () { int *a; int *dev_a; int size = N*sizeof(int); a = (int*)malloc(size); cudaMalloc ((void**) &dev_a, size); helloCUDA<<<1,N>>>(dev_a); //ESBMC_verify_kernel(helloCUDA,1,N,dev_a); cudaMemcpy(a,dev_a,size,cudaMemcpyDeviceToHost); for (int i = 0; i < N; i++) { assert(a[i] == i); // } free(a); cudaFree(dev_a); return 0; }
9,957
#include <stdio.h> #include <cuda.h> __global__ void hello_world() { printf("Hello, World\n"); } int main() { hello_world<<<1,1>>>(); cudaDeviceSynchronize(); return 0; }
9,958
#include "includes.h" __global__ void bin_start(int *binStart, int *binEnd, int *partBin, int nparts) { // This kernel function was adapted from NVIDIA CUDA 5.5 Examples // This software contains source code provided by NVIDIA Corporation extern __shared__ int sharedBin[]; //blockSize + 1 int index = threadIdx.x + blockIdx.x*blockDim.x; int bin; // for a given bin index, the previous bins's index is stored in sharedBin if (index < nparts) { bin = partBin[index]; // Load bin data into shared memory so that we can look // at neighboring particle's hash value without loading // two bin values per thread sharedBin[threadIdx.x + 1] = bin; if (index > 0 && threadIdx.x == 0) { // first thread in block must load neighbor particle bin sharedBin[0] = partBin[index - 1]; } } __syncthreads(); if (index < nparts) { // If this particle has a different cell index to the previous // particle then it must be the first particle in the cell, // so store the index of this particle in the cell. // As it isn't the first particle, it must also be the cell end of // the previous particle's cell bin = partBin[index]; if (index == 0 || bin != sharedBin[threadIdx.x]) { binStart[bin] = index; if (index > 0) binEnd[sharedBin[threadIdx.x]] = index; } if (index == nparts - 1) { binEnd[bin] = index + 1; } } }
9,959
#include "includes.h" __global__ void BlurViaStencil(float* d_out, float* d_in) { const float kernel[3][3] = {0.04, 0.12, 0.04, 0.12, 0.36, 0.12, 0.04, 0.12, 0.04}; int rowID = blockIdx.x + 1; int colID = threadIdx.x + 1; int pos = rowID * (blockDim.x + 2) + colID; d_out[pos] = d_in[pos - blockDim.x - 3] * kernel[0][0] + d_in[pos - blockDim.x - 2] * kernel[0][1] + d_in[pos - blockDim.x - 1] * kernel[0][2] + d_in[pos - 1] * kernel[1][0] + d_in[pos] * kernel[1][1] + d_in[pos + 1] * kernel[1][2] + d_in[pos + blockDim.x + 1] * kernel[2][0] + d_in[pos + blockDim.x + 2] * kernel[2][1] + d_in[pos + blockDim.x + 3] * kernel[2][2]; }
9,960
#include <cuda_runtime.h> // texture<float, cudaTextureType1D, cudaReadModeElementType> tex1DRef(0, cudaFilterModePoint, cudaAddressModeBorder); // __global__ void transformKernel(float* output, int element_count) { // // int tid = blockIdx.x * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; // int tid = blockIdx.x * blockDim.x + threadIdx.x; // if (tid < element_count) { // output[tid] = tex1Dfetch(tex1DRef, tid); // // output[tid] = tex1D(tex1DRef, tid); // } // }
9,961
#include "cuda_runtime.h" #include "stdio.h" __global__ void checkIndex(void){ printf("threadIdx: (%d, %d, %d) blockIdx: (%d, %d, %d) gridDim: (%d, %d, %d) \n", \ threadIdx.x, threadIdx.y, threadIdx.z, \ blockIdx.x, blockIdx.y, blockIdx.z, \ gridDim.x, gridDim.y, gridDim.z); } int main(){ // define total data element int nElem = 6; // define grid and block structure dim3 block(3); dim3 grid((nElem+block.x-1)/block.x); // check grid and block dimension from host side printf("grid.x %d, grid.y %d grid.z %d \n", grid.x, grid.y, grid.z); printf("block.x %d, block.y %d block.z %d \n", block.x, block.y, block.z); checkIndex<<<grid, block>>>(); cudaDeviceReset(); return 0; }
9,962
#include "includes.h" //////////// Calculates weighting for assembling single element solution /////////// // One weight is evaluated for each node // Added back to global memory __global__ void glob_sols( float *Le, float *w, float *u_glob, float *ue, int *cells, int num_cells) { int idx = blockIdx.x*blockDim.x + threadIdx.x; int idy = blockIdx.y*blockDim.y + threadIdx.y; int v; float Lii, weight; if(idx < num_cells && idy < blockDim.y){ v = cells[(idx*3) + idy]; // getting global vertex number Lii = Le[(idx*9) + (idy*3) + idy]; weight = Lii/w[v]; atomicAdd(&u_glob[v], weight * ue[(idx*3) + idy]); } }
9,963
// sinusoidal kernel (Rob Farber) // Simple kernel to modify vertex positions in sine wave pattern __global__ void kernel(float4* pos, uchar4 *colorPos, unsigned int width, unsigned int height, float time) { unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; // calculate uv coordinates float u = x / (float) width; float v = y / (float) height; u = u*2.0f - 1.0f; v = v*2.0f - 1.0f; // calculate simple sine wave pattern float freq = 4.0f; float w = sinf(u*freq + time) * cosf(v*freq + time) * 0.5f; // write output vertex pos[y*width+x] = make_float4(u, w, v, 1.0f); colorPos[y*width+x].w = 0; colorPos[y*width+x].x = 255.f *0.5*(1.f+sinf(w+x)); colorPos[y*width+x].y = 255.f *0.5*(1.f+sinf(x)*cosf(y)); colorPos[y*width+x].z = 255.f *0.5*(1.f+sinf(w+time/10.f)); } // Wrapper for the __global__ call that sets up the kernel call extern "C" void launch_kernel(float4* pos, uchar4* colorPos, unsigned int mesh_width, unsigned int mesh_height, float time) { // execute the kernel dim3 block(8, 8, 1); dim3 grid(mesh_width / block.x, mesh_height / block.y, 1); kernel<<< grid, block>>>(pos, colorPos, mesh_width, mesh_height, time); }
9,964
#include "stdio.h" __global__ void add_arrays_gpu( float *in1, float *in2, float *out, int Ntot) { int idx=blockIdx.x*blockDim.x+threadIdx.x; if ( idx <Ntot ) out[idx]=in1[idx]+in2[idx]+threadIdx.x; } extern int add_vectors() { /* pointers to host memory */ float *a, *b, *c; /* pointers to device memory */ float *a_d, *b_d, *c_d; int N=18; int i; /* Allocate arrays a, b and c on host*/ a = (float*) malloc(N*sizeof(float)); b = (float*) malloc(N*sizeof(float)); c = (float*) malloc(N*sizeof(float)); /* Allocate arrays a_d, b_d and c_d on device*/ cudaMalloc ((void **) &a_d, sizeof(float)*N); cudaMalloc ((void **) &b_d, sizeof(float)*N); cudaMalloc ((void **) &c_d, sizeof(float)*N); /* Initialize arrays a and b */ for (i=0; i<N; i++) { a[i]= (float) i; b[i]=-(float) i; } /* Copy data from host memory to device memory */ cudaMemcpy(a_d, a, sizeof(float)*N, cudaMemcpyHostToDevice); cudaMemcpy(b_d, b, sizeof(float)*N, cudaMemcpyHostToDevice); /* Compute the execution configuration */ int block_size=8; dim3 dimBlock(block_size); dim3 dimGrid ( (N/dimBlock.x) + (!(N%dimBlock.x)?0:1) ); /* Add arrays a and b, store result in c */ add_arrays_gpu<<<dimGrid,dimBlock>>>(a_d, b_d, c_d, N); /* Copy data from deveice memory to host memory */ cudaMemcpy(c, c_d, sizeof(float)*N, cudaMemcpyDeviceToHost); /* Print c */ for (i=0; i<N; i++) printf(" c[%d]=%f\n",i,c[i]); /* Free the memory */ free(a); free(b); free(c); cudaFree(a_d); cudaFree(b_d);cudaFree(c_d); return 0; }
9,965
#include "includes.h" __global__ void MatrixMulKernelV1(float* M, float* N, float* P, int Width) { int Row = blockIdx.y*blockDim.y+threadIdx.y; int Col = blockIdx.x*blockDim.x+threadIdx.x; if ((Row < Width) && (Col < Width)) { float Pvalue = 0; for (int k = 0; k < Width; ++k) Pvalue += M[Row*Width+k]*N[k*Width+Col]; P[Row*Width+Col] = Pvalue; } }
9,966
#include "includes.h" __global__ void k_Simple( const float* p_Input, float* p_Output, int p_Width, int p_Height) { const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; if (x < p_Width && y < p_Height) { const int index = (y * p_Width + x) * 4; p_Output[index] = p_Input[index]; p_Output[index + 1] = p_Input[index + 1]; p_Output[index + 2] = p_Input[index + 2]; p_Output[index + 3] = p_Input[index + 3]; }}
9,967
#include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/reduce.h> #include <thrust/functional.h> #include <algorithm> #include <cstdlib> int main(void) { unsigned int size = 4096*4096; thrust::host_vector<int32_t> input_host(size); for(int i=0; i < size; i++){ input_host[i] = i; } //std::generate(input_host.begin(), input_host.end(), rand); for(int i=0; i < 100; i++){ printf("%d,", input_host[i]); } printf("\n"); // transfer to device and compute sum thrust::device_vector<int32_t> input_device = input_host; thrust::device_vector<int32_t> output_device(size); thrust::plus<int32_t> binary_op; thrust::exclusive_scan(input_device.begin(), input_device.end(), output_device.begin(), 0, binary_op); // in-place scan thrust::host_vector<int32_t> output_host = output_device; for(int i=0; i < 100; i++){ printf("%d,", output_host[i]); } printf("\n"); cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); for(int i=0; i < 100; i++){ //int x = thrust::reduce(input_device.begin(), input_device.end(), 0, binary_op); thrust::exclusive_scan(input_device.begin(), input_device.end(), output_device.begin(), 0, binary_op); // in-place scan } cudaEventRecord(stop, 0); cudaEventSynchronize(stop); float elapsedTime; cudaEventElapsedTime(&elapsedTime , start, stop); printf("Avg. time is %f ms\n", elapsedTime/100); return 0; }
9,968
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include<stdio.h> __global__ void unique_idx_calc_threadInx(int* input) { int thread_id = threadIdx.x; printf("threadIdx: %d, value: %d \n", thread_id, input[thread_id]); } __global__ void unique_grid_calculation(int* input) { int thread_id = threadIdx.x; int offset = blockIdx.x * blockDim.x; int grid_id = thread_id + offset; printf("blockIdx.x: %d, threadIdx: %d, gid: %d, value: %d \n", blockIdx.x, thread_id, grid_id, input[grid_id]); } /* int main() { int array_size = 16; int array_byte_size = sizeof(int) * array_size; int h_data[] = { 23, 9, 4, 53, 65, 12, 1, 33, 87, 45, 23, 12, 342, 56, 44, 99 }; for (int i = 0; i < array_size; i++) { printf("%d ", h_data[i]); } printf("\n\n"); int* d_data; cudaMalloc((void**)&d_data, array_byte_size); cudaMemcpy(d_data, h_data, array_byte_size, cudaMemcpyHostToDevice); dim3 block(4); dim3 grid(4); unique_grid_calculation<<<grid, block>>>(d_data); cudaDeviceSynchronize(); cudaDeviceReset(); return 0; } */
9,969
#include<thrust/device_vector.h> #include<thrust/transform.h> #include<thrust/sequence.h> #include<thrust/copy.h> #include<thrust/fill.h> #include<thrust/replace.h> #include<thrust/functional.h> #include<iostream> int main(){ int N = 10; // raw pointer to device memory int * raw_ptr; cudaMalloc((void **) &raw_ptr, N *sizeof(int)); // wrap raw pointer with a device_ptr thrust::device_ptr<int> dev_ptr(raw_ptr); // use device_ptr in thrust algorithms thrust::fill(dev_ptr, dev_ptr + N, (int)0); // access device memory through device_ptr dev_ptr[0] = 1; // free memory cudaFree(raw_ptr); return 0; }
9,970
#include <stdio.h> #include <assert.h> #include <cuda.h> #include <cuda_runtime.h> #define THREAD_PER_BLOCK 1024 #define RADIUS 1000 __global__ void cudaVecAddKernel(int* a, int* b, int* c, int size) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < size) { c[id] = a[id] + b[id]; } } /** * an optimized stencial_add kernel with shared_memory * the motivation here is that each element is loaded by threads (2*radius+1) times. * we definitely want to optimize it. */ __global__ void cudaStencialAddKernel_optimized(int* a, int* c, int size) { __shared__ int temp[THREAD_PER_BLOCK + RADIUS * 2]; int id = blockIdx.x * blockDim.x + threadIdx.x; if (id >= size) return; // all threads within the block collaboratievly load the // data required into the on-chip shared memory. int sid = threadIdx.x + RADIUS; temp[sid] = a[id]; int offset1 = THREAD_PER_BLOCK + RADIUS; if (threadIdx.x < RADIUS) { int id1 = id - RADIUS; if (id1 >= 0) temp[threadIdx.x] = a[id1]; int id2 = id + THREAD_PER_BLOCK; if (id2 < size) temp[threadIdx.x + offset1] = a[id2]; } __syncthreads(); //synchronize to ensure all data are available // perfrom stencil add on the shared memory int offset2 = blockIdx.x * blockDim.x - RADIUS; for (int i = threadIdx.x; i <= threadIdx.x + RADIUS * 2; i++) { int g_i = offset2 + i; if (g_i < 0 || g_i >= size) continue; c[id] += temp[i]; } } __global__ void cudaSencialAddKernel(int* a, int* c, int size) { int id = blockIdx.x * blockDim.x + threadIdx.x; if (id < size) { for (int i = id - RADIUS; i <= id + RADIUS; i++) { if (i < 0 || i >= size) continue; c[id] += a[i]; } } } void cudaVecAdd(int* a, int* b, int* c, int size) { cudaVecAddKernel <<< (size + THREAD_PER_BLOCK - 1)/THREAD_PER_BLOCK, THREAD_PER_BLOCK >>>(a, b, c, size); } void cudaStencialAdd(int* a, int *c, int size) { cudaSencialAddKernel <<< (size + THREAD_PER_BLOCK - 1)/THREAD_PER_BLOCK, THREAD_PER_BLOCK >>> (a, c, size); } void cudaStencialAdd_optimized(int* a, int *c, int size) { cudaStencialAddKernel_optimized <<< (size + THREAD_PER_BLOCK - 1) / THREAD_PER_BLOCK, THREAD_PER_BLOCK >>> (a, c, size); }
9,971
#include <stdio.h> #include <iostream> #include <cuda.h> int main( void ) { std::cout << "Hello, World!" << std::endl; return 0; }
9,972
/** * Autor: Grupo GRID * Fecha: Julio 2016 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 4 __global__ void MultiplocarMatrices(int *d_a, int *d_b, int *d_c, int n ) { int id, i, j; id = blockIdx.x * blockDim.x + threadIdx.x; if ( id < n ) { for( i = 0 ; i < n ; i++ ) { d_c[ id * n + i ] = 0; for ( j = 0 ; j < n ; j++) { d_c[ id * n + i ] += ( d_a[ id * n + j ] * d_b[ j * n + id ] ); } } } } int main( int argc, char** argv) { int *h_a, *h_b, *h_c; int *d_a, *d_b, *d_c; char validacion[10]; int n = N; // Valor por defecto if ( argc > 1 ) { n = atoi (argv[1]); if ( n > 1024 ) { n = 1024; } } size_t memSize = n * n * sizeof( int ); h_a = (int *) malloc( memSize ); h_b = (int *) malloc( memSize ); h_c = (int *) malloc( memSize ); if ( h_a == NULL || h_b == NULL || h_c == NULL ) { perror("Memoria insuficiente\n"); exit(-1); } cudaMalloc( (void**) &d_a, memSize ); cudaMalloc( (void**) &d_b, memSize ); cudaMalloc( (void**) &d_c, memSize ); if ( d_a == NULL || d_b == NULL || d_c == NULL ) { perror("Memoria insuficiente en la GPU\n"); exit(-1); } for( int i = 0 ; i < n ; i++ ) { for( int j = 0 ; j < n ; j++ ) { h_a[ n * i + j] = 1; h_b[ n * i + j] = 1; h_c[ n * i + j] = 0; } } cudaMemcpy( d_a, h_a , memSize, cudaMemcpyHostToDevice ); cudaMemcpy( d_b, h_b , memSize, cudaMemcpyHostToDevice ); MultiplocarMatrices<<< 1 , n >>> (d_a, d_b, d_c, n ); cudaMemcpy( h_c, d_c, memSize, cudaMemcpyDeviceToHost ); // Validación de la multiplicación // El producto de dos matrices de NxN de unos produce una matriz donde todos los elementos son N strcpy(validacion, "Ok"); for( int i = 0 ; i < n ; i++ ) { for( int j = 0 ; j < n ; j++ ) { if ( h_c[ n * i + j ] != n ) { strcpy(validacion, "Error"); } } } cudaFree(d_a); cudaFree(d_b); cudaFree(d_c); free(h_a); free(h_b); free(h_c); printf ( "\t %10d \t\t %s \t ", n, validacion ); return 0; }
9,973
__global__ void gIncr(float *d, size_t ind, float delta) { d[ind] += delta; } __global__ void gSum(float *d, size_t size, float *total) { total = 0; for (size_t i = 0; i < size; ++i) { *total += d[i]; } }
9,974
#include "conv2d-transpose.hh" #include "graph.hh" #include "../runtime/node.hh" #include "../memory/alloc.hh" #include "ops-builder.hh" #include "conv2d-transpose-input-grad.hh" #include "conv2d-transpose-kernel-grad.hh" #include <cassert> #include <stdexcept> #include <cmath> namespace ops { Conv2DTranspose::Conv2DTranspose(Op* input, Op* kernel, const int out_size[], const int strides[]) : Op("conv2d_transpose", Shape({out_size[0], out_size[1], out_size[2], out_size[3]}), {input, kernel} ) , m_out_size(out_size) , m_strides(strides) , m_input_shape(input->shape_get()) , m_kernel_shape(kernel->shape_get()) {} void Conv2DTranspose::compile() { auto& g = Graph::instance(); auto& cinput = g.compiled(preds()[0]); auto& ckernel = g.compiled(preds()[1]); Shape out_shape({m_out_size[0], m_out_size[1], m_out_size[2], m_out_size[3]}); dbl_t* out_data = tensor_alloc(out_shape.total()); int input_size[4] = { cinput.out_shape[0], cinput.out_shape[1], cinput.out_shape[2], cinput.out_shape[3]}; int kernel_size[4] = { ckernel.out_shape[0], ckernel.out_shape[1], ckernel.out_shape[2], ckernel.out_shape[3]}; auto out_node = rt::Node::op_conv2d_transpose(cinput.out_data, ckernel.out_data, m_out_size, m_strides, out_data, input_size, kernel_size, {cinput.out_node, ckernel.out_node}); g.add_compiled(this, {out_node}, {out_data}, out_node, out_shape, out_data); } Op* Conv2DTranspose::child_grad(std::size_t index, Op* dout) { assert(index < 2); if (dout == nullptr) throw std::runtime_error {"conv2d_transpose must not be the final node of the gradient"}; auto& builder = OpsBuilder::instance(); int input_size[4] = { m_input_shape[0], m_input_shape[1], m_input_shape[2], m_input_shape[3]}; int kernel_size[4] = { m_kernel_shape[0], m_kernel_shape[1], m_kernel_shape[2], m_kernel_shape[3]}; if (index == 0) return builder.conv2d_transpose_input_grad(dout, preds()[1], m_strides, input_size); else return builder.conv2d_transpose_kernel_grad(dout, preds()[0], m_strides, kernel_size); } }
9,975
#include <curand.h> #include <curand_kernel.h> __device__ void one_point_cross(int* newIndividuals, int* d_pop, int start, int end, curandState* my_curandstate, int dimensions, int pop_size) { int pos = curand(my_curandstate) % (dimensions - 1); int partner = curand(my_curandstate) % pop_size; int cont = 0, sum = 0; for (int i = start; i < start + pos; i++) { newIndividuals[cont] = d_pop[i]; sum += d_pop[i]; cont++; } for (int i = dimensions * partner + pos; i < dimensions * partner + dimensions - 1; i++) { newIndividuals[cont] = d_pop[i]; sum += d_pop[i]; cont++; } newIndividuals[cont] = sum; cont++; sum = 0; for (int i = dimensions * partner; i < dimensions * partner + pos; i++) { newIndividuals[cont] = d_pop[i]; sum += d_pop[i]; cont++; } for (int i = start + pos; i < end - 1; i++) { newIndividuals[cont] = d_pop[i]; sum += d_pop[i]; cont++; } newIndividuals[cont] = sum; } __device__ void mutation(int* newIndividuals, int* d_pop, int start, int end, curandState* my_curandstate, int dimensions) { int pos = curand(my_curandstate) % (dimensions - 1); int cont = 0, sum = 0; for (int i = start; i < end - 1; i++) { if (i == start + pos) newIndividuals[cont] = 1 - d_pop[i]; else newIndividuals[cont] = d_pop[i]; sum += newIndividuals[cont]; cont++; } newIndividuals[cont] = sum; } extern "C" __global__ void applyOperators(double* d_operators_probabilites, int* d_pop, int dimensions, int operators_number, curandState* my_curandstate, int pop_size, int totalThreads) { int idx = threadIdx.x + blockDim.x * blockIdx.x; int row = idx * (pop_size / totalThreads); if (pop_size % totalThreads != 0) row++; if (idx < totalThreads) { for (int j = row; j < row + (pop_size / totalThreads); j++) { int i; int start, end; //Select Operator double sum = 0.0; int cont = 0; float rand_number = curand_uniform(my_curandstate + idx); for (int i = row * operators_number; i < row * operators_number + operators_number; i++) { sum += d_operators_probabilites[i]; if (rand_number < sum) break; cont++; } start = row * dimensions; end = start + dimensions; float reward = -1.0; //Cross int newIndividuals[2 * 1000]; if (cont == 0) { one_point_cross(newIndividuals, d_pop, start, end, my_curandstate + idx, dimensions, pop_size); int cont_new; if (newIndividuals[dimensions - 1] > d_pop[end - 1] && newIndividuals[dimensions - 1] > newIndividuals[2 * dimensions - 1]) { cont_new = 0; for (int i = start; i < end; i++) { d_pop[i] = newIndividuals[cont_new]; cont_new++; } reward = 1.0; } else if (newIndividuals[2 * dimensions - 1] > d_pop[end - 1] && newIndividuals[2 * dimensions - 1] > newIndividuals[dimensions - 1]) { cont_new = dimensions; for (int i = start; i < end; i++) { d_pop[i] = newIndividuals[cont_new]; cont_new++; } reward = 1.0; } } //Mutation else if (cont == 1) { mutation(newIndividuals, d_pop, start, end, my_curandstate + idx, dimensions); if (newIndividuals[dimensions - 1] > d_pop[end - 1]) { int cont_new = 0; for (int i = start; i < end; i++) { d_pop[i] = newIndividuals[cont_new]; cont_new++; } reward = 1.0; } } //Apply reward float plus = curand_uniform(my_curandstate + idx); plus = 1.0 + (plus * reward); d_operators_probabilites[row * operators_number + cont] *= plus; //Normalizes float sumP = 0.0; for (int i = row * operators_number; i < row * operators_number + operators_number; i++) { sumP += d_operators_probabilites[i]; } for (int i = row * operators_number; i < row * operators_number + operators_number; i++) { d_operators_probabilites[i] /= sumP; } } } }
9,976
#include <stdio.h> #include <math.h> #include <time.h> #include <iostream> #include <cuda.h> #define NUMBER_RUNS 1 #define LCG_A 1103515245 #define LCG_C 12345 #define LCG_M 2147483646 #define MAX_TRIES 1000 #define N_LIMIT 20 #define MAX_TEMP_STEPS 100 #define TEMP_START 0.5 #define COOLING 0.99 #define THREADS 1024 #define BOLTZMANN_COEFF 0.01 using namespace std; struct city { double x; double y; }; struct permutation { int cost; int* order; int nSucc; }; struct GlobalConstants { int CITY_N; city* cities; unsigned int* randSeeds; }; //global variables struct city *cities; int CITY_N; //global variables on GPU __constant__ GlobalConstants cuTspParam; /* rounding function, but at .5 rounds to the lower int. Due to the TSPLIB * standard library. */ __device__ __host__ __inline__ int nint(float x) { return (int) (x + 0.5); } /* Randomisation is done by a simple linear congruential generator. * We use A and C values as done by glibc. */ __device__ __inline__ unsigned int rand(unsigned int *x) { *x = ((LCG_A * (*x)) + LCG_C) & 0x7fffffff; return *x; } __device__ __inline__ float randomFloat(unsigned int *x) { return (float) (rand(x) / (float) LCG_M); } __device__ __inline__ double randomDouble(unsigned int *x) { return (double) (rand(x) / (double) LCG_M); } __device__ __inline__ unsigned int randomInt(unsigned int *x, unsigned int max) { return rand(x) % max; } __device__ __inline__ bool randomBool(unsigned int *x) { if ((randomInt(x, 256) >> 7) & 0x00000001) return true; else return false; } __device__ __host__ __inline__ int euclideanDistance(struct city *a, struct city *b) { float dx = b->x - a->x; float dy = b->y - a->y; return nint((sqrt(dx * dx + dy * dy))); } /* Calcuates the delta of the costs given by a new order using reverse */ __device__ __inline__ int reverseCost(struct city *cities, int *order, int *n) { int cost; cost = -euclideanDistance(&cities[order[n[0]]], &cities[order[n[2]]]); cost -= euclideanDistance(&cities[order[n[1]]], &cities[order[n[3]]]); cost += euclideanDistance(&cities[order[n[0]]], &cities[order[n[3]]]); cost += euclideanDistance(&cities[order[n[1]]], &cities[order[n[2]]]); return cost; } /* The order of the city is changed by swapping the * order between n[0] and n[1]. * The swapping is done beginning from the outer end * going into the middle */ __device__ __inline__ void reverse(int *order, int *n) { int CITY_N = cuTspParam.CITY_N; int swaps = (1 + ((n[1] - n[0] + CITY_N) % CITY_N)) / 2; // this many elements have to be swapped to have a complete reversal for (int j = 0; j < swaps; ++j) { int k = (n[0] + j) % CITY_N; int l = (n[1] - j + CITY_N) % CITY_N; int tmp = order[k]; order[k] = order[l]; order[l] = tmp; } } /* Calculates the delta of the costs of the city order if * the transportation of this segments (given by n) are actually * done. */ __device__ __inline__ int transportCost(struct city *cities, int *order, int *n) { int cost; cost = -euclideanDistance(&cities[order[n[1]]], &cities[order[n[5]]]); cost -= euclideanDistance(&cities[order[n[0]]], &cities[order[n[4]]]); cost -= euclideanDistance(&cities[order[n[2]]], &cities[order[n[3]]]); cost += euclideanDistance(&cities[order[n[0]]], &cities[order[n[2]]]); cost += euclideanDistance(&cities[order[n[1]]], &cities[order[n[3]]]); cost += euclideanDistance(&cities[order[n[4]]], &cities[order[n[5]]]); return cost; } /* Transport the path segment (consisting of the start n[0] and end at n[1] * to the path given by n[2] and n[3], which are adjacent and the segment is * to be placed in between. n[4] is the city preceding n[0] and n[5] succeeds * n[1]. * Transportation should only be done if the metroplis algorithm agrees. * */ __device__ void transport(int *order, int *n) { int CITY_N = cuTspParam.CITY_N; int *newOrder = &order[CITY_N]; int m1 = (n[1] - n[0] + CITY_N) % CITY_N; int m2 = (n[4] - n[3] + CITY_N) % CITY_N; int m3 = (n[2] - n[5] + CITY_N) % CITY_N; int i = 0; for (int j = 0; j <= m1; ++j) { newOrder[i++] = order[(j + n[0]) % CITY_N]; } for (int j = 0; j <= m2; ++j) { newOrder[i++] = order[(j + n[3]) % CITY_N]; } for (int j = 0; j <= m3; ++j) { newOrder[i++] = order[(j + n[5]) % CITY_N]; } for (int j = 0; j < CITY_N; ++j) { order[j] = newOrder[j]; } } /* Metroplis algorithm: Always take the downhill path and * sometime take the uphill path to avoid local minima */ __device__ __inline__ bool metropolis(const int cost, const double t, unsigned int *x) { return cost < 0 || randomDouble(x) < exp((double) (BOLTZMANN_COEFF * -cost / t)); } __host__ __inline__ void copy_permutation(struct permutation* dest, const struct permutation* src) { dest->cost = src->cost; dest->nSucc = src->nSucc; for (int i = 0; i < CITY_N; ++i) { dest->order[i] = src->order[i]; } } /* Main kernel function */ __global__ void solve( struct permutation *permutations, const float t) { struct city *cities = cuTspParam.cities; int CITY_N = cuTspParam.CITY_N; int notSeg; // number of cities not on the segment int maxChangeTries = MAX_TRIES * CITY_N; int succLimit = N_LIMIT * CITY_N; int dCost; bool ans; int n[6]; int id = blockDim.x * blockIdx.x + threadIdx.x; struct permutation *perm = &(permutations[id]); unsigned int *x = cuTspParam.randSeeds; perm->nSucc = 0; for (int j = 0; j < maxChangeTries; ++j) { do { n[0] = randomInt(x, CITY_N); n[1] = randomInt(x, CITY_N - 1); if (n[1] >= n[0]) ++n[1]; notSeg = (n[0] - n[1] + CITY_N - 1) % CITY_N; } while (notSeg < 2); /* It is randomly choosen whether a transportation or a reversion is done */ if (randomBool(x)) { n[2] = (n[1] + randomInt(x, abs(notSeg - 1)) + 1) % CITY_N; n[3] = (n[2] + 1) % CITY_N; n[4] = (n[0] + CITY_N- 1) % CITY_N; n[5] = (n[1] + 1) % CITY_N; dCost = transportCost(cities, perm->order, n); ans = metropolis(dCost, t, x); if (ans) { ++perm->nSucc; perm->cost += dCost; transport(perm->order, n); } } else { n[2] = (n[0] + CITY_N - 1) % CITY_N; n[3] = (n[1] + 1) % CITY_N; dCost = reverseCost(cities, perm->order, n); ans = metropolis(dCost, t, x); if (ans) { ++perm->nSucc; perm->cost += dCost; reverse(perm->order, n); } } /* Finish early if there are enough successful changes */ if (perm->nSucc > succLimit) break; } } class Anneal { private: /* Calculates the length of the initial path, which is already given. * This is in O(n) */ void initialPath(struct permutation *perm, struct city *cities) { int i, i1, i2; perm->cost= 0; for (i = 0; i < CITY_N - 1; i++) { i1 = perm->order[i]; i2 = perm->order[i+1]; perm->cost += euclideanDistance(&cities[i1], &cities[i2]); } i1 = perm->order[CITY_N - 1]; i2 = perm->order[0]; perm->cost += euclideanDistance(&cities[i1], &cities[i2]); cout << "Initial path length: " << perm->cost << endl; } void printInformation(struct permutation *currPerm, bool showOrder = true) { cout << "Path Length = " << currPerm->cost << endl; cout << "Successful Moves: " << currPerm->nSucc << endl; if (showOrder) { cout << "Order: "; for (int j = 0; j < CITY_N; j++) { cout << currPerm->order[j] << " "; } } cout << endl; } public: double runtime; int resultCost; Anneal() {} void order(struct city *cities, int *order) { double t = TEMP_START; long seed = (long) (time(NULL)); cudaError_t cudaStat; struct permutation* dPermutation; struct permutation* hPermutation = (struct permutation *) malloc(THREADS * sizeof(struct permutation)); for (int i = 0; i < CITY_N; i++) { hPermutation[i].order = new int [CITY_N]; } struct city *dCities; unsigned int *LCGX = (unsigned int *) malloc(THREADS * sizeof(unsigned int)); unsigned int *dLCGX; struct permutation *currPerm = (struct permutation *) malloc(sizeof(struct permutation)); currPerm->order = new int [CITY_N]; struct permutation *allMinPerm= (struct permutation *) malloc(sizeof(struct permutation)); allMinPerm->order = new int [CITY_N]; int oldCost = 2147483647; int repeatCost = 0; clock_t startAll, endAll; // timer to measure the overall run time double runtimeAll; clock_t startCuda, endCuda; //timer to measure the run time of cuda double cudaRuntime = 0.0f; startAll = clock(); //initialize RNG srand(seed); //initialize seeds for RNG on GPU for (int i = 0; i < THREADS; ++i) { LCGX[i] = rand(); } // Kernel invocation int threadsPerBlock = 256; int blocksPerGrid = (THREADS + threadsPerBlock - 1) / threadsPerBlock; cout << "Threads: " << THREADS << ", Blocks: " << blocksPerGrid << endl; for (int i = 0; i < CITY_N; i++) { currPerm->order[i] = order[i]; } initialPath(currPerm, cities); copy_permutation(allMinPerm, currPerm); //allocate and copy #threads permutations on the device cudaStat = cudaMalloc(&dPermutation, THREADS * sizeof(struct permutation)); if (cudaStat != cudaSuccess) { cout << "couldn't allocate memory on the device. Exit." << endl; return; } for (int i = 0; i < THREADS; i++) { int* order; cudaStat = cudaMalloc(&order, 2 * CITY_N * sizeof(int)); if (cudaStat != cudaSuccess) { cout << "couldn't allocate memory on the device. Exit." << endl; return; } cudaStat = cudaMemcpy(order, currPerm->order, CITY_N * sizeof(int), cudaMemcpyHostToDevice); if (cudaStat != cudaSuccess) { cout << "couldn't allocate memory on the device. Exit." << endl; return; } cudaStat = cudaMemcpy(&dPermutation[i].order, &order, sizeof(int*), cudaMemcpyHostToDevice); if (cudaStat != cudaSuccess) { cout << "couldn't allocate memory on the device. Exit." << endl; return; } } cout<<"After the first call\n"; cudaStat = cudaMalloc(&dCities, CITY_N * sizeof(struct city)); if (cudaStat != cudaSuccess) { cout << "couldn't allocate memory on the device. Exit." << endl; return; } cudaStat = cudaMemcpy(dCities, cities, CITY_N * sizeof(struct city), cudaMemcpyHostToDevice); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory to global memory. Exit." << endl; return; } cudaStat = cudaMalloc(&dLCGX, THREADS * sizeof(unsigned int)); if (cudaStat != cudaSuccess) { cout << "couldn't allocate memory on the device. Exit." << endl; return; } cudaStat = cudaMemcpy(dLCGX, LCGX, THREADS * sizeof(unsigned int), cudaMemcpyHostToDevice); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory to global memory. Exit." << endl; return; } cout<<"Just after the allocation\n"; GlobalConstants params; params.cities = dCities; params.randSeeds = dLCGX; params.CITY_N = CITY_N; cudaMemcpyToSymbol(cuTspParam, &params, sizeof(GlobalConstants)); cout<<"Just before the for loop\n"; /* Try up to MAX_TEMP_STEPS temperature steps. It could stop before if no kernel * showed any succesful change or if the solution did not change 5 times */ for (int i = 0; i < MAX_TEMP_STEPS; ++i) { cudaThreadSynchronize(); startCuda = clock(); cout<<"This is the "<<i<<" th loop\n"; //Copies the initial permutation to each result permutation for (int i = 0; i < THREADS; i++) { //cudaStat = cudaMemcpy(dPermutation[i].order, currPerm->order, CITY_N * sizeof(int), cudaMemcpyHostToDevice); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory to global memory. Exit." << endl; return; } cudaStat = cudaMemcpy(&dPermutation[i].cost, &currPerm->cost, sizeof(int), cudaMemcpyHostToDevice); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory to global memory. Exit." << endl; return; } } cout<<"Just before the kernel call\n"; //invoke cuda solve<<<blocksPerGrid, threadsPerBlock>>>(dPermutation, t); cudaStat = cudaThreadSynchronize(); if (cudaStat != cudaSuccess) { cout << "something went wrong during device execution. Exit." << endl; return; } endCuda = clock(); cudaRuntime += (endCuda - startCuda) * 1000 / CLOCKS_PER_SEC; for (int i = 0; i < THREADS; i++) { cudaStat = cudaMemcpy(hPermutation[i].order, dPermutation[i].order, CITY_N * sizeof(int), cudaMemcpyDeviceToHost); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory from global memory. Exit." << endl; return; } cudaStat = cudaMemcpy(&hPermutation[i].cost, &dPermutation[i].cost, sizeof(int), cudaMemcpyDeviceToHost); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory from global memory. Exit." << endl; return; } cudaStat = cudaMemcpy(&hPermutation[i].nSucc, &dPermutation[i].nSucc, sizeof(int), cudaMemcpyDeviceToHost); if (cudaStat != cudaSuccess) { cout << "couldn't copy memory from global memory. Exit." << endl; return; } } /* Loops through all resulting permutations and store the one with minimal length but * at least one swap. * If all threads didn't swap, exit the program. * Takes O(n) time. */ int minCost = 2147483647; bool swap = false; for (int j = 0; j < THREADS; ++j) { if (minCost >= hPermutation[j].cost && hPermutation[j].nSucc != 0) { currPerm = &(hPermutation[j]); minCost = currPerm->cost; swap = true; if (minCost < allMinPerm->cost) copy_permutation(allMinPerm, currPerm); //memcpy(allMinPerm, currPerm, sizeof(struct permutation)); } } if (!swap) { cout << "No swaps occured. Exit" << endl; break; } if (oldCost == minCost) { if (++repeatCost == 5) { cout << "Cost did not change 5 times in a row. Exit" << endl; break; } } else repeatCost = 0; cout << endl << "T = " << t << endl; //cout << "repeat: " << repeatCost << ", old: " << oldCost << ", new: " << minCost << endl; printInformation(currPerm, false); //for (int j = 0; j < THREADS; ++j) // printInformation(&(hPermutation[j]), false); oldCost = minCost; t *= COOLING; } endAll = clock(); runtimeAll = (endAll - startAll) / (1.0f * CLOCKS_PER_SEC) * 1000; cout << endl << "Final Result:" << endl; cout << "=============" << endl; printInformation(allMinPerm); runtime = runtimeAll; resultCost = allMinPerm->cost; printf("\nThe program needed an overall time of %.2lf ms.\n", runtimeAll); printf("%.2lf ms were spent at the CUDA part.\n", cudaRuntime); printf("So %.2lf ms were spent at the host.", runtimeAll - cudaRuntime); cudaFree(dPermutation); cudaFree(dCities); cudaFree(dLCGX); free(allMinPerm); free(LCGX); free(hPermutation); } }; void readFile(char* FILENAME) { FILE *fp; char line[80]; int i = 0; fp = fopen(FILENAME, "rt"); for (int i = 0; i < 6; i++) { fgets(line, 80, fp); if (i == 3) { char* pch = strtok(line, ":"); pch = strtok(NULL, "\t\n"); CITY_N = atoi(pch); } } cout<<"Number of cities is "<<CITY_N<<endl; cities = (struct city *) malloc (CITY_N * sizeof(struct city)); while (fgets(line, 80, fp) != NULL && i < CITY_N) { sscanf(line, "%*d %lf %lf", &(cities[i].x), &(cities[i].y)); ++i; } } void printCities(struct city *cities) { cout << "Cities: " << endl; for (int i = 0; i < CITY_N; ++i) cout << i << ". x: " << cities[i].x << " y: " << cities[i].y << endl; } int main(int argc, char* argv[]) { if (argc < 2) { printf("Usage: ./tsp inputFiles\n"); exit(-1); } readFile(argv[1]); int *order = (int *) malloc(CITY_N * sizeof(int)); float avgResult = 0.0f; double avgRuntime = 0.0f; for (int runs = 0; runs < NUMBER_RUNS; ++runs) { for (int i = 0; i < CITY_N; ++i) order[i] = i; //printCities(cities); Anneal *a = new Anneal(); a->order(cities, order); avgResult += a->resultCost / (NUMBER_RUNS * 1.0f); avgRuntime += a->runtime / (NUMBER_RUNS * 1.0f); } cout << endl << endl; cout << "Average Costs: " << avgResult << endl; cout << "Average Runtime: " << avgRuntime << endl; return 0; }
9,977
/* arrayfire: Fix race condition in reduce_first_kernel.*/ __global__ void warp_reduce(double *s_ptr) { int tidx = threadIdx.x; int tidy = threadIdx.y; double *s_ptr_vol = s_ptr + tidx; double tmp = *s_ptr; for (int n = 16; n >= 1; n >>= 1) { if (tidx < n) { double val1, val2; val1 = s_ptr_vol[0]; val2 = s_ptr_vol[n]; tmp = val1 + val2; s_ptr_vol[0] = tmp; } } }
9,978
#include <iostream> #include <chrono> __global__ void polynomial_expansion (float* poly,int degree,int n,float* array) { int index=blockIdx.x*blockDim.x+threadIdx.x; if(index<n) { float result=0.0; float exponent=1.0; for(int x=0;x<=degree;++x) { result+=exponent*poly[x]; exponent*=array[index]; } array[index]=result; } } int main(int argc, char* argv[]) { if(argc<3) { std::cerr<<"usage: "<<argv[0]<<" n degree"<<std::endl; return -1; } int n=atoi(argv[1]); int degree=atoi(argv[2]); int nbiter=1; float* array=new float[n]; float* poly=new float[degree+1]; for(int i=0;i<n;++i) { array[i]=1.; } for(int i=0;i<degree+1;++i) { poly[i]=1.; } float *d_array,*d_poly; //start calculating time std::chrono::time_point<std::chrono::system_clock> start_time,end_time; start_time = std::chrono::system_clock::now(); cudaMalloc(&d_array,n*sizeof(float)); cudaMalloc(&d_poly,(degree+1)*sizeof(float)); cudaMemcpy(d_array,array,n*sizeof(float),cudaMemcpyHostToDevice); cudaMemcpy(d_poly,poly,(degree+1)*sizeof(float),cudaMemcpyHostToDevice); polynomial_expansion<<<(n+255)/256, 256>>>(d_poly,degree,n,d_array); cudaMemcpy(array,d_array,n*sizeof(float),cudaMemcpyDeviceToHost); cudaFree(d_array); cudaFree(d_poly); cudaDeviceSynchronize(); { bool correct=true; int ind; for(int i=0;i<n;++i) { if(fabs(array[i]-(degree+1))>0.01) { correct=false; ind=i; } } if(!correct) std::cerr<<"Result is incorrect. In particular array["<<ind<<"] should be "<<degree+1<<" not "<< array[ind]<<std::endl; } // calculate and print time end_time=std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_time=(end_time-start_time)/nbiter; std::cout<<n<<" "<<degree<<" "<<elapsed_time.count()<<std::endl; // free arrays delete[] array; delete[] poly; return 0; }
9,979
// Each thread calculates part of fitness abs(y_i - y) // Result: matrix populationCnt*pointsCnt (row - individual; col - part of fitness) extern "C" __global__ void fitness_kernel(int populationCnt, int *population, int pointsCnt, float *pointsX, float *pointsY, float *result) { int gridDimX = gridDim.x; int blockDimX = blockDim.x; for (int i = blockIdx.x; i < populationCnt; i += gridDimX) { const int shift = 5*i; for (int p = threadIdx.x; p < pointsCnt; p += blockDimX) { const float x = pointsX[p]; const float y = pointsY[p]; float fApprox = population[shift + 4]; for (int k = 3; k >= 0; k--) { fApprox = fApprox * x + population[shift + k]; } fApprox /= 10.0f; result[i*pointsCnt + p] = abs(fApprox - y); } } }
9,980
#include <stdio.h> // listPrimes - shows the prime numbers between a fixed range. // Eric McCreath 2019 - GPL // based on https://en.wikipedia.org/wiki/Integer_square_root // assumes a positive number long intsquroot(long n) { long shift = 2; long nShifted = n >> shift; while (nShifted != 0 && nShifted != n) { shift += 2; nShifted = n >> shift; } shift -= 2; long result = 0; while (shift >= 0) { result = result << 1; long candidateResult = result + 1; if (candidateResult * candidateResult <= n >> shift) { result = candidateResult; } shift = shift - 2; } return result; } __device__ int prime[1]; __global__ void checkFactors(long v, long srt) { long idx = blockIdx.x * blockDim.x + threadIdx.x; long totalThreads = blockDim.x * gridDim.x; int check = 0; for (long i = idx + 2; i <= srt; i += totalThreads) { if (v % i == 0) { prime[0] = 0; } if (prime[0] == 0) break; } } // isPrime - just a simple loop to check if the number is divisible by // any number from 2 to the square root of the number int isPrime(long v) { long srt = intsquroot(v); int h_prime; h_prime = 1; cudaMemcpyToSymbol(prime, &h_prime, sizeof(int), 0); checkFactors<<<64, 128>>>(v, srt); cudaDeviceSynchronize(); cudaMemcpyFromSymbol(&h_prime, prime, sizeof(int), 0); return h_prime; } // listPrimes - check each number in the range void listPrimes(long start, long end) { for (long num = start; num < end; num++) { printf("%ld : %s\n", num, (isPrime(num) ? "yes" : "no")); } } /* * The only prime in the range below is 9223372036854775783 * Noting on my Intel i7-4790K it takes 23s to run. */ int main() { long largestlong = 0x7FFFFFFFFFFFFFFFL; listPrimes(largestlong - 100L, largestlong); return 0; }
9,981
//#include "xfasttrie-binary.cuh" //#include "Catch2/catch.hpp" //#include "cuda/api_wrappers.h" // //#include "xfasttrie-common.cuh" // //using XTrie = XFastTrieBinary<unsigned char, int>; //using XTrieKey = typename XTrie::key_type; //using XTrie3 = XFastTrieBinary<unsigned char, int, 3>; //using XTrie3Key = typename XTrie3::key_type; //using BigXTrie = XFastTrieBinary<int, int>; //using BigXTrieKey = typename BigXTrie::key_type; //using HugeXTrie = XFastTrieBinary<gpu::UInt64, int>; //using HugeXTrieKey = typename HugeXTrie::key_type; // //SCENARIO("X-FAST-TRIE-BINARY", "[XFASTTRIE][BINARY]") //{ // int memory_size_allocated = 8u * 1024 * 1024; // auto current_device = cuda::device::current::get(); // auto d_memory = cuda::memory::device::make_unique<char[]>(current_device, memory_size_allocated); // auto d_allocator = cuda::memory::device::make_unique<gpu::default_allocator>(current_device); // unsigned int number_warps = 1u; // // GIVEN("A X-fast trie for 2^3") // { // auto d_xtrie3 = cuda::memory::device::make_unique<XTrie3>(current_device); // cuda::launch( // initialize_allocator<XTrie3>, // { 1u, number_warps * 32u }, // d_allocator.get(), d_memory.get(), memory_size_allocated, d_xtrie3.get() // ); // // WHEN("We add different values") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_find<XTrie3>, // { 1u, number_warps * 32u }, // d_xtrie3.get() // ); // } // } // // WHEN("We try in increasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_increasing_order<XTrie3>, // { 1u, number_warps * 32u }, // d_xtrie3.get() // ); // } // } // // WHEN("We try again in decreasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_decreasing_order<XTrie3>, // { 1u, number_warps * 32u }, // d_xtrie3.get() // ); // } // } // // WHEN("We add different values") // { // THEN("Predecessor and successor should be conformed") // { // cuda::launch( // test_predecessor_successor<XTrie3>, // { 1u, number_warps * 32u }, // d_xtrie3.get() // ); // } // } // } // // GIVEN("A X-fast trie for 2^8") // { // auto d_xtrie = cuda::memory::device::make_unique<XTrie>(current_device); // cuda::launch( // initialize_allocator<XTrie>, // { 1u, number_warps * 32u }, // d_allocator.get(), d_memory.get(), memory_size_allocated, d_xtrie.get() // ); // // WHEN("We add different values") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_find<XTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We try in increasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_increasing_order<XTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We try again in decreasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_decreasing_order<XTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We add different values") // { // THEN("Predecessor and successor should be conformed") // { // cuda::launch( // test_predecessor_successor<XTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We add random values") // { // THEN("It should be ok") // { // cuda::launch( // test_random<XTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get(), 10 // ); // } // } // } // // GIVEN("A X-fast trie for 2^32") // { // auto d_xtrie = cuda::memory::device::make_unique<BigXTrie>(current_device); // cuda::launch( // initialize_allocator<BigXTrie>, // { 1u, number_warps * 32u }, // d_allocator.get(), d_memory.get(), memory_size_allocated, d_xtrie.get() // ); // // WHEN("We add different values") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_find<BigXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We try in increasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_increasing_order<BigXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We try again in decreasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_decreasing_order<BigXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We add different values") // { // THEN("Predecessor and successor should be conformed") // { // cuda::launch( // test_predecessor_successor<BigXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We add random values") // { // THEN("It should be ok") // { // cuda::launch( // test_random<BigXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get(), 10 // ); // } // } // } // // GIVEN("A X-fast trie for 2^64") // { // auto d_xtrie = cuda::memory::device::make_unique<HugeXTrie>(current_device); // cuda::launch( // initialize_allocator<HugeXTrie>, // { 1u, number_warps * 32u }, // d_allocator.get(), d_memory.get(), memory_size_allocated, d_xtrie.get() // ); // // WHEN("We add different values") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_find<HugeXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We try in increasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_increasing_order<HugeXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We try again in decreasing order") // { // THEN("We should be able to retrieve them") // { // cuda::launch( // test_insert_decreasing_order<HugeXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We add different values") // { // THEN("Predecessor and successor should be conformed") // { // cuda::launch( // test_predecessor_successor<HugeXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get() // ); // } // } // // WHEN("We add random values") // { // THEN("It should be ok") // { // cuda::launch( // test_random<HugeXTrie>, // { 1u, number_warps * 32u }, // d_xtrie.get(), 10 // ); // } // } // } //}
9,982
#include <cmath> #include "SamplingPoint.cuh" #include "CUDAHelper.cuh" SamplingPoint::SamplingPoint(const SamplingPoint &other) : _x(other._x), _y(other._y), _i (other._i), _s(other._s), _t(other._t), _fo(other._fo), _kernelSize(other._kernelSize), _kernel(nullptr), d_kernel(nullptr) { if (other._kernel != nullptr) { _kernel = new double[_kernelSize * _kernelSize]; memcpy(_kernel, other._kernel, sizeof(double) * _kernelSize * _kernelSize); } } SamplingPoint::~SamplingPoint() { if (_kernel != nullptr) delete [] _kernel; } double* SamplingPoint::setKernel(std::vector<double> kernel, bool overrideSize) { if (!overrideSize && kernel.size() != _kernelSize * _kernelSize) { return nullptr; } else { _kernelSize = sqrt(kernel.size()); if (_kernel != nullptr) delete [] _kernel; _kernel = new double[_kernelSize * _kernelSize]; for (int i = 0; i != _kernelSize * _kernelSize; ++i) { _kernel[i] = kernel.at(i); } if (d_kernel != nullptr) { cudaFree(d_kernel); cudaMalloc((void**)&d_kernel, sizeof(double) * _kernelSize * _kernelSize); cudaMemcpy(d_kernel, _kernel, sizeof(double) * _kernelSize * _kernelSize, cudaMemcpyHostToDevice); } return _kernel; } } void SamplingPoint::copyToDevice() { if (_kernel == nullptr) return; if (d_kernel != nullptr) { cudaFree(d_kernel); } cudaMalloc((void**)&d_kernel, sizeof(double) * _kernelSize * _kernelSize); cudaMemcpy(d_kernel, _kernel, sizeof(double) * _kernelSize * _kernelSize, cudaMemcpyHostToDevice); cudaCheckErrors("ERROR"); } void SamplingPoint::removeFromDevice() { if (d_kernel == nullptr) return; cudaFree(d_kernel); d_kernel = nullptr; cudaCheckErrors("ERROR"); }
9,983
#include <cassert> #include <functional> struct state { int row; int left; int down; int right; }; __global__ void count_solutions(int size, int *count, state *initial_states, int num_initial_states) { const auto thread_index = blockIdx.x * blockDim.x + threadIdx.x; if (thread_index >= num_initial_states) return; constexpr const auto MaxStackSize = 200; state stack[MaxStackSize]; stack[0] = initial_states[thread_index]; auto stack_top = 1; while (stack_top > 0) { const auto &cur_state = stack[--stack_top]; const auto row = cur_state.row; const auto left = cur_state.left; const auto down = cur_state.down; const auto right = cur_state.right; if (row == size) { atomicAdd(count, 1); } else { const auto used = ~(left | down | right); for (auto bit = 1; bit != 1 << size; bit <<= 1) { if (bit & used) { assert(stack_top < MaxStackSize); auto &state = stack[stack_top++]; state.row = row + 1; state.left = (left | bit) << 1; state.down = down | bit; state.right = (right | bit) >> 1; } } } } } int count_solutions_cuda(int size) { constexpr const auto MaxParallelLevel = 5; constexpr const auto MaxInitialStates = 20000000; state *initial_states; cudaMallocManaged(&initial_states, MaxInitialStates * sizeof *initial_states); int num_initial_states = 0; const std::function<void(int, int, int, int, int)> populate_initial_states = [initial_states, &num_initial_states, &populate_initial_states](int row, int left, int down, int right, int size) { assert(row <= MaxParallelLevel); const auto used = ~(left | down | right); for (auto bit = 1; bit != 1 << size; bit <<= 1) { if (bit & used) { if (row < MaxParallelLevel) { populate_initial_states(row + 1, (left | bit) << 1, down | bit, (right | bit) >> 1, size); } else { assert(num_initial_states < MaxInitialStates); initial_states[num_initial_states++] = {row + 1, (left | bit) << 1, down | bit, (right | bit) >> 1}; } } } }; populate_initial_states(0, 0, 0, 0, size); int *count; cudaMallocManaged(&count, sizeof count); *count = 0; constexpr const auto ThreadsPerBlock = 256; const auto num_blocks = (num_initial_states + ThreadsPerBlock - 1) / ThreadsPerBlock; count_solutions<<<num_blocks, ThreadsPerBlock>>>(size, count, initial_states, num_initial_states); cudaDeviceSynchronize(); const auto result = *count; cudaFree(count); cudaFree(initial_states); return result; }
9,984
#include "includes.h" __global__ void MatrixMulKernel(float* d_M, float* d_N, float* d_P, int Width) { // Calculate the row index of the d_Pelement and d_M int Row = blockIdx.y*blockDim.y+threadIdx.y; // Calculate the column index of d_P and d_N int Col = blockIdx.x*blockDim.x+threadIdx.x; if ((Row < Width) && (Col < Width)) { float Pvalue = 0; // each thread computes one element of the block sub-matrix for (int k = 0; k < Width; ++k) { Pvalue += d_M[Row*Width+k]*d_N[k*Width+Col]; } d_P[Row*Width+Col] = Pvalue; } }
9,985
#include <stdio.h> #define T 64 #define n 256 __global__ void vecAdd(int *A, int *B, int *C) { int i = blockIdx.x*blockDim.x+threadIdx.x; C[i] = A[i]; } int main (int argc, char *argv[]){ int i; int size = n*sizeof(int); int a[n], b[n], c[n], *devA, *devB, *devC; for (i=0; i< n; i++){ a[i] = i; } cudaMalloc( (void**)&devA,size); cudaMalloc( (void**)&devB,size); cudaMalloc( (void**)&devC,size); cudaMemcpy( devA, a, size, cudaMemcpyHostToDevice); cudaMemcpy( devB, b, size, cudaMemcpyHostToDevice); vecAdd<<<n/T, T>>>(devA, devB, devC); cudaMemcpy(c, devC, size, cudaMemcpyDeviceToHost); cudaFree(devA); cudaFree(devB); cudaFree(devC); for (i=0; i < n; i++) { printf("%d ",c[i]); } printf("\n"); }
9,986
/* * use global to indicate function runs on the device. */ #include <stdio.h> /* cuda c keyword __global__ indicates that a function * is run on the device and called from the host. * * nvcc will split the source into host and device * components. the nvidia compiler will handle functions * like kernel(), whilst gcc will handle rest. */ __global__ void kernel(void) { } int main(void) { /* "kernel launch" * a call from host code to device code */ kernel<<<1,1>>>(); printf("hi again.\n"); return 0; }
9,987
#include <cmath> #include <iostream> #include <thrust/extrema.h> #include <thrust/device_vector.h> #define HANDLE_ERROR(err) \ do { if (err != cudaSuccess) { printf("ERROR: %s\n", cudaGetErrorString(err)); exit(0);} } while (0) struct comparator { __host__ __device__ bool operator()(double a, double b) { return std::fabs(a) < std::fabs(b); } }; __global__ void swapRows(double *data, int n, int i, int i_max) { int idx = blockDim.x * blockIdx.x + threadIdx.x; int offset = blockDim.x * gridDim.x; for (int j = idx; j < n; j += offset) { double tmp = data[j * n + i]; data[j * n + i] = data[j * n + i_max]; data[j * n + i_max] = tmp; } } __global__ void divide(double *data, int n, int i) { int idx = blockDim.x * blockIdx.x + threadIdx.x; int offset = blockDim.x * gridDim.x; for (int j = idx + i + 1; j < n; j += offset) { data[i * n + j] /= data[i * n + i]; } } __global__ void kernel(double *data, int n, int i) { int idx = blockDim.x * blockIdx.x + threadIdx.x; int idy = blockDim.y * blockIdx.y + threadIdx.y; int offsetx = blockDim.x * gridDim.x; int offsety = blockDim.y * gridDim.y; for (int j = idx + i + 1; j < n; j += offsetx) { for (int k = idy + i + 1; k < n; k += offsety) { data[k * n + j] -= data[i * n + j] * data[k * n + i]; } } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; double *mat = new double[n * n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { std::cin >> mat[i + j * n]; } } int *p = new int[n]; for (int i = 0; i < n; ++i) { p[i] = i; } double *data; HANDLE_ERROR(cudaMalloc((void **) &data, sizeof(double) * n * n)); HANDLE_ERROR(cudaMemcpy(data, mat, sizeof(double) * n * n, cudaMemcpyHostToDevice)); comparator comp; thrust::device_ptr<double> i_ptr, i_max_ptr; for (int i = 0; i < n - 1; ++i) { int i_max = i; i_ptr = thrust::device_pointer_cast(data + i * n); i_max_ptr = thrust::max_element(i_ptr + i, i_ptr + n, comp); i_max = i_max_ptr - i_ptr; if (i_max != i) { p[i] = i_max; swapRows<<<256, 256>>>(data, n, i, i_max); } divide<<<256, 256>>>(data, n, i); kernel<<<dim3(32, 32), dim3(32, 32)>>>(data, n, i); } cudaMemcpy(mat, data, sizeof(double) * n * n, cudaMemcpyDeviceToHost); std::cout.precision(10); std::cout.setf(std::ios::scientific); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { std::cout << mat[i + j * n] << " "; } std::cout << "\n"; } for (int i = 0; i < n; ++i) { std::cout << p[i] << " "; } std::cout << "\n"; HANDLE_ERROR(cudaFree(data)); delete[] mat; delete[] p; return 0; }
9,988
//#include "MemoryManagerGPU.h" //#include "cuda_runtime_api.h" // //void MemoryManagerGPU::AllocateMemoryForPrimitives() { // // Vertex3D* device_vertexs; // Normal3D* device_normals; // Polygon3D* device_polygons; // // longSize vertexs_size = host_data_info_.numberOfVertexs * sizeof(Vertex3D); // longSize normals_size = host_data_info_.numberOfNormals * sizeof(Normal3D); // longSize polygons_size = host_data_info_.numberOfPolygons * sizeof(Polygon3D); // // cudaMalloc((void **)&device_vertexs, vertexs_size); // cudaMalloc((void**)&device_normals, normals_size); // cudaMalloc((void**)&device_polygons, polygons_size); // // cudaMemcpy(device_vertexs, host_data_info_.allVertexs, vertexs_size, cudaMemcpyHostToDevice); // cudaMemcpy(device_normals, host_data_info_.allNormals, normals_size, cudaMemcpyHostToDevice); // cudaMemcpy(device_polygons, host_data_info_.allPolygons, polygons_size, cudaMemcpyHostToDevice); // // this->device_data_info_.deviceVertexs = device_vertexs; // this->device_data_info_.deviceNormals = device_normals; // this->device_data_info_.devicePolygons = device_polygons; // //} // //void MemoryManagerGPU::AllocateMemoryForBuffer() //{ // // cudaMalloc((void**)& this->device_display_buffer_, this->display_buffer_size_); // //}
9,989
#pragma once #include "cuda.h"
9,990
#include <stdio.h> __global__ void kernel(int* a, int* b, int* c) { *c = *a + *b; } int main() { int a, b, c; int *d_a, *d_b, *d_c; a = 7; b = 8; cudaMalloc((void **)&d_a, sizeof(int)); cudaMalloc((void **)&d_b, sizeof(int)); cudaMalloc((void **)&d_c, sizeof(int)); cudaMemcpy(d_a, &a, sizeof(int), cudaMemcpyHostToDevice); cudaMemcpy(d_b, &b, sizeof(int), cudaMemcpyHostToDevice); kernel<<<1, 1>>>(d_a, d_b, d_c); cudaMemcpy(&c, d_c, sizeof(int), cudaMemcpyDeviceToHost); printf("Asd %d\n", c); return 0; }
9,991
#include <iostream> #include <cuda_profiler_api.h> #include <sys/time.h> #define STREAMS_NUM 8 __global__ void plus(float *a, float *b, float *c, int n, int offset) { int i = blockIdx.x*blockDim.x + threadIdx.x + offset; c[i] = a[i] + b[i]; } int main(void){ int n = 1024*1024; int size = n*sizeof(float); struct timeval start, end; float *a, *b; float *c; cudaHostAlloc( (void**) &a, size ,cudaHostAllocDefault ); cudaHostAlloc( (void**) &b, size ,cudaHostAllocDefault ); cudaHostAlloc( (void**) &c, size ,cudaHostAllocDefault ); float *a_d,*b_d,*c_d; for(int i=0; i < n; i++) { a[i] = 20.0; b[i] = 10.0; } cudaMalloc((void **)&a_d,size); cudaMalloc((void **)&b_d,size); cudaMalloc((void **)&c_d,size); const int StreamSize = n / STREAMS_NUM; cudaStream_t Stream[STREAMS_NUM]; for (int i = 0; i < STREAMS_NUM; i++) cudaStreamCreate(&Stream[i]); dim3 block(1024); dim3 grid((n- 1)/1024 + 1); gettimeofday( &start, NULL ); for ( int i = 0; i < STREAMS_NUM; i++) { int Offset = i * StreamSize; cudaMemcpyAsync(&a_d[Offset], &a[Offset], StreamSize * sizeof(float), cudaMemcpyHostToDevice, Stream[i]); cudaMemcpyAsync(&b_d[Offset], &b[Offset], StreamSize * sizeof(float), cudaMemcpyHostToDevice, Stream[i]); cudaMemcpyAsync(&c_d[Offset], &c[Offset], StreamSize * sizeof(float), cudaMemcpyHostToDevice, Stream[i]); plus<<<grid, block>>>(a_d, b_d, c_d, StreamSize, Offset); cudaMemcpyAsync(&a[Offset], &a_d[Offset], StreamSize * sizeof(float), cudaMemcpyDeviceToHost, Stream[i]); cudaMemcpyAsync(&b[Offset], &b_d[Offset], StreamSize * sizeof(float), cudaMemcpyDeviceToHost, Stream[i]); cudaMemcpyAsync(&c[Offset], &c_d[Offset], StreamSize * sizeof(float), cudaMemcpyDeviceToHost, Stream[i]); } gettimeofday(&end,NULL); int timeuseGPU = 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec; std::cout<<"total time use in GPU-Stream is "<<timeuseGPU<<" us "<<std::endl; cudaFree(a_d); cudaFree(b_d); cudaFree(c_d); cudaFreeHost(a); cudaFreeHost(b); cudaFreeHost(c); }
9,992
#include "includes.h" __global__ void Kernel01 (int N, int M, int P, float *A, float *B, float *C) { int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; if (row < N && col < M) { float tmp = 0.0; for (int k=0; k<P; k++) tmp += A[row*P+k] * B[k*N+col]; C[row*N+col] = tmp; } }
9,993
#include "includes.h" __global__ void update_array_two_gpu(int m, int n, int i, int numberOfThreadsRequired, int count, int oldCount, int *d_array ) { long j=blockIdx.x *blockDim.x + threadIdx.x; if (j> numberOfThreadsRequired) {} else { d_Z2 = d_A2 + 1; if (j < n) { d_Z1 = d_A1 + 1; } } }
9,994
__global__ void test(float *A, const int N){ int i = threadIdx.x; float x = A[i+1]; if (i < N){ A[i] = x; // DR } }
9,995
#include "includes.h" __global__ void add(int* a, int* b, int* c) { int id = threadIdx.x; if (id < N) { c[id] = b[id] + a[id]; } }
9,996
/* Shared memory is allocated per thread block, so all threads in the block have access to the same shared memory. Threads can access data in shared memory loaded from global memory by other threads within the same thread block. To ensure correct results when parallel threads cooperate, we must synchronize the threads. CUDA provides a simple barrier synchronization primitive, __syncthreads(). A thread’s execution can only proceed past a __syncthreads() after all threads in its block have executed the __syncthreads(). This code reverses the data in a 64-element array using shared memory. The two kernels are very similar, differing only in how the shared memory arrays are declared and how the kernels are invoked. */ #include <iostream> __global__ void staticReverse(int *device_array, size_t array_size){ __shared__ int shared_array[64]; int thread_id = threadIdx.x; int thread_position_to_swap = array_size - thread_id - 1; shared_array[thread_id] = device_array[thread_id]; __syncthreads(); device_array[thread_id] = shared_array[thread_position_to_swap]; } __global__ void dynamicReverse(int *device_array, size_t array_size){ extern __shared__ int shared_array[]; int thread_id = threadIdx.x; int thread_position_to_swap = array_size - thread_id - 1; shared_array[thread_id] = device_array[thread_id]; __syncthreads(); device_array[thread_id] = shared_array[thread_position_to_swap]; } int main(){ const size_t array_size = 64; int host_array[array_size], host_result[array_size], host_check[array_size]; for(size_t i = 0; i != array_size; ++i){ host_array[i] = i; host_check[i] = array_size - i - 1; host_result[i] = 0; } int *device_array; cudaMalloc(&device_array, array_size * sizeof(int)); // Run version with static shared memory cudaMemcpy(device_array, host_array, array_size * sizeof(int), cudaMemcpyHostToDevice); staticReverse<<<1, array_size>>>(device_array, array_size); cudaMemcpy(host_result, device_array, array_size * sizeof(int), cudaMemcpyDeviceToHost); // Check result for(size_t i = 0; i != array_size; ++i){ if(host_result[i] != host_check[i]){ std::cout << " Static - Mismatch found in position : " << i << " - " << host_result[i] << " != " << host_check[i] << '\n'; } } // Run version with dynamic shared memory cudaMemcpy(device_array, host_array, array_size * sizeof(int), cudaMemcpyHostToDevice); dynamicReverse<<<1, array_size, array_size * sizeof(int)>>>(device_array, array_size); cudaMemcpy(host_result, device_array, array_size * sizeof(int), cudaMemcpyDeviceToHost); // Check result for(size_t i = 0; i != array_size; ++i){ if(host_result[i] != host_check[i]){ std::cout << " Dynamic - Mismatch found in position : " << i << " - " << host_result[i] << " != " << host_check[i] << '\n'; } } std::cout << "***SUCCESSFULLY EXECUTED!***" <<std::endl; }
9,997
/* Jaitirth Jacob - 13CO125 Vidit Bhargava - 13CO151 */ #include <stdio.h> int main() { int count; cudaGetDeviceCount(&count); printf("Device Queries:\n"); printf("There are %d CUDA devices.\n", count); for (int i = 0; i < count; ++i) { printf("\nCUDA Device #%d\n", i); cudaDeviceProp devProp; cudaGetDeviceProperties(&devProp, i); printf("\tDevice Identification: %s\n", devProp.name); printf("\tGlobal memory: %u\n", devProp.totalGlobalMem); printf("\tShared memory per block: %u\n", devProp.sharedMemPerBlock); printf("\tNumber of registers per block: %d\n", devProp.regsPerBlock); printf("\tNumber of thread in warp: %d\n", devProp.warpSize); printf("\tMaximum threads per block: %d\n", devProp.maxThreadsPerBlock); for (int i = 0; i < 3; ++i) printf("\tMaximum dimension %d of block: %d\n", i, devProp.maxThreadsDim[i]); for (int i = 0; i < 3; ++i) printf("\tMaximum dimension %d of grid: %d\n", i, devProp.maxGridSize[i]); printf("\tAvailable constant memory: %u\n", devProp.totalConstMem); printf("\tMajor revision number: %d\n", devProp.major); printf("\tMinor revision number: %d\n", devProp.minor); printf("\tNumber of multiprocessors: %d\n", devProp.multiProcessorCount); printf("\tClock rate: %d\n", devProp.clockRate); } return 0; }
9,998
// // Created by klaus on 12.07.21. // #include "GPUWriter.cuh" #include <iostream> #include <fstream> #include <string> #include <ios> #include <queue> GPUWriter::GPUWriter(std::string outputFile){ this->FILENAME = outputFile; } void GPUWriter::addUnitStream(std::string name, std::shared_ptr<GPUUnitStream> unitStream) { this->unit_streams.push_back(unitStream); this->unit_names.push_back(name); } void GPUWriter::addIntStream(std::string name, std::shared_ptr<GPUIntStream> intStream) { this->int_streams.push_back(intStream); this->int_names.push_back(name); } void GPUWriter::writeOutputFile() { // Open output file std::ofstream f; f.open(FILENAME); // Priority queue of streams to be put in std::priority_queue<std::tuple<int, int, bool>, std::deque<std::tuple<int, int, bool>>, std::greater<std::tuple<int, int, bool>>> sorter; // Current positions in stream int* int_positions = (int*) calloc(this->int_streams.size(), sizeof (int)); int* unit_positions = (int*) calloc(this->unit_streams.size(), sizeof (int)); int* int_sizes = (int*) malloc(this->int_streams.size()*sizeof (int)); int* unit_sizes = (int*) malloc(this->unit_streams.size()*sizeof (int)); if (int_positions == nullptr || unit_positions == nullptr || int_sizes == nullptr || unit_sizes == nullptr) { throw std::runtime_error("Out of memory. Cannot sort output streams."); } // Populate data structures int i = 0; for (auto & stream : int_streams) { // Save position int_sizes[i] = sizeof(stream->host_timestamp)/sizeof(int); sorter.push(std::make_tuple(stream->host_timestamp[0], i, true)); i++; } i = 0; for (auto & stream : unit_streams) { // Save position unit_sizes[i] = sizeof(stream->host_timestamp)/sizeof(int); sorter.push(std::make_tuple(stream->host_timestamp[0], i, false)); i++; } std::tuple<int, int, bool> current; // Traverse the priority queue while (true) { // Check if queue is empty if (sorter.empty()) break; // Get the first element and write it to the file current = sorter.top(); int timestamp = std::get<0>(current); int index = std::get<1>(current); bool isIntStream = std::get<2>(current); // switch depending on stream type if (isIntStream) { auto s = int_streams[index]; int p = int_positions[index]; f << s->host_timestamp[p] << ": " << int_names[index] << " = " << s->host_values[p] << "\n"; p = ++int_positions[index]; if (int_positions[index] < int_sizes[index]) { sorter.push(std::make_tuple(s->host_timestamp[p], index, true)); } } else { auto s = unit_streams[index]; int p = unit_positions[index]; f << s->host_timestamp[p] << ": " << unit_names[index] << " = ()\n"; p = ++unit_positions[index]; if (unit_positions[index] < unit_sizes[index]) { sorter.push(std::make_tuple(s->host_timestamp[p], index, false)); } } // Remove the first element sorter.pop(); } // Free streams for (auto &stream : unit_streams) { stream->free_host(); } for (auto &stream : int_streams) { stream->free_host(); } // Close the file and free the position array f.close(); delete int_positions; delete unit_positions; delete int_sizes; delete unit_sizes; }
9,999
#include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct { int width; int height; float *elements; } Matrix; #define BLOCK_SIZE 16 clock_t cpu_startTime, cpu_endTime, gpu_startTime, gpu_endTime; double cpu_elapseTime, gpu_elapseTime; __global__ void MatMulKernel(const Matrix, const Matrix, Matrix); void MatMulCPU(const Matrix A, const Matrix B, Matrix C) { // M(row, col) = *(M.elements + row * M.width + col) int i, j, k; for (i = 0; i < A.height; i++) { for (j = 0; j < B.width; j++) { *(C.elements + i * C.width + j) = 0; for (k = 0; k < A.width; k++) { *(C.elements + i * C.width + j) += (*(A.elements + i * A.width + k)) * (*(B.elements + k * B.width + j)); } } } } void MatMulGPU(const Matrix A, const Matrix B, Matrix C) { Matrix d_A; d_A.width = A.width; d_A.height = A.height; size_t size = A.width * A.height * sizeof(float); cudaMalloc((void **)&d_A.elements, size); cudaMemcpy(d_A.elements, A.elements, size, cudaMemcpyHostToDevice); Matrix d_B; d_B.width = B.width; d_B.height = B.height; size = B.width * B.height * sizeof(float); cudaMalloc((void **)&d_B.elements, size); cudaMemcpy(d_B.elements, B.elements, size,cudaMemcpyHostToDevice); Matrix d_C; d_C.width = C.width; d_C.height = C.height; size = C.width * C.height * sizeof(float); cudaMalloc((void **)&d_C.elements, size); gpu_startTime = clock(); dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE); dim3 dimGrid(B.width / dimBlock.x, A.height / dimBlock.y); MatMulKernel<<<dimGrid, dimBlock>>>(d_A, d_B, d_C); gpu_endTime = clock(); gpu_elapseTime = ((gpu_endTime - gpu_startTime)/(double)CLOCKS_PER_SEC); cudaMemcpy(C.elements, d_C.elements, size, cudaMemcpyDeviceToHost); cudaFree(d_A.elements); cudaFree(d_B.elements); cudaFree(d_C.elements); } __global__ void MatMulKernel(Matrix A, Matrix B, Matrix C) { float Cvalue = 0; int row = blockIdx.y * blockDim.y + threadIdx.y; int col = blockIdx.x * blockDim.x + threadIdx.x; for (int e = 0; e < A.width; ++e) Cvalue += A.elements[row * A.width + e] * B.elements[e * B.width + col]; C.elements[row * C.width + col] = Cvalue; } int main(int argc, char** argv) { srand((unsigned int)time(NULL)); int i = 0; Matrix A; A.width = 1600; A.height = 1600; A.elements = (float*)malloc(A.width * A.height * sizeof(float)); Matrix B; B.width = 1600; B.height = 1600; B.elements = (float*)malloc(B.width * B.height * sizeof(float)); Matrix C; C.width = B.width; C.height = A.height; C.elements = (float*)malloc(C.height * C.width * sizeof(float)); Matrix D; D.width = B.width; D.height = A.height; D.elements = (float*)malloc(D.height * D.width * sizeof(float)); for (i = 0; i < A.height * A.width; i++) { A.elements[i] = (float)rand()/(float)(RAND_MAX); B.elements[i] = (float)rand()/(float)(RAND_MAX); } //CPU: cpu_startTime = clock(); MatMulCPU(A, B, C); cpu_endTime = clock(); cpu_elapseTime = ((cpu_endTime - cpu_startTime)/(double)CLOCKS_PER_SEC); for (i = 0; i < 10; i++) { printf("%f ", C.elements[i]); } printf("\nCPU time: %f ms\n", cpu_elapseTime); //GPU: MatMulGPU(A, B, D); for (i = 0; i < 10; i++) { printf("%f ", D.elements[i]); } printf("\nGPU time: %f ms\n", gpu_elapseTime); free(A.elements); free(B.elements); free(C.elements); free(D.elements); return 0; } //Dla macierzy 32x64: CPU 0,000963ms, GPU 0,000014ms (z przesyłlniem danych - 0,96053ms) //Dla macierzy 1600x1600: CPU 37,0357ms, GPU 0,00002 ms
10,000
#include "leaky-relu-grad.hh" #include "graph.hh" #include "../runtime/node.hh" #include "../memory/alloc.hh" namespace ops { LeakyReluGrad::LeakyReluGrad(Op* z, Op* dout, dbl_t alpha) : Op("leaky_relu_grad", z->shape_get(), {z, dout}) , alpha_(alpha) {} void LeakyReluGrad::compile() { auto& g = Graph::instance(); auto& cz_out = g.compiled(preds()[0]); auto& cdout = g.compiled(preds()[1]); std::size_t len = cz_out.out_shape.total(); Shape out_shape = cz_out.out_shape; dbl_t* out_data = tensor_alloc(len); auto out_node = rt::Node::op_leaky_relu_grad(cz_out.out_data, cdout.out_data, out_data, alpha_, len, {cz_out.out_node, cdout.out_node}); g.add_compiled(this, {out_node}, {out_data}, out_node, out_shape, out_data); } }