Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tomotools
Nabu
Commits
12d96b7d
Commit
12d96b7d
authored
Jan 07, 2022
by
Pierre Paleo
Browse files
Update CudaSinoNormalization with division op
parent
c3b23fcd
Changes
1
Hide whitespace changes
Inline
Side-by-side
nabu/reconstruction/sinogram_cuda.py
View file @
12d96b7d
...
...
@@ -188,17 +188,28 @@ class CudaSinoNormalization(SinoNormalization):
}
elif
self
.
normalization_array
is
not
None
:
normalization_array
=
self
.
normalization_array
n_angles
,
n_x
=
self
.
sinos_shape
[
-
2
:]
# If normalization_array is 1D, make a 2D array by repeating the line
if
normalization_array
.
ndim
==
1
:
normalization_array
=
np
.
tile
(
normalization_array
,
(
n_angles
,
1
))
if
normalization_array
.
shape
!=
(
n_angles
,
n_x
):
raise
ValueError
(
"Expected normalization array to be of shape (n_angles, n_x) = (%d, %d)"
%
(
n_angles
,
n_x
)
)
normalization_array
=
np
.
tile
(
normalization_array
,
(
self
.
n_angles
,
1
))
self
.
_d_normalization_array
=
garray
.
to_gpu
(
normalization_array
.
astype
(
"f"
))
if
self
.
normalization_kind
==
"subtraction"
:
generic_op_val
=
1
elif
self
.
normalization_kind
==
"division"
:
generic_op_val
=
3
self
.
_norm_kernel
=
CudaKernel
(
"inplace_generic_op_2Dby2D"
,
filename
=
get_cuda_srcfile
(
"ElementOp.cu"
),
signature
=
"PPii"
,
options
=
[
"-DGENERIC_OP=%d"
%
generic_op_val
]
)
self
.
_norm_kernel_args
=
[
self
.
_d_normalization_array
,
np
.
int32
(
self
.
n_angles
),
np
.
int32
(
self
.
n_x
)
]
blk
=
(
32
,
32
,
1
)
self
.
_norm_kernel_kwargs
=
{
"block"
:
blk
,
"grid"
:
(
int
(
updiv
(
self
.
n_angles
,
blk
[
0
])),
int
(
updiv
(
self
.
n_x
,
blk
[
1
])),
1
)
}
def
_normalize_chebyshev
(
self
,
sinos
):
if
sinos
.
flags
.
c_contiguous
:
...
...
@@ -224,24 +235,24 @@ class CudaSinoNormalization(SinoNormalization):
#
# Array subtraction
# Array subtraction
/division
#
def
_normalize_
subtract_array
(
self
,
sino
):
def
_normalize_
op
(
self
,
sino
):
if
sino
.
ndim
==
2
:
# Things can go wrong if "sino" is a non-contiguous 2D array
# But this should be handled outside this function, as the processing is in-place
s
ino
-=
self
.
_
d_
norm
alization_array
s
elf
.
_norm_kernel
(
sino
,
*
self
.
_norm
_kernel_args
,
**
self
.
_norm_kernel_kwargs
)
else
:
if
sino
.
flags
.
forc
:
# Contiguous 3D array. But pycuda wants the same shape for both operands.
for
i
in
range
(
sino
.
shape
[
0
]):
sino
[
i
]
-=
self
.
_
d_
norm
alization_array
self
.
_norm_kernel
(
sino
[
i
]
,
*
self
.
_norm
_kernel_args
,
**
self
.
_norm_kernel_kwargs
)
else
:
# Non-contiguous 2D array. Make a temp. copy
for
i
in
range
(
sino
.
shape
[
0
]):
self
.
_d_tmp
[:]
=
sino
[
i
][:]
self
.
_d_tmp
-=
self
.
_
d_
norm
alization_array
self
.
_norm_kernel
(
self
.
_d_tmp
,
*
self
.
_norm
_kernel_args
,
**
self
.
_norm_kernel_kwargs
)
sino
[
i
][:]
=
self
.
_d_tmp
[:]
return
sino
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment