Skip to content

Commit 9075919

Browse files
authored
Merge pull request andyzeng#10 from DavidGillsjo/optional_gpu
Optional GPU_MODE
2 parents 94879cd + 923fb77 commit 9075919

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

fusion.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class TSDFVolume(object):
1919

20-
def __init__(self,vol_bnds,voxel_size):
20+
def __init__(self,vol_bnds,voxel_size, use_gpu = True):
2121

2222
# Define voxel volume parameters
2323
self._vol_bnds = vol_bnds # rows: x,y,z columns: min,max in world coordinates in meters
@@ -35,8 +35,12 @@ def __init__(self,vol_bnds,voxel_size):
3535
self._weight_vol_cpu = np.zeros(self._vol_dim).astype(np.float32) # for computing the cumulative moving average of observations per voxel
3636
self._color_vol_cpu = np.zeros(self._vol_dim).astype(np.float32)
3737

38+
#Set GPU_MODE
39+
self.gpu_mode = use_gpu and FUSION_GPU_MODE
40+
41+
3842
# Copy voxel volumes to GPU
39-
if FUSION_GPU_MODE:
43+
if self.gpu_mode:
4044
self._tsdf_vol_gpu = cuda.mem_alloc(self._tsdf_vol_cpu.nbytes)
4145
cuda.memcpy_htod(self._tsdf_vol_gpu,self._tsdf_vol_cpu)
4246
self._weight_vol_gpu = cuda.mem_alloc(self._weight_vol_cpu.nbytes)
@@ -62,7 +66,7 @@ def __init__(self,vol_bnds,voxel_size):
6266
int max_threads_per_block = blockDim.x;
6367
int block_idx = blockIdx.z*gridDim.y*gridDim.x+blockIdx.y*gridDim.x+blockIdx.x;
6468
int voxel_idx = gpu_loop_idx*gridDim.x*gridDim.y*gridDim.z*max_threads_per_block+block_idx*max_threads_per_block+threadIdx.x;
65-
69+
6670
int vol_dim_x = (int) vol_dim[0];
6771
int vol_dim_y = (int) vol_dim[1];
6872
int vol_dim_z = (int) vol_dim[2];
@@ -163,7 +167,7 @@ def __init__(self,vol_bnds,voxel_size):
163167
# n_voxels_expand = int(np.ceil((new_bnds[dim,1]-self._vol_bnds[dim,1])/self._voxel_size))
164168
# new_chunk_size = np.round((self._vol_bnds[:,1]-self._vol_bnds[:,0])/self._voxel_size).astype(int)
165169
# new_chunk_size[dim] = n_voxels_expand # size of expanding region (i.e. chunk)
166-
170+
167171
# # Initialize chunks and concatenate to current voxel volume
168172
# self._tsdf_vol_cpu = np.concatenate((self._tsdf_vol_cpu,np.ones(new_chunk_size)),axis=dim)
169173
# self._weight_vol_cpu = np.concatenate((self._weight_vol_cpu,np.zeros(new_chunk_size)),axis=dim)
@@ -180,7 +184,7 @@ def integrate(self,color_im,depth_im,cam_intr,cam_pose,obs_weight=1.):
180184
color_im = np.floor(color_im[:,:,2]*256*256+color_im[:,:,1]*256+color_im[:,:,0])
181185

182186
# GPU mode: integrate voxel volume (calls CUDA kernel)
183-
if FUSION_GPU_MODE:
187+
if self.gpu_mode:
184188
for gpu_loop_idx in range(self._n_gpu_loops):
185189
self._cuda_integrate(self._tsdf_vol_gpu,
186190
self._weight_vol_gpu,
@@ -249,7 +253,7 @@ def integrate(self,color_im,depth_im,cam_intr,cam_pose,obs_weight=1.):
249253

250254
# Copy voxel volume to CPU
251255
def get_volume(self):
252-
if FUSION_GPU_MODE:
256+
if self.gpu_mode:
253257
cuda.memcpy_dtoh(self._tsdf_vol_cpu,self._tsdf_vol_gpu)
254258
cuda.memcpy_dtoh(self._color_vol_cpu,self._color_vol_gpu)
255259
return self._tsdf_vol_cpu,self._color_vol_cpu
@@ -314,7 +318,7 @@ def meshwrite(filename,verts,faces,norms,colors):
314318
# Write vertex list
315319
for i in range(verts.shape[0]):
316320
ply_file.write("%f %f %f %f %f %f %d %d %d\n"%(verts[i,0],verts[i,1],verts[i,2],norms[i,0],norms[i,1],norms[i,2],colors[i,0],colors[i,1],colors[i,2]))
317-
321+
318322
# Write face list
319323
for i in range(faces.shape[0]):
320324
ply_file.write("3 %d %d %d\n"%(faces[i,0],faces[i,1],faces[i,2]))

0 commit comments

Comments
 (0)