Changes

Jump to: navigation, search

BarraCUDA Boiz

1,472 bytes removed, 20:25, 13 April 2017
Assignment 3
[[File:Set Samples.png]]
__global__ void setSamples(cv[[File::cuda::PtrStepSz<float> samples, cv::cuda::PtrStepSz<uchar> img, int dimC) { int i = blockIdx.y*blockDim.y + threadIdx.y; int j = blockIdx.x*blockDim.x + threadIdx.x; if (i >= imgSetSamplesKernelOptimized.rows |png| j >= img.cols) return; int index = i * img.cols + j; int y_index = j * dimC; for (int d = 0; d<dimC; d++) { samples(index, d) = (float)img(i, y_index + d); } }550px]]
[[File:Calculate Distance Kernel.png]]
__global__ void calculateDistance(cv::cuda::PtrStepSz<float> centers, cv::cuda:[[File:PtrStepSz<float> samples, int k, int N, int dim, double* minval, float* D) { // Compute distances between already sampled centers and other input samples. // Update nearest distance if it is smaller than previous ones. int col = blockIdx.x * blockDim.x + threadIdx.x; int row = blockIdx.y * blockDim.y + threadIdx.y; int i = col + row * N; //int i = blockIdx.y*blockDim.y + threadIdxCalculateDistanceKernelOptimized.y; if (i >= N) return; double dist = 0.0; int k_diff = k - 1; for (int d = 0; d<dim; d++) { double diff = centers(k_diff, d) - samples(i, d); dist += diff * diff; } if (dist < minval[i]) { minval[ipng|550px] = dist; } *D += minval[i]; }
[[File:Generate Image Kernel.png]]
__global__ void generateImage(cv[[File::cuda::PtrStepSz<uchar> out, cv::cuda::PtrStepSz<int> indices, cv::cuda::PtrStepSz<float> centers, int dim) { // Generate output image int i = blockIdx.y*blockDim.y + threadIdx.y; int j = blockIdx.x*blockDim.x + threadIdxGenerateImageKernelOptimized.x; if (i >= out.rows png|| j >= out.cols) return; int index = i * out.cols + j; int ci = indices(index, 0); int y_index = j*dim; for (int d = 0; d<dim; d++) { out(i, y_index + d) = (uchar)centers(ci, d); } }550px]]
52
edits

Navigation menu