Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
ca776404
Commit
ca776404
authored
Dec 24, 2015
by
Davis King
Browse files
Added pack_idx() and unpack_idx().
parent
b66c5254
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
dlib/dnn/cuda_utils.h
dlib/dnn/cuda_utils.h
+60
-0
No files found.
dlib/dnn/cuda_utils.h
View file @
ca776404
...
@@ -35,6 +35,66 @@ namespace dlib
...
@@ -35,6 +35,66 @@ namespace dlib
namespace
cuda
namespace
cuda
{
{
// ------------------------------------------------------------------------------------
__inline__
__device__
size_t
pack_idx
(
size_t
dim_size3
,
size_t
dim_size2
,
size_t
dim_size1
,
size_t
idx4
,
size_t
idx3
,
size_t
idx2
,
size_t
idx1
)
/*!
ensures
- Converts a 4D array index into a 1D index assuming row major layout. To
understand precisely what this function does, imagine we had an array
declared like this:
int ARRAY[anything][dim_size3][dim_size2][dim_size1];
Then we could index it like this:
ARRAY[idx4][idx3][idx2][idx1]
or equivalently like this:
((int*)ARRAY)[pack_idx(dim_size3,dim_size2,dim_size1, idx4,idx3,idx2,idx1)]
!*/
{
return
((
idx4
*
dim_size3
+
idx3
)
*
dim_size2
+
idx2
)
*
dim_size1
+
idx1
;
}
__inline__
__device__
void
unpack_idx
(
size_t
idx
,
size_t
dim_size3
,
size_t
dim_size2
,
size_t
dim_size1
,
size_t
&
idx4
,
size_t
&
idx3
,
size_t
&
idx2
,
size_t
&
idx1
)
/*!
ensures
- This function computes the inverse of pack_idx(). Therefore,
if PACKED == pack_idx(dim_size3,dim_size2,dim_size1, idx4,idx3,idx2,idx1)
then unpack_idx(PACKED,dim_size3,dim_size2,dim_size1, IDX4,IDX3,IDX2,IDX1)
results in:
- IDX1 == idx1
- IDX2 == idx2
- IDX3 == idx3
- IDX4 == idx4
!*/
{
idx1
=
idx
%
dim_size1
;
idx
/=
dim_size1
;
idx2
=
idx
%
dim_size2
;
idx
/=
dim_size2
;
idx3
=
idx
%
dim_size3
;
idx
/=
dim_size3
;
idx4
=
idx
;
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
// This function is from the article:
// This function is from the article:
...
...
Write
Preview
Markdown
is supported
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