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

GPU Version #83

Open
wants to merge 194 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
1ddb31b
adding cuda to cython compilation
ErickHernandezGutierrez Mar 14, 2020
d1d594b
adding gpu manager with CudaLinearOperator class
ErickHernandezGutierrez Mar 14, 2020
77816f3
testing CudaLinearOperator on core.pyx file
ErickHernandezGutierrez Mar 14, 2020
91ebe72
Adding kernels for Ax multiplication in GPU
ErickHernandezGutierrez Mar 24, 2020
ad4c7bc
Fixing compilation error with variable names
ErickHernandezGutierrez Mar 24, 2020
0438fcd
Fixing compilation error with variable names
ErickHernandezGutierrez Mar 24, 2020
e1ba287
Fixing compilation error with variable names
ErickHernandezGutierrez Mar 24, 2020
173d953
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 24, 2020
1ef189c
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
5ac1533
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
d9d6868
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
c9927ee
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
f2f489e
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
e8da361
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
491ce82
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
71dc3d5
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
4ffcd26
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
a2f1fa1
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
80adafe
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
e6964ea
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
da54fc2
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 25, 2020
6e5974d
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
c121e13
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
4835b3f
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
528b9b3
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
be50c26
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
24eb5d0
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
2f37df8
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
8184b95
Adding kernels for operation A'y in GPU
ErickHernandezGutierrez Mar 27, 2020
c00957c
Enabling nthreads=0 in set_threads() function
ErickHernandezGutierrez Mar 27, 2020
4a61912
Enabling nthreads=0 in set_threads() function
ErickHernandezGutierrez Mar 27, 2020
4f772c0
Enabling nthreads=0 in set_threads() function
ErickHernandezGutierrez Mar 27, 2020
b3a1a8e
Modfying some variable names
ErickHernandezGutierrez Mar 28, 2020
02aa561
Modfying some variable names
ErickHernandezGutierrez Mar 28, 2020
071464d
Modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
43a1439
Modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
437e553
Modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
0e41caf
Revert "Enabling nthreads=0 in set_threads() function"
ErickHernandezGutierrez Mar 28, 2020
c64337a
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
86c9d32
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
242c7fb
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
f4b1382
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
a66b5a3
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
f8c5b0c
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
211744b
Reverting wrong file merging and modifying some variable names
ErickHernandezGutierrez Mar 28, 2020
fe9eb38
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
a0e5213
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
6f6740a
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
e074127
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
aea527c
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
2046cae
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
06be9b9
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
1253405
Adding CUDA error checker
ErickHernandezGutierrez Mar 29, 2020
0dbe1dc
Adding CudaLinearOperator to build_dictionary()
ErickHernandezGutierrez Mar 29, 2020
e1c3319
Adding CudaLinearOperator to build_dictionary()
ErickHernandezGutierrez Mar 29, 2020
b187eed
Adding CudaLinearOperator to build_dictionary()
ErickHernandezGutierrez Mar 29, 2020
1ab2b28
Fixing bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 29, 2020
71099f6
Fixing bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 29, 2020
2e19a23
Fixing bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 29, 2020
e00cc6e
Fixing bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 29, 2020
75b7219
Fixing bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 29, 2020
c2c6a8d
Solving bug in operation A'y in GPU
ErickHernandezGutierrez Mar 30, 2020
2e1559a
Solving bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 30, 2020
484df81
Solving bug with A'y operation in CUDA
ErickHernandezGutierrez Mar 30, 2020
f06d11c
Solving bug with operation A'y in CUDA
ErickHernandezGutierrez Mar 30, 2020
6c335cd
Solving bug with operation A'y in CUDA
ErickHernandezGutierrez Mar 30, 2020
6cb8994
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
1c32ed7
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
02b1c67
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
2bea86b
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
38e39a8
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
58f09dc
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
65a101e
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
4d59900
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
06396e0
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
f20936d
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
b4cb321
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
c4f0b9d
Adding memory size and CUDA version checker
ErickHernandezGutierrez Mar 30, 2020
eda2061
Solving bug with operation A'y in CUDA
ErickHernandezGutierrez Mar 31, 2020
b2adc33
Solving bug with operation A'y in CUDA
ErickHernandezGutierrez Mar 31, 2020
258b4bc
Solving bug with operation A'y in CUDA
ErickHernandezGutierrez Mar 31, 2020
bd4eaf9
Solving bug with operation A'y in CUDA
ErickHernandezGutierrez Mar 31, 2020
f6c22b3
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
9ccdcb8
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
e718fa3
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
76fa0c7
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
4d9cc30
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
2aa0ac9
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
9b8b9f8
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
9b529aa
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
948d638
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
8c9e1ec
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
07287e7
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
4bf271a
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
7a23b1b
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
d911b00
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 1, 2020
35c7fab
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
f7ac496
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
d0a855e
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
7cfbad6
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
99c332d
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
90df1b2
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
4f6ef08
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
da1df87
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
b51f9b5
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
e442dc5
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
5ebdad2
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
e0250e8
Adding fcall flag to CudaLinearOperator
ErickHernandezGutierrez Apr 2, 2020
9a7dd02
Minor clenup
ErickHernandezGutierrez Apr 3, 2020
a120ff6
Adding texture memory to kernels
ErickHernandezGutierrez Jun 14, 2020
512edb2
Adding texture memory to kernels
ErickHernandezGutierrez Jun 14, 2020
ccc147b
removing textures for experiments
ErickHernandezGutierrez Jul 3, 2020
b62895d
removing textures for experiments
ErickHernandezGutierrez Jul 3, 2020
1667493
Adding option to choose GPU
ErickHernandezGutierrez Jul 18, 2020
b948fde
Adding option to choose GPU
ErickHernandezGutierrez Jul 18, 2020
0f1de29
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
2a5b493
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
a99c955
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
2082491
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
b0641ff
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
9c19631
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
b89bed8
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
8fb324b
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
8c8fa75
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
8ce9b41
Adding option to choose CUDA GPU
ErickHernandezGutierrez Jul 18, 2020
aa86476
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
0c8007e
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
ad35e09
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
26ab0ac
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
14bb55d
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
0067039
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
bee7b0e
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
bd2b467
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
666407d
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
2a15a0c
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
90ac9b9
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
c1d30ed
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
382efb9
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
e1638b6
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
349efd2
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
97cefb0
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
95d2bbf
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
9511ec7
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
bd6518a
Merging CUDA version with the lastest COMMIT version
ErickHernandezGutierrez Jul 18, 2020
234f750
Adding tutorial to enable GPU acceleration
ErickHernandezGutierrez Jul 18, 2020
13dfccf
Adding tutorial to enable GPU acceleration
ErickHernandezGutierrez Jul 18, 2020
ced31cc
Adding tutorial to enable GPU acceleration
ErickHernandezGutierrez Jul 18, 2020
52cbcc5
Minor cleanup
ErickHernandezGutierrez Jul 18, 2020
0ebf7df
Adding Cuda toolkit to the installation guide
ErickHernandezGutierrez Jul 18, 2020
714f066
Adding Cuda toolkit to the installation guide
ErickHernandezGutierrez Jul 18, 2020
02d00b1
Adding link to nvidia drivers
ErickHernandezGutierrez Jul 18, 2020
ff86418
Merge branch 'master' of https://github.com/daducci/COMMIT into cudagpu
ErickHernandezGutierrez Jan 5, 2021
c91b4d2
Adding version information to CHANGELOG file
ErickHernandezGutierrez Jan 5, 2021
b7e1c60
Removing tutorial for cuda version
ErickHernandezGutierrez Jan 5, 2021
2b61340
Minor cleanup
ErickHernandezGutierrez Jan 5, 2021
ea871aa
Minor cleanup
ErickHernandezGutierrez Jan 5, 2021
5142c49
Minor Cleanup
ErickHernandezGutierrez Jan 8, 2021
1deff30
Solving Bug
ErickHernandezGutierrez Jan 13, 2021
f84b4ee
Solving Bug
ErickHernandezGutierrez Jan 13, 2021
083c1ee
Avoid compilation of CPU version when GPU version is selected
ErickHernandezGutierrez Jan 13, 2021
b33e668
Create cudaoperator folder
ErickHernandezGutierrez Jan 14, 2021
c34128c
Create cudaoperator folder
ErickHernandezGutierrez Jan 14, 2021
aabaed0
Create cudaoperator folder
ErickHernandezGutierrez Jan 14, 2021
a563a52
Change cuda error handling
ErickHernandezGutierrez Jan 14, 2021
84036cf
Change cuda error handling
ErickHernandezGutierrez Jan 14, 2021
6b9cd46
Change cuda error handling
ErickHernandezGutierrez Jan 14, 2021
4082bdd
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
8c98e69
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
cd80599
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
b0f8e3a
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
7570d1c
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
4e32050
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
1da8091
Check GPU properties before build operator
ErickHernandezGutierrez Jan 23, 2021
a5f279a
Show warning message when using 'n' in 'set_threads()'
ErickHernandezGutierrez Jan 23, 2021
5bc8b16
Show warning message when using 'n' in 'set_threads()'
ErickHernandezGutierrez Jan 23, 2021
421ba45
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
82deb61
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
c84ee15
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
3ad7365
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
d780d56
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
d95aaa0
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
5a33853
Modify CUDA error messages
ErickHernandezGutierrez Jan 24, 2021
7841549
Add color to COMMIT when CUDA is enabled
ErickHernandezGutierrez Jan 24, 2021
fbb90ea
Add color to COMMIT when CUDA is enabled
ErickHernandezGutierrez Jan 24, 2021
9926bc6
Add color to COMMIT when CUDA is enabled
ErickHernandezGutierrez Jan 24, 2021
8920a16
Add color to COMMIT when CUDA is enabled
ErickHernandezGutierrez Jan 24, 2021
0246036
Add destructor to CudaLinearOperator class
ErickHernandezGutierrez Jan 24, 2021
4e30982
Remove messages when deleting GPU memory
ErickHernandezGutierrez Jan 24, 2021
512eea8
Assign 1 thread per voxel
ErickHernandezGutierrez Jul 4, 2021
867c4c5
Assign 1 thread per voxel
ErickHernandezGutierrez Jul 4, 2021
32c8144
Change end of line from CRLF to LF
ErickHernandezGutierrez Sep 28, 2021
c7c721f
Merge branch 'master' of https://github.com/daducci/COMMIT into cudagpu
ErickHernandezGutierrez Sep 28, 2021
bd0aa44
GPU acceleration added to CHANGELOG
ErickHernandezGutierrez Sep 29, 2021
018bfb7
merge cudagpu branch with lastest version
ErickHernandezGutierrez Jun 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
extras/* linguist-vendored

# Never modify line endings of our bash scripts
*.sh -lf
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@

# Change Log
All notable changes to COMMIT will be documented in this file.

## [1.7.0] - 2022-06-07

### Added
- GPU acceleration with CUDA for faster model fitting
- 'cudaoperator' extension to handle operator in GPU memory

### Fixed
- Changed end of line from CRLF to LF in several files

### Changed
- setupy.py: Added custom cython compilation for .cu files with nvcc
- set_threads(): 'n' parameter was renamed to 'nthreads'

## [1.6.2] - 2022-05-05

### Fixed
Expand Down
361 changes: 195 additions & 166 deletions commit/core.pyx

Large diffs are not rendered by default.

224 changes: 224 additions & 0 deletions commit/cudaoperator/operator.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#!python
#cython: language_level=3, boundscheck=False, wraparound=False, profile=False

import cython
import numpy as np
cimport numpy as np
from amico.util import ERROR, LOG

cdef extern from "operator_withCUDA.cuh":
int checkCompatibility(int)

def check_compatibility(gpu_id):
return checkCompatibility(gpu_id)

def check_cuda(error_id):
if error_id == -1:
ERROR( 'Impossible to allocate auxiliar memory in CPU' )
elif error_id == 1:
ERROR( 'Impossible to allocate memory in GPU' )
elif error_id == 2:
ERROR( 'Impossible to transfer memory to GPU' )
elif error_id == 3:
ERROR( 'Impossible to bind textures' )
elif error_id == 4:
ERROR( 'Impossible to transfer constant values to GPU' )
elif error_id == 5:
ERROR( 'There was a problem deleting GPU memory' )
elif error_id == 6:
ERROR( 'There was a problem unbinding texture memory' )
elif error_id == 7:
ERROR( 'There was a problem resetting GPU' )
elif error_id == 0:
print( '[ OK ]' )

cdef extern from "operator_withCUDA.cuh":
cdef cppclass C_CudaLinearOperator "CudaLinearOperator":
C_CudaLinearOperator(int, int, int, int, int, int, int, int, int)

int setDictionary(np.uint32_t*, np.uint32_t*, np.uint16_t*, np.float32_t*, np.uint32_t*, np.uint16_t*)
int setTransposeDictionary(np.uint32_t*, np.uint32_t*, np.uint16_t*, np.float32_t*)
int setKernels(np.float32_t*, np.float32_t*, np.float32_t*)
int setVectors()
int setGlobals()
int destroy()

void dot(np.float64_t*, np.float64_t*)
void Tdot(np.float64_t*, np.float64_t*)

cdef class CudaLinearOperator :
"""This class is a wrapper to the CUDA C++ code for performing marix-vector multiplications
with the COMMIT linear operator A in a CUDA GPU. The multiplications are done using CUDA C++ code
that uses information from the DICTIONARY and KERNELS data structures.
"""
cdef int nS, nF, nR, nE, nT, nV, nI, n, ndirs, gpu_id
cdef public int adjoint, n1, n2

cdef DICTIONARY
cdef KERNELS
cdef THREADS

cdef unsigned int* ICf
cdef float* ICl
cdef unsigned int* ICv
cdef unsigned short* ICo
cdef unsigned int* ECv
cdef unsigned short* ECo
cdef unsigned int* ISOv

cdef float* LUT_IC
cdef float* LUT_EC
cdef float* LUT_ISO

# pointer to this operator in GPU memory
cdef C_CudaLinearOperator* thisptr

# these should be always None, they remain for compatibility
cdef unsigned int* ICthreads
cdef unsigned int* ECthreads
cdef unsigned int* ISOthreads
cdef unsigned char* ICthreadsT
cdef unsigned int* ECthreadsT
cdef unsigned int* ISOthreadsT


def __init__( self, DICTIONARY, KERNELS, THREADS, fcall = 0 ) :
"""Set the pointers to the data structures used by the C code."""
self.DICTIONARY = DICTIONARY
self.KERNELS = KERNELS
self.THREADS = THREADS

self.nF = DICTIONARY['IC']['nF'] # number of FIBERS
self.nR = KERNELS['wmr'].shape[0] # number of FIBER RADII
self.nE = DICTIONARY['EC']['nE'] # number of EC segments
self.nT = KERNELS['wmh'].shape[0] # number of EC TORTUOSITY values
self.nV = DICTIONARY['nV'] # number of VOXELS
self.nI = KERNELS['iso'].shape[0] # number of ISO contributions
self.n = DICTIONARY['IC']['n'] # numbner of IC segments
self.ndirs = KERNELS['wmr'].shape[1] # number of directions
self.gpu_id = THREADS['gpu_id'] # id of the CUDA GPU

if KERNELS['wmr'].size > 0 :
self.nS = KERNELS['wmr'].shape[2] # number of SAMPLES
elif KERNELS['wmh'].size > 0 :
self.nS = KERNELS['wmh'].shape[2]
else :
self.nS = KERNELS['wmr'].shape[1]

self.adjoint = 0 # direct of inverse product

self.n1 = self.nV*self.nS
self.n2 = self.nR*self.nF + self.nT*self.nE + self.nI*self.nV

# get C pointers to arrays in DICTIONARY
cdef unsigned int [::1] ICf = DICTIONARY['IC']['fiber']
self.ICf = &ICf[0]
cdef float [::1] ICl = DICTIONARY['IC']['len']
self.ICl = &ICl[0]
cdef unsigned int [::1] ICv = DICTIONARY['IC']['v']
self.ICv = &ICv[0]
cdef unsigned short [::1] ICo = DICTIONARY['IC']['o']
self.ICo = &ICo[0]
cdef unsigned int [::1] ECv = DICTIONARY['EC']['v']
self.ECv = &ECv[0]
cdef unsigned short [::1] ECo = DICTIONARY['EC']['o']
self.ECo = &ECo[0]
cdef unsigned int [::1] ISOv = DICTIONARY['ISO']['v']
self.ISOv = &ISOv[0]

# get C pointers to arrays in KERNELS
cdef float [:, :, ::1] wmrSFP = KERNELS['wmr']
self.LUT_IC = &wmrSFP[0,0,0]
cdef float [:, :, ::1] wmhSFP = KERNELS['wmh']
self.LUT_EC = &wmhSFP[0,0,0]
cdef float [:, ::1] isoSFP = KERNELS['iso']
self.LUT_ISO = &isoSFP[0,0]

# create the operator in GPU memory
self.thisptr = new C_CudaLinearOperator(self.n, self.nV, self.nF, self.nE, self.ndirs, self.nS, self.nR, self.nT, self.nI)

# build operator in GPU only one time
if fcall == 1:
print( '\t* global values... ', end='' )
check_cuda( self.thisptr.setGlobals() )

print( '\t* lookup tables... ', end='' )
check_cuda( self.thisptr.setKernels(&wmrSFP[0,0,0], &wmhSFP[0,0,0], &isoSFP[0,0]) )

print( '\t* x&y vectors... ', end='' )
check_cuda( self.thisptr.setVectors() )

print( '\t* A operator... ', end='' )
check_cuda( self.thisptr.setDictionary(&ICv[0],&ICf[0],&ICo[0],&ICl[0], &ECv[0],&ECo[0]) )

idx = np.lexsort( [np.array(self.DICTIONARY['IC']['o']), np.array(self.DICTIONARY['IC']['fiber'])] )

self.DICTIONARY['IC']['v'] = self.DICTIONARY['IC']['v'][ idx ]
self.DICTIONARY['IC']['o'] = self.DICTIONARY['IC']['o'][ idx ]
self.DICTIONARY['IC']['fiber'] = self.DICTIONARY['IC']['fiber'][ idx ]
self.DICTIONARY['IC']['len'] = self.DICTIONARY['IC']['len'][ idx ]

ICf = self.DICTIONARY['IC']['fiber']
ICl = self.DICTIONARY['IC']['len']
ICv = self.DICTIONARY['IC']['v']
ICo = self.DICTIONARY['IC']['o']

self.ICf = &ICf[0]
self.ICl = &ICl[0]
self.ICv = &ICv[0]
self.ICo = &ICo[0]

print( '\t* A\' operator... ', end='' )
check_cuda( self.thisptr.setTransposeDictionary(&self.ICv[0], &self.ICf[0], &self.ICo[0], &self.ICl[0]) )

def __del__( self ):
self.thisptr.destroy()

@property
def T( self ) :
"""Transpose of the explicit matrix."""
C = CudaLinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS )
C.adjoint = 1 - C.adjoint
return C

@property
def shape( self ) :
"""Size of the explicit matrix."""
if not self.adjoint :
return ( self.n1, self.n2 )
else :
return ( self.n2, self.n1 )


def dot( self, double [::1] v_in ):
"""Wrapper to C code for efficiently performing the matrix-vector multiplications.

Parameters
----------
v_in : 1D numpy.array of double
Input vector for the matrix-vector multiplication

Returns
-------
v_out : 1D numpy.array of double
Results of the multiplication
"""

# Permit only matrix-vector multiplications
if v_in.size != self.shape[1] :
ERROR( "A.dot(): dimensions do not match" )

# Create output array
cdef double [::1] v_out = np.zeros( self.shape[0], dtype=np.float64 )

# Call the cython function to read the memory pointers
if not self.adjoint :
# DIRECT PRODUCT A*x
self.thisptr.dot(&v_in[0], &v_out[0])
else :
# INVERSE PRODUCT A'*y
self.thisptr.Tdot(&v_in[0], &v_out[0])

return v_out


Loading