-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft for fista cupy, gpu tests added
- Loading branch information
Showing
12 changed files
with
529 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Defines common fixtures and makes them available to all tests | ||
|
||
import os | ||
import numpy as np | ||
import pytest | ||
import cupy as cp | ||
|
||
CUR_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
@pytest.fixture(scope="session") | ||
def test_data_path(): | ||
return os.path.join(CUR_DIR, "test_data") | ||
|
||
# only load from disk once per session, and we use np.copy for the elements, | ||
# to ensure data in this loaded file stays as originally loaded | ||
@pytest.fixture(scope="session") | ||
def data_file(test_data_path): | ||
in_file = os.path.join(test_data_path, "normalised_data.npz") | ||
return np.load(in_file) | ||
|
||
@pytest.fixture | ||
def ensure_clean_memory(): | ||
cp.get_default_memory_pool().free_all_blocks() | ||
cp.get_default_pinned_memory_pool().free_all_blocks() | ||
yield None | ||
cp.get_default_memory_pool().free_all_blocks() | ||
cp.get_default_pinned_memory_pool().free_all_blocks() | ||
|
||
|
||
@pytest.fixture | ||
def data(data_file): | ||
return np.copy(data_file["data_norm"]) | ||
|
||
@pytest.fixture | ||
def data_cupy(data): | ||
return cp.asarray(data) | ||
|
||
@pytest.fixture | ||
def angles(data_file): | ||
return np.copy(data_file["angles"]) | ||
|
||
@pytest.fixture | ||
def angles_cupy(angles): | ||
return cp.asarray(angles) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from unittest import mock | ||
import cupy as cp | ||
from cupy.cuda import nvtx | ||
import numpy as np | ||
import pytest | ||
from numpy.testing import assert_allclose | ||
|
||
from tomobar.methodsDIR_CuPy import RecToolsDIRCuPy | ||
|
||
eps = 1e-06 | ||
@cp.testing.gpu | ||
def test_rec_FBPcupy(data_cupy, angles, ensure_clean_memory): | ||
detX=cp.shape(data_cupy)[2] | ||
detY=cp.shape(data_cupy)[1] | ||
N_size = detX | ||
RecToolsCP = RecToolsDIRCuPy( | ||
DetectorsDimH=detX, # Horizontal detector dimension | ||
DetectorsDimV=detY, # Vertical detector dimension (3D case) | ||
CenterRotOffset=0.0, # Center of Rotation scalar or a vector | ||
AnglesVec=angles, # A vector of projection angles in radians | ||
ObjSize=N_size, # Reconstructed object dimensions (scalar) | ||
device_projector="gpu", | ||
) | ||
FBPrec_cupy = RecToolsCP.FBP3D(data_cupy) | ||
recon_data = FBPrec_cupy.get() | ||
assert_allclose(np.min(recon_data), -0.014693323, rtol=eps) | ||
assert_allclose(np.max(recon_data), 0.0340156, rtol=eps) | ||
assert recon_data.dtype == np.float32 | ||
assert recon_data.shape == (128, 160, 160) | ||
|
||
@cp.testing.gpu | ||
def test_rec_FBP_mask_cupy(data_cupy, angles, ensure_clean_memory): | ||
detX=cp.shape(data_cupy)[2] | ||
detY=cp.shape(data_cupy)[1] | ||
N_size = detX | ||
RecToolsCP = RecToolsDIRCuPy( | ||
DetectorsDimH=detX, # Horizontal detector dimension | ||
DetectorsDimV=detY, # Vertical detector dimension (3D case) | ||
CenterRotOffset=0.0, # Center of Rotation scalar or a vector | ||
AnglesVec=angles, # A vector of projection angles in radians | ||
ObjSize=N_size, # Reconstructed object dimensions (scalar) | ||
device_projector="gpu", | ||
) | ||
FBPrec_cupy = RecToolsCP.FBP3D(data_cupy, recon_mask_radius = 0.7) | ||
recon_data = FBPrec_cupy.get() | ||
assert_allclose(np.min(recon_data), -0.0129751, rtol=eps) | ||
assert_allclose(np.max(recon_data), 0.0340156, rtol=eps) | ||
assert recon_data.dtype == np.float32 | ||
assert recon_data.shape == (128, 160, 160) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.