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
bb8e0bc8
Commit
bb8e0bc8
authored
Apr 04, 2018
by
Davis King
Browse files
More cleanup
parent
0ce6ed5b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
67 deletions
+69
-67
dlib/dnn/cuda_data_ptr.cpp
dlib/dnn/cuda_data_ptr.cpp
+49
-0
dlib/dnn/cuda_data_ptr.h
dlib/dnn/cuda_data_ptr.h
+20
-0
dlib/dnn/cudnn_dlibapi.cpp
dlib/dnn/cudnn_dlibapi.cpp
+0
-49
dlib/dnn/cudnn_dlibapi.h
dlib/dnn/cudnn_dlibapi.h
+0
-18
No files found.
dlib/dnn/cuda_data_ptr.cpp
View file @
bb8e0bc8
...
...
@@ -59,6 +59,55 @@ namespace dlib
}
}
// ------------------------------------------------------------------------------------
class
cudnn_device_buffer
{
public:
// not copyable
cudnn_device_buffer
(
const
cudnn_device_buffer
&
)
=
delete
;
cudnn_device_buffer
&
operator
=
(
const
cudnn_device_buffer
&
)
=
delete
;
cudnn_device_buffer
()
{
buffers
.
resize
(
16
);
}
~
cudnn_device_buffer
()
{
}
std
::
shared_ptr
<
resizable_cuda_buffer
>
get_buffer
(
)
{
int
new_device_id
;
CHECK_CUDA
(
cudaGetDevice
(
&
new_device_id
));
// make room for more devices if needed
if
(
new_device_id
>=
(
long
)
buffers
.
size
())
buffers
.
resize
(
new_device_id
+
16
);
// If we don't have a buffer already for this device then make one
std
::
shared_ptr
<
resizable_cuda_buffer
>
buff
=
buffers
[
new_device_id
].
lock
();
if
(
!
buff
)
{
buff
=
std
::
make_shared
<
resizable_cuda_buffer
>
();
buffers
[
new_device_id
]
=
buff
;
}
// Finally, return the buffer for the current device
return
buff
;
}
private:
std
::
vector
<
std
::
weak_ptr
<
resizable_cuda_buffer
>>
buffers
;
};
std
::
shared_ptr
<
resizable_cuda_buffer
>
device_global_buffer
()
{
thread_local
cudnn_device_buffer
buffer
;
return
buffer
.
get_buffer
();
}
// ------------------------------------------------------------------------------------
}
...
...
dlib/dnn/cuda_data_ptr.h
View file @
bb8e0bc8
...
...
@@ -179,6 +179,26 @@ namespace dlib
cuda_data_void_ptr
buffer
;
};
// ----------------------------------------------------------------------------------------
std
::
shared_ptr
<
resizable_cuda_buffer
>
device_global_buffer
(
);
/*!
ensures
- Returns a pointer to a globally shared CUDA memory buffer on the
currently selected CUDA device. The buffer is also thread local. So
each host thread will get its own buffer. You can use this global buffer
as scratch space for CUDA computations that all take place on the default
stream. Using it in this way ensures that there aren't any race conditions
involving the use of the buffer.
- The global buffer is deallocated once all references to it are
destructed. It will be reallocated as required. So if you want to avoid
these reallocations then hold a copy of the shared_ptr returned by this
function.
!*/
// ----------------------------------------------------------------------------------------
}
}
...
...
dlib/dnn/cudnn_dlibapi.cpp
View file @
bb8e0bc8
...
...
@@ -117,55 +117,6 @@ namespace dlib
thread_local
cudnn_context
c
;
return
c
.
get_handle
();
}
// ------------------------------------------------------------------------------------
class
cudnn_device_buffer
{
public:
// not copyable
cudnn_device_buffer
(
const
cudnn_device_buffer
&
)
=
delete
;
cudnn_device_buffer
&
operator
=
(
const
cudnn_device_buffer
&
)
=
delete
;
cudnn_device_buffer
()
{
buffers
.
resize
(
16
);
}
~
cudnn_device_buffer
()
{
}
std
::
shared_ptr
<
resizable_cuda_buffer
>
get_buffer
(
)
{
int
new_device_id
;
CHECK_CUDA
(
cudaGetDevice
(
&
new_device_id
));
// make room for more devices if needed
if
(
new_device_id
>=
(
long
)
buffers
.
size
())
buffers
.
resize
(
new_device_id
+
16
);
// If we don't have a buffer already for this device then make one
std
::
shared_ptr
<
resizable_cuda_buffer
>
buff
=
buffers
[
new_device_id
].
lock
();
if
(
!
buff
)
{
buff
=
std
::
make_shared
<
resizable_cuda_buffer
>
();
buffers
[
new_device_id
]
=
buff
;
}
// Finally, return the buffer for the current device
return
buff
;
}
private:
std
::
vector
<
std
::
weak_ptr
<
resizable_cuda_buffer
>>
buffers
;
};
std
::
shared_ptr
<
resizable_cuda_buffer
>
device_global_buffer
()
{
thread_local
cudnn_device_buffer
buffer
;
return
buffer
.
get_buffer
();
}
// ------------------------------------------------------------------------------------
class
cudnn_activation_descriptor
...
...
dlib/dnn/cudnn_dlibapi.h
View file @
bb8e0bc8
...
...
@@ -17,24 +17,6 @@ namespace dlib
namespace
cuda
{
// ----------------------------------------------------------------------------------------
std
::
shared_ptr
<
resizable_cuda_buffer
>
device_global_buffer
(
);
/*!
ensures
- Returns a pointer to a globally shared CUDA memory buffer on the
currently selected CUDA device. The buffer is also thread local. So
each host thread will get its own buffer. You can use this global buffer
as scratch space for CUDA computations that all take place on the default
stream. Using it in this way ensures that there aren't any race conditions
involving the use of the buffer.
- The global buffer is deallocated once all references to it are
destructed. It will be reallocated as required. So if you want to avoid
these reallocations then hold a copy of the shared_ptr returned by this
function.
!*/
// -----------------------------------------------------------------------------------
class
tensor_descriptor
...
...
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