From 8da0df3ee72d360aef8d26bc1186853477c76cbd Mon Sep 17 00:00:00 2001 From: Jiabing Li Date: Thu, 8 Feb 2018 16:01:25 -0600 Subject: [PATCH] whatever --- python/network.py | 4 ++-- python/network_dpy.py | 1 - stim/cuda/templates/gaussian_blur.cuh | 35 +++++++++++++++++++---------------- stim/image/image.h | 4 ++-- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/python/network.py b/python/network.py index 584e3ad..f6906c7 100644 --- a/python/network.py +++ b/python/network.py @@ -318,14 +318,14 @@ class Network: R = (200, 200, 200) #generate a meshgrid of the appropriate size and resolution to surround the network - lower, upper = self.aabb(self.N, self.F) #get the space occupied by the network + lower, upper = self.aabb() #get the space occupied by the network x = np.linspace(lower[0], upper[0], R[0]) #get the grid points for uniform sampling of this space y = np.linspace(lower[1], upper[1], R[1]) z = np.linspace(lower[2], upper[2], R[2]) X, Y, Z = np.meshgrid(x, y, z) #Z = 150 * numpy.ones(X.shape) - + Q = np.stack((X, Y, Z), 3) diff --git a/python/network_dpy.py b/python/network_dpy.py index 72bb428..c326d89 100644 --- a/python/network_dpy.py +++ b/python/network_dpy.py @@ -14,7 +14,6 @@ import math -alkjasfdljkhfsadlkjhfsad class Point: def __init__(self, x, y, z, radius): self.x = x diff --git a/stim/cuda/templates/gaussian_blur.cuh b/stim/cuda/templates/gaussian_blur.cuh index 1165bd7..7f90bd2 100644 --- a/stim/cuda/templates/gaussian_blur.cuh +++ b/stim/cuda/templates/gaussian_blur.cuh @@ -9,34 +9,34 @@ namespace stim{ - namespace cuda{ + namespace cuda { template - void gen_gaussian(T* out, T sigma, unsigned int width){ + void gen_gaussian(T* out, T sigma, unsigned int width) { //fill the kernel with a gaussian - for(unsigned int xi = 0; xi < width; xi++){ + for (unsigned int xi = 0; xi < width; xi++) { - float x = (float)xi - (float)(width/2); //calculate the x position of the gaussian - float g = 1.0 / (sigma * sqrt(2 * 3.14159)) * exp( - (x*x) / (2*sigma*sigma) ); + float x = (float)xi - (float)(width / 2); //calculate the x position of the gaussian + float g = 1.0 / (sigma * sqrt(2 * 3.14159)) * exp(-(x*x) / (2 * sigma*sigma)); out[xi] = g; } } template - void tex_gaussian_blur2(T* out, T sigma, unsigned int x, unsigned int y, cudaTextureObject_t texObj, cudaArray* cuArray){ + void tex_gaussian_blur2(T* out, T sigma, unsigned int x, unsigned int y, cudaTextureObject_t texObj, cudaArray* cuArray) { //allocate space for the kernel unsigned int kwidth = sigma * 8 + 1; - float* kernel0 = (float*) malloc( kwidth * sizeof(float) ); + float* kernel0 = (float*)malloc(kwidth * sizeof(float)); //fill the kernel with a gaussian gen_gaussian(kernel0, sigma, kwidth); //copy the kernel to the GPU T* gpuKernel0; - HANDLE_ERROR(cudaMalloc(&gpuKernel0, kwidth*sizeof(T))); + HANDLE_ERROR(cudaMalloc(&gpuKernel0, kwidth * sizeof(T))); HANDLE_ERROR(cudaMemcpy(gpuKernel0, kernel0, kwidth * sizeof(T), cudaMemcpyHostToDevice)); //perform the gaussian blur as a separable convolution @@ -48,18 +48,18 @@ namespace stim{ } template - void gpu_gaussian_blur2(T* image, T sigma, unsigned int x, unsigned int y){ + void gpu_gaussian_blur2(T* image, T sigma, unsigned int x, unsigned int y) { //allocate space for the kernel unsigned int kwidth = sigma * 8 + 1; - float* kernel0 = (float*) malloc( kwidth * sizeof(float) ); + float* kernel0 = (float*)malloc(kwidth * sizeof(float)); //fill the kernel with a gaussian gen_gaussian(kernel0, sigma, kwidth); //copy the kernel to the GPU T* gpuKernel0; - HANDLE_ERROR(cudaMalloc(&gpuKernel0, kwidth*sizeof(T))); + HANDLE_ERROR(cudaMalloc(&gpuKernel0, kwidth * sizeof(T))); HANDLE_ERROR(cudaMemcpy(gpuKernel0, kernel0, kwidth * sizeof(T), cudaMemcpyHostToDevice)); //perform the gaussian blur as a separable convolution @@ -71,21 +71,24 @@ namespace stim{ /// Applies a Gaussian blur to a 2D image stored on the CPU template - void cpu_gaussian_blur2(T* image, T sigma, unsigned int x, unsigned int y){ + void cpu_gaussian_blur2(T* image, T sigma, unsigned int x, unsigned int y, float &gpu_time) { + gpuTimer_start(); //allocate space for the kernel unsigned int kwidth = sigma * 8 + 1; - float* kernel0 = (float*) malloc( kwidth * sizeof(float) ); + float* kernel0 = (float*)malloc(kwidth * sizeof(float)); //fill the kernel with a gaussian gen_gaussian(kernel0, sigma, kwidth); //perform the gaussian blur as a separable convolution stim::cuda::cpu_conv2sep(image, x, y, kernel0, kwidth, kernel0, kwidth); - + gpu_time = gpuTimer_end(); + } + - }; -}; + } +} #endif diff --git a/stim/image/image.h b/stim/image/image.h index f85baca..8ead34a 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -276,8 +276,8 @@ public: allocate(cols, rows, channels); //allocate space for the image size_t img_bytes = bytes(); unsigned char* cv_ptr = (unsigned char*)cvImage.data; - if (C() == 1) //if this is a single-color image, just copy the data - type_copy(cv_ptr, img, size()); + //if (C() == 1) //if this is a single-color image, just copy the data + type_copy(cv_ptr, img, size()); //memcpy(img, cv_ptr, bytes()); if(C() == 3) //if this is a 3-color image, OpenCV uses BGR interleaving from_opencv(cv_ptr, X(), Y()); -- libgit2 0.21.4