Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sreekanth Arikatla
VTK-m
Commits
b530a5ce
Commit
b530a5ce
authored
Dec 19, 2017
by
Sujin Philip
Browse files
Fix issue with Managed Memory for 0 size arrays
parent
a6f6ea99
Changes
1
Hide whitespace changes
Inline
Side-by-side
vtkm/cont/cuda/internal/CudaAllocator.cu
View file @
b530a5ce
...
...
@@ -33,6 +33,10 @@ static bool IsInitialized = false;
// True if all devices support concurrent pagable managed memory.
static
bool
ManagedMemorySupported
=
false
;
// Avoid overhead of cudaMemAdvise and cudaMemPrefetchAsync for small buffers.
// This value should be > 0 or else these functions will error out.
static
std
::
size_t
Threshold
=
1
<<
20
;
}
namespace
vtkm
...
...
@@ -94,6 +98,12 @@ bool CudaAllocator::IsManagedPointer(const void* ptr)
void
*
CudaAllocator
::
Allocate
(
std
::
size_t
numBytes
)
{
CudaAllocator
::
Initialize
();
// When numBytes is zero cudaMallocManaged returns an error and the behavior
// of cudaMalloc is not documented. Just return nullptr.
if
(
numBytes
==
0
)
{
return
nullptr
;
}
void
*
ptr
=
nullptr
;
if
(
ManagedMemorySupported
)
...
...
@@ -115,7 +125,7 @@ void CudaAllocator::Free(void* ptr)
void
CudaAllocator
::
PrepareForControl
(
const
void
*
ptr
,
std
::
size_t
numBytes
)
{
if
(
IsManagedPointer
(
ptr
))
if
(
IsManagedPointer
(
ptr
)
&&
numBytes
>=
Threshold
)
{
#if CUDART_VERSION >= 8000
// TODO these hints need to be benchmarked and adjusted once we start
...
...
@@ -128,7 +138,7 @@ void CudaAllocator::PrepareForControl(const void* ptr, std::size_t numBytes)
void
CudaAllocator
::
PrepareForInput
(
const
void
*
ptr
,
std
::
size_t
numBytes
)
{
if
(
IsManagedPointer
(
ptr
))
if
(
IsManagedPointer
(
ptr
)
&&
numBytes
>=
Threshold
)
{
#if CUDART_VERSION >= 8000
int
dev
;
...
...
@@ -143,7 +153,7 @@ void CudaAllocator::PrepareForInput(const void* ptr, std::size_t numBytes)
void
CudaAllocator
::
PrepareForOutput
(
const
void
*
ptr
,
std
::
size_t
numBytes
)
{
if
(
IsManagedPointer
(
ptr
))
if
(
IsManagedPointer
(
ptr
)
&&
numBytes
>=
Threshold
)
{
#if CUDART_VERSION >= 8000
int
dev
;
...
...
@@ -158,7 +168,7 @@ void CudaAllocator::PrepareForOutput(const void* ptr, std::size_t numBytes)
void
CudaAllocator
::
PrepareForInPlace
(
const
void
*
ptr
,
std
::
size_t
numBytes
)
{
if
(
IsManagedPointer
(
ptr
))
if
(
IsManagedPointer
(
ptr
)
&&
numBytes
>=
Threshold
)
{
#if CUDART_VERSION >= 8000
int
dev
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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