Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstruction errors out with certain geometries cause memset fail when initializing iterative reconstruction. #501

Open
X-Strahl opened this issue Oct 23, 2023 · 4 comments

Comments

@X-Strahl
Copy link

I am having issues reconstructing certain geometries in TIGRE with MLEM and CGLS/LSQR (FDK works fine). This only happens with certain geometry combinations and I have not been able to pinpoint what triggers it exactly. By just downsampling the radiographs, I am able to circumvent it, but smaller radiographs do not mean it will succeed. Sometimes upsampling fixes the issue. This includes changing the geometry of course (detector pixel amount and size).

With this code:

from tigre.utilities import sample_loader
import tigre
import tigre.algorithms as algs
import matplotlib.pyplot as plt
import numpy as np

phantom = np.random.rand(3511,1964,1964).astype(np.float32)
tigre_geometry = tigre.geometry_default(nVoxel=phantom.shape)
tigre_geometry.nDetector=np.array([phantom.shape[0],phantom.shape[1]])
angles = np.linspace(0, 2*np.pi, 102)
tigre_geometry.DSD=458
tigre_geometry.DSO=28

tigre_geometry.dDetector=np.array([0.12987013, 0.12987013])
tigre_geometry.sDetector=np.array([455.97402597, 255.06493506])
tigre_geometry.dVoxel=np.array([0.02026159, 0.02027554, 0.02027554])
tigre_geometry.sVoxel=np.array([28.4532169373,15.9162968, 15.9162968 ])

projections_default = tigre.Ax(phantom, tigre_geometry, angles)
print(tigre_geometry)
recon=algs.mlem(projections_default, tigre_geometry, angles, 20)

I can provoke the error. And I get the output:


TIGRE parameters
-----
Geometry parameters
Distance from source to detector (DSD) = 458 mm
Distance from source to origin (DSO)= 28 mm
-----
Detector parameters
Number of pixels (nDetector) = [3511 1964]
Size of each pixel (dDetector) = [0.12987013 0.12987013] mm
Total size of the detector (sDetector) = [455.97402597 255.06493506] mm
-----
Image parameters
Number of voxels (nVoxel) = [3511 1964 1964]
Total size of the image (sVoxel) = [28.45321694 15.9162968  15.9162968 ] mm
Size of each voxel (dVoxel) = [0.02026159 0.02027554 0.02027554] mm
-----
Offset correction parameters
Offset of image from origin (offOrigin) = [0 0 0] mm
Offset of detector (offDetector) = [0 0] mm
-----
Auxillary parameters
Samples per pixel of forward projection (accuracy) = 0.5
-----
Rotation of the Detector (rotDetector) = [0 0 0] rad

../Common/CUDA/TIGRE_common.cpp (7): memset fail 
../Common/CUDA/TIGRE_common.cpp (14): CBCT:CUDA:Atb an illegal memory access was encountered

Hardware is 512GB RAM and dual RTX 4090. Forcing TIGRE to just use one GPU does not fix the issue. Latest Cython and Numpy is used.

@X-Strahl
Copy link
Author

Screenshot 2023-10-23 at 9 07 57 AM

I also see issues like this sometimes where it seemingly succeeds but the reconstruction looks like this (This is a vertical slice), where a large portion has no value.

@AnderBiguri
Copy link
Member

Thanks! this seems an edge case on the memory management of CUDA, I believe.
I'll investigate.

@immortalmin
Copy link

When I was using a remote Python interpreter in PyCharm, I encountered a similar issue.

../Common/CUDA/TIGRE_common.cpp (7): Main loop fail
../Common/CUDA/TIGRE_common.cpp (14): CBCT:CUDA:Atb an illegal memory access was encountered

Solution:

  1. In edit configurations->Environment->Environment variables add LD_LIBRARY_PATH=[path to cuda lib64]; . e.g. Replace [path to cuda lib64] with /usr/local/cuda/lib64.
  2. Ensure that tigre related libraries are imported before other libraries

@AnderBiguri
Copy link
Member

thanks for that information @immortalmin ! I think its the same error, but I don't think its caused by the same issue. However, super important info, thanks for bringing this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants