Commit aaa5c367 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Modify configuration file. Start estimate_required_memory

parent 1bb75bdf
......@@ -45,6 +45,15 @@ def count_cuda_devices():
def get_gpu_memory(device_id):
"""
Return the total memory (in GigaBytes) of a device.
"""
cuda.init()
return cuda.Device(device_id).total_memory()/1e9
"""
pycuda/driver.py
np.complex64: SIGNED_INT32, num_channels = 2
......
......@@ -12,13 +12,20 @@ The user needs to provide:
import os
from .utils import parse_params_values
from .cli_configs import ReconstructConfig
from .validate import validate_conffile_noexcept
def parse_args():
def main():
args = parse_params_values(
ReconstructConfig,
parser_description="Perform a tomographic reconstruction."
)
validator = validate_conffile_noexcept(args["input_file"], print_ok=False)
nabu_config = validator.nabu_config
dataset_structure = validator.dataset_config
if __name__ == "__main__":
parse_args()
main()
......@@ -25,7 +25,7 @@ def get_config(fname):
return config
def nabu_validate(fname):
def validate_conffile(fname):
# Read the configuration file and extract the key/values
config = get_config(fname)
......@@ -42,6 +42,19 @@ def nabu_validate(fname):
# Remove unused radios (modifies dataset_structure)
validator.remove_unused_radios()
return validator
def validate_conffile_noexcept(fname, print_ok=True):
try:
validator = validate_conffile(fname)
except Exception as exc:
print("Error while checking %s:" % fname)
print(exc)
exit(-1)
if print_ok:
print("Configuration file %s is valid" % fname)
return validator
def main():
......@@ -50,13 +63,7 @@ def main():
parser_description="Validate a Nabu configuration file."
)
fname = args["input_file"]
try:
nabu_validate(fname)
except Exception as exc:
print("Error while checking %s:" % fname)
print(exc)
exit(-1)
print("Configuration file %s is valid" % fname)
validate_conffile_noexcept(fname)
if __name__ == "__main__":
main()
#!/usr/bin/env python
"""
computations.py: determine computational needs, chunking method to be used, etc.
"""
def get_chunk_size(nabu_config, dataset, available_mem):
"""
Return the maximum chunk size that can be used with a given amount of memory.
"""
def estimate_required_memory(nabu_config, dataset, chunk_size=None):
"""
Estimate the memory (RAM) needed for a reconstruction.
Parameters
----------
nabu_config: dict
Dictionary describing the nabu configuration. Usually extracted from
the configuration file.
dataset: nabu.resources.dataset_analyzer.DatasetAnalyzer
Dataset structure.
"""
Ny, Nx = dataset.radio_dims
Na = dataset.n_angles
if chunk_size is not None:
Ny = chunk_size
if nabu_config["dataset"]["binning"]:
Nx = Nx // nabu_config["dataset"]["binning"]
if nabu_config["dataset"]["binning_z"]:
Ny = Ny // nabu_config["dataset"]["binning_z"]
if nabu_config["dataset"]["projections_subsampling"]:
Na = Na // nabu_config["dataset"]["projections_subsampling"]
data_volume_size = Nx * Ny * Na * 2 # assuming uint16
rec_config = nabu_config["reconstruction"]
reconstructed_volume_size = 0
if rec_config["method"] != "none":
Nx_rec = rec_config["end_x"] - rec_config["start_x"] + 1
Ny_rec = rec_config["end_y"] - rec_config["start_y"] + 1
Nz_rec = rec_config["end_z"] - rec_config["start_z"] + 1
reconstructed_volume_size = Nx_rec * Ny_rec * Nz_rec * 4 # float32
......@@ -46,6 +46,24 @@ nabu_config = {
"hst_key": "background_file",
"validator": optional_file_name_validator,
},
"binning": {
"default": "1",
"help": "Binning factor.\nThe final slices dimensions will be divided by 'slices_binning'",
"hst_key": None,
"validator": binning_validator,
},
"binning_z": {
"default": "1",
"help": "Whether to also bin in the 'z' direction, resulting in a lesser number of reconstructed slices",
"hst_key": None,
"validator": binning_validator,
},
"projections_subsampling": {
"default": "1",
"help": "Projections subsampling factor: take one projection out of 'projection_subsampling'",
"hst_key": "file_interval",
"validator": binning_validator,
},
},
"preproc": {
"flatfield_enabled": {
......@@ -162,7 +180,7 @@ nabu_config = {
},
"method": {
"default": "FBP",
"help": "Reconstruction method",
"help": "Reconstruction method. Possible values: FBP, none. If value is 'none', no reconstruction will be done.",
"hst_key": None,
"validator": reconstruction_method_validator,
},
......@@ -220,24 +238,6 @@ nabu_config = {
"hst_key": None,
"validator": integer_validator,
},
"slices_binning": {
"default": "1",
"help": "Binning factor in the case where the reconstructed slices are to be binned.\nThe slices dimensions will be divided by 'slices_binning'",
"hst_key": None,
"validator": binning_validator,
},
"slices_binning_z": {
"default": "1",
"help": "Whether to also bin in the 'z' direction, resulting in a lesser number of reconstructed slices",
"hst_key": None,
"validator": binning_validator,
},
"projections_subsampling": {
"default": "1",
"help": "Projections subsampling factor: take one projection out of 'projection_subsampling'",
"hst_key": "file_interval",
"validator": binning_validator,
},
"iterations": {
"default": "200",
"help": "\nParameters for iterative algorithms\n------------------------------------\nNumber of iterations",
......
......@@ -203,7 +203,7 @@ def padding_mode_validator(val):
@validator
def reconstruction_method_validator(val):
avail_rec_methods = ["fbp", "dfi"]
avail_rec_methods = ["fbp", "none"] # dfi, iterative...
return name_range_checker(val, avail_rec_methods, "reconstruction method")
@validator
......
......@@ -109,6 +109,7 @@ def setup_package():
"nabu-test=nabu.tests:nabu_test",
"nabu-config=nabu.resources.cli.bootstrap:bootstrap",
"nabu-validate=nabu.resources.cli.validate:main",
"nabu-reconstruct=nabu.resources.cli.reconstruct:main",
],
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment