sinogram_id, sinogram = astra.create_sino3d_gpu(phantom, astra_proj_geom, astra_vol_geom) # Create a data object for the reconstruction rec_id = astra.data3d.create('-vol', astra_vol_geom) # Set up the parameters for a reconstruction algorithm using the CUDA backend cfg = astra.astra_dict('CGLS3D_CUDA') cfg['ReconstructionDataId'] = rec_id cfg['ProjectionDataId'] = sinogram_id cfg['ProjectorId'] = proj_id # Create the algorithm object from the configuration structure alg_id = astra.algorithm.create(cfg) with timer('ASTRA Run'): # Run the algorithm astra.algorithm.run(alg_id, niter) # Get the result rec = astra.data3d.get(rec_id) # Clean up. astra.algorithm.delete(alg_id) astra.data3d.delete(rec_id) astra.data3d.delete(sinogram_id) astra.projector3d.delete(proj_id) # --- ODL --- # Create ray transform
# Perform some benchmarks with rn opt_spc = odl.rn(n) simple_spc = SimpleRn(n) x, y, z = np.random.rand(n), np.random.rand(n), np.random.rand(n) ox, oy, oz = (opt_spc.element(x.copy()), opt_spc.element(y.copy()), opt_spc.element(z.copy())) sx, sy, sz = (simple_spc.element(x.copy()), simple_spc.element(y.copy()), simple_spc.element(z.copy())) if 'cuda' in odl.space.entry_points.tensor_space_impl_names(): cu_spc = odl.rn(n, impl='cuda') cx, cy, cz = (cu_spc.element(x.copy()), cu_spc.element(y.copy()), cu_spc.element(z.copy())) print(" lincomb:") with timer("SimpleRn"): for _ in range(iterations): simple_spc.lincomb(2.13, sx, 3.14, sy, out=sz) print("result: {}".format(sz[1:5])) with timer("odl numpy"): for _ in range(iterations): opt_spc.lincomb(2.13, ox, 3.14, oy, out=oz) print("result: {}".format(oz[1:5])) if 'cuda' in odl.space.entry_points.tensor_space_impl_names(): with timer("odl cuda"): for _ in range(iterations): cu_spc.lincomb(2.13, cx, 3.14, cy, out=cz) print("result: {}".format(cz[1:5]))