Commit 0ce6ed5b authored by Davis King's avatar Davis King

Cleanup of cuda code.

parent 8073f4b1
......@@ -160,8 +160,12 @@ namespace dlib
cuda_data_void_ptr get(size_t size)
/*!
ensures
- This object will return the buffer of requested size of larger
- This object will return the buffer of requested size or larger.
- buffer.size() >= size
- Client code should not hold the returned cuda_data_void_ptr for long
durations, but instead should call get() whenever the buffer is
needed. Doing so ensures that multiple buffers are not kept around
in the event of a resize.
!*/
{
if (buffer.size() < size)
......
......@@ -160,12 +160,12 @@ namespace dlib
std::vector<std::weak_ptr<resizable_cuda_buffer>> buffers;
};
static std::shared_ptr<resizable_cuda_buffer> device_global_buffer()
std::shared_ptr<resizable_cuda_buffer> device_global_buffer()
{
thread_local cudnn_device_buffer buffer;
return buffer.get_buffer();
}
// ------------------------------------------------------------------------------------
class cudnn_activation_descriptor
......
......@@ -17,6 +17,24 @@ 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
......
......@@ -366,7 +366,7 @@ namespace dlib
follows:
ensures
- calling clean() Causes this object to forget about everything except its
- calling clean() causes this object to forget about everything except its
parameters. This is useful if your layer caches information between
forward and backward passes and you want to clean out that cache
information before saving the network to disk.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment