diff --git a/python/network_dpy.py b/python/network_dpy.py new file mode 100644 index 0000000..1dbb8ae --- /dev/null +++ b/python/network_dpy.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Jan 19 2018 + +@author: Jiabing +""" + +import struct +import numpy as np +import scipy as sp +import networkx as nx +import matplotlib.pyplot as plt +import math + +class Point: + def __init__(self, x, y, z, radius): + self.x = x + self.y = y + self.z = z + self.r = radius + + +class Fiber: + def __init__(self, fiber_idx,point_idx): + self.fidx = fiber_idx + self.pidx = point_idx + + + +class Node: + def __init__(self, point_idx, fidx): + self.pidx= point_idx + self.fidx = fidx + + +#class NWT: + +#class network(point, Fiber, Node): \ No newline at end of file diff --git a/stim/iVote/ivote2.cuh b/stim/iVote/ivote2.cuh index 47e388e..f10fec3 100644 --- a/stim/iVote/ivote2.cuh +++ b/stim/iVote/ivote2.cuh @@ -152,13 +152,17 @@ namespace stim { template - void cpu_ivote2(T* cpuI, unsigned int rmax, size_t x, size_t y, bool invert = false, T t = 0, int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { + void cpu_ivote2(T* cpuI, unsigned int rmax, size_t x, size_t y, float &gpu_time, bool invert = false, T t = 0, int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { size_t bytes = x*y * sizeof(T); T* gpuI; //allocate space on the gpu to save the input image + + gpuTimer_start(); HANDLE_ERROR(cudaMalloc(&gpuI, bytes)); HANDLE_ERROR(cudaMemcpy(gpuI, cpuI, bytes, cudaMemcpyHostToDevice)); //copy the image to the gpu stim::gpu_ivote2(gpuI, rmax, x, y, invert, t, iter, phi, conn, debug); //call the gpu version of the ivote HANDLE_ERROR(cudaMemcpy(cpuI, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output to the cpu + + gpu_time = gpuTimer_end(); } } #endif \ No newline at end of file diff --git a/stim/iVote/ivote2/local_max.cuh b/stim/iVote/ivote2/local_max.cuh index 0da2a85..eebc64c 100644 --- a/stim/iVote/ivote2/local_max.cuh +++ b/stim/iVote/ivote2/local_max.cuh @@ -10,7 +10,7 @@ namespace stim{ // this kernel calculates the local maximum for finding the cell centers template - __global__ void cuda_local_max(T* gpuCenters, T* gpuVote, int conn, int x, int y){ + __global__ void cuda_local_max(T* gpuCenters, T* gpuVote, int conn, int x, int y){ // calculate the 2D coordinates for this current thread. int xi = blockIdx.x * blockDim.x + threadIdx.x; @@ -20,16 +20,16 @@ namespace stim{ return; // convert 2D coordinates to 1D - int i = yi * x + xi; + int i = yi * x + xi; gpuCenters[i] = 0; //initialize the value at this location to zero T val = gpuVote[i]; - for(int xl = xi - conn; xl < xi + conn; xl++){ - for(int yl = yi - conn; yl < yi + conn; yl++){ + for(unsigned int xl = xi - conn; xl < xi + conn; xl++){ + for(unsigned int yl = yi - conn; yl < yi + conn; yl++){ if(xl >= 0 && xl < x && yl >= 0 && yl < y){ - int il = yl * x + xl; + unsigned int il = yl * x + xl; if(gpuVote[il] > val){ return; } @@ -47,7 +47,7 @@ namespace stim{ } template - void gpu_local_max(T* gpuCenters, T* gpuVote, unsigned int conn, size_t x, size_t y){ + void gpu_local_max(T* gpuCenters, T* gpuVote, unsigned int conn, unsigned int x, unsigned int y){ unsigned int max_threads = stim::maxThreadsPerBlock(); /*dim3 threads(max_threads, 1); diff --git a/stim/image/image.h b/stim/image/image.h index 6e2925c..f85baca 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -275,10 +275,10 @@ public: int channels = cvImage.channels(); 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()); - memcpy(img, cv_ptr, 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()); + //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()); #else -- libgit2 0.21.4