Skip to content

Commit

Permalink
Merge pull request #69 from acoreas/main
Browse files Browse the repository at this point in the history
Fix CUDA voxelization issue
  • Loading branch information
spichardo authored Sep 10, 2024
2 parents 91e8c63 + ecbbd5e commit 641c38b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
12 changes: 6 additions & 6 deletions BabelBrain/BabelDatasetPreps.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,11 @@ def GetSkullMaskFromSimbNIBSSTL(SimbNIBSDir='4007/4007_keep/m2m_4007_keep/',
if VoxelizeFilter is None:
while(True):
try:
with CodeTimer("skull voxelization",unit='s'):
with CodeTimer("cpu skull voxelization",unit='s'):
skull_grid = skull_mesh.voxelized(SpatialStep*0.75,max_iter=30).fill().points.astype(np.float32)
with CodeTimer("brain voxelization",unit='s'):
with CodeTimer("cpu voxelization",unit='s'):
csf_grid = csf_mesh.voxelized(SpatialStep*0.75,max_iter=30).fill().points.astype(np.float32)
with CodeTimer("skin voxelization",unit='s'):
with CodeTimer("cpu voxelization",unit='s'):
skin_grid = skin_mesh.voxelized(SpatialStep*0.75,max_iter=30).fill().points.astype(np.float32)
break
except AttributeError as err:
Expand All @@ -753,11 +753,11 @@ def GetSkullMaskFromSimbNIBSSTL(SimbNIBSDir='4007/4007_keep/m2m_4007_keep/',
else:
raise err
else:
with CodeTimer("cpu skull voxelization",unit='s'):
with CodeTimer("skull voxelization",unit='s'):
skull_grid = VoxelizeFilter(skull_mesh,targetResolution=SpatialStep*0.75,GPUBackend=VoxelizeCOMPUTING_BACKEND)
with CodeTimer("cpu brain voxelization",unit='s'):
with CodeTimer("brain voxelization",unit='s'):
csf_grid = VoxelizeFilter(csf_mesh,targetResolution=SpatialStep*0.75,GPUBackend=VoxelizeCOMPUTING_BACKEND)
with CodeTimer("cpu skin voxelization",unit='s'):
with CodeTimer("skin voxelization",unit='s'):
skin_grid = VoxelizeFilter(skin_mesh,targetResolution=SpatialStep*0.75,GPUBackend=VoxelizeCOMPUTING_BACKEND)


Expand Down
3 changes: 1 addition & 2 deletions BabelBrain/CalculateMaskProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def __del__(self):
BinaryClosing.InitBinaryClosing(DeviceName=devicename,GPUBackend=gpu_backend)

DataPreps.InitMedianGPUCallback(MedianFilter.MedianFilter,COMPUTING_BACKEND)
if gpu_backend != 'CUDA':
DataPreps.InitVoxelizeGPUCallback(Voxelize.Voxelize,COMPUTING_BACKEND)
DataPreps.InitVoxelizeGPUCallback(Voxelize.Voxelize,COMPUTING_BACKEND)
DataPreps.InitMappingGPUCallback(MappingFilter.MapFilter,COMPUTING_BACKEND)
DataPreps.InitResampleGPUCallback(Resample.ResampleFromTo,COMPUTING_BACKEND)
DataPreps.InitBinaryClosingGPUCallback(BinaryClosing.BinaryClose,COMPUTING_BACKEND)
Expand Down
4 changes: 1 addition & 3 deletions BabelBrain/GPUFunctions/GPUVoxelize/Voxelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ def Voxelize(inputMesh,targetResolution=1333/500e3/6*0.75*1e3,GPUBackend='OpenCL
int_params_gpu,
np.uint32(gx),
np.uint32(gy),
np.uint32(gz),
np.uint32(points_section.size))
)
np.uint32(gz)))

# Move kernel output data back to host memory
points_section=points_section_gpu.get()
Expand Down
5 changes: 1 addition & 4 deletions BabelBrain/GPUFunctions/GPUVoxelize/voxelize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,9 @@ __kernel void ExtractPoints(__global const unsigned int* voxel_table,
const unsigned int * int_params,
const unsigned int gx,
const unsigned int gy,
const unsigned int gz,
const unsigned int section_size)
const unsigned int gz)
{
size_t k = (size_t)(blockIdx.x*blockDim.x + threadIdx.x);

if (k >= section_size) return;
#endif

#ifdef _METAL
Expand Down

0 comments on commit 641c38b

Please sign in to comment.