diff options
author | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2017-01-26 14:57:57 +0100 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2017-02-08 14:39:01 +0100 |
commit | d85a660f064e8130b27e11c7fd762221c754c315 (patch) | |
tree | 72382e8414c8dc51a7a7ef45845b4c61b25dfed9 /python/astra/data3d_c.pyx | |
parent | ebd5fe932fd2d6c4a516bc1cdc69e37aa4f5cf55 (diff) | |
download | astra-d85a660f064e8130b27e11c7fd762221c754c315.tar.gz astra-d85a660f064e8130b27e11c7fd762221c754c315.tar.bz2 astra-d85a660f064e8130b27e11c7fd762221c754c315.tar.xz astra-d85a660f064e8130b27e11c7fd762221c754c315.zip |
Start work on CFloat32Data3DGPU to allow persistent/external GPU memory
Diffstat (limited to 'python/astra/data3d_c.pyx')
-rw-r--r-- | python/astra/data3d_c.pyx | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/python/astra/data3d_c.pyx b/python/astra/data3d_c.pyx index 3934f22..56247de 100644 --- a/python/astra/data3d_c.pyx +++ b/python/astra/data3d_c.pyx @@ -45,12 +45,17 @@ from .PyXMLDocument cimport XMLDocument cimport utils from .utils import wrap_from_bytes -from .pythonutils import geom_size +from .pythonutils import geom_size, GPULink import operator from six.moves import reduce +include "config.pxi" + +cdef extern from "Python.h": + void* PyLong_AsVoidPtr(object) + cdef CData3DManager * man3d = <CData3DManager * >PyData3DManager.getSingletonPtr() @@ -65,12 +70,19 @@ def create(datatype,geometry,data=None, link=False): cdef Config *cfg cdef CVolumeGeometry3D * pGeometry cdef CProjectionGeometry3D * ppGeometry - cdef CFloat32Data3DMemory * pDataObject3D + cdef CFloat32Data3D * pDataObject3D cdef CConeProjectionGeometry3D* pppGeometry - cdef CFloat32CustomMemory * pCustom - - if link and data.shape!=geom_size(geometry): - raise Exception("The dimensions of the data do not match those specified in the geometry.") + cdef CFloat32CustomMemory * pCustom = NULL + IF HAVE_CUDA==True: + cdef MemHandle3D hnd + + if link: + if isinstance(data, GPULink): + s = geom_size(geometry) + if geom_size(geometry) != ( data.z, data.y, data.x ): + raise Exception("The dimensions of the data do not match those specified in the geometry.") + elif data.shape!=geom_size(geometry): + raise Exception("The dimensions of the data do not match those specified in the geometry.") if datatype == '-vol': cfg = utils.dictToConfig(six.b('VolumeGeometry'), geometry) @@ -80,10 +92,18 @@ def create(datatype,geometry,data=None, link=False): del pGeometry raise Exception('Geometry class not initialized.') if link: - pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data) - pDataObject3D = <CFloat32Data3DMemory * > new CFloat32VolumeData3DMemory(pGeometry, pCustom) + if isinstance(data, GPULink): + IF HAVE_CUDA==True: + s = geom_size(geometry) + hnd = wrapHandle(<float*>PyLong_AsVoidPtr(data.ptr), data.x, data.y, data.z, data.pitch/4) + pDataObject3D = <CFloat32Data3D * > new CFloat32VolumeData3DGPU(pGeometry, hnd) + ELSE: + raise NotImplementedError("CUDA support is not enabled in ASTRA") + else: + pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data) + pDataObject3D = <CFloat32Data3D * > new CFloat32VolumeData3DMemory(pGeometry, pCustom) else: - pDataObject3D = <CFloat32Data3DMemory * > new CFloat32VolumeData3DMemory(pGeometry) + pDataObject3D = <CFloat32Data3D * > new CFloat32VolumeData3DMemory(pGeometry) del cfg del pGeometry elif datatype == '-sino' or datatype == '-proj3d' or datatype == '-sinocone': @@ -105,8 +125,16 @@ def create(datatype,geometry,data=None, link=False): del ppGeometry raise Exception('Geometry class not initialized.') if link: - pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data) - pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(ppGeometry, pCustom) + if isinstance(data, GPULink): + IF HAVE_CUDA==True: + s = geom_size(geometry) + hnd = wrapHandle(<float*>PyLong_AsVoidPtr(data.ptr), data.x, data.y, data.z, data.pitch/4) + pDataObject3D = <CFloat32Data3D * > new CFloat32ProjectionData3DGPU(ppGeometry, hnd) + ELSE: + raise NotImplementedError("CUDA support is not enabled in ASTRA") + else: + pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data) + pDataObject3D = <CFloat32Data3D * > new CFloat32ProjectionData3DMemory(ppGeometry, pCustom) else: pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(ppGeometry) del ppGeometry @@ -118,8 +146,7 @@ def create(datatype,geometry,data=None, link=False): del pDataObject3D raise Exception("Couldn't initialize data object.") - if not link: fillDataObject(pDataObject3D, data) - + if not link: fillDataObject(dynamic_cast_mem(pDataObject3D), data) return man3d.store(<CFloat32Data3D*>pDataObject3D) |