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
gaoqiong
composable_kernel_ROCM
Commits
d0a846c2
Commit
d0a846c2
authored
Dec 17, 2024
by
Ville Pietilä
Browse files
Added more logging. Fix pinned host memory pool to be a real singleton.
parent
af2a1bd8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
7 deletions
+26
-7
include/ck/utility/host_memory_allocator.hpp
include/ck/utility/host_memory_allocator.hpp
+26
-7
No files found.
include/ck/utility/host_memory_allocator.hpp
View file @
d0a846c2
...
...
@@ -8,6 +8,7 @@
#include <map>
#include <queue>
#include <mutex>
#include "unistd.h"
namespace
ck
{
namespace
memory
{
...
...
@@ -15,15 +16,27 @@ namespace memory {
class
MemPool
{
public:
MemPool
()
=
default
;
MemPool
()
:
enableLogging_
(
ck
::
EnvIsEnabled
(
CK_ENV
(
CK_LOGGING
))),
pid_
(
getpid
())
{
if
(
enableLogging_
)
std
::
cout
<<
"[ MemPool ] Created memory pool for process "
<<
pid_
<<
std
::
endl
;
}
~
MemPool
()
{
if
(
enableLogging_
)
std
::
cout
<<
"[ MemPool ] Deleting pool for process "
<<
pid_
<<
"..."
<<
std
::
endl
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
for
(
auto
&
[
size
,
q
]
:
memory_pool_
)
{
clearMemoryPoolQueue
(
q
);
}
if
(
enableLogging_
)
std
::
cout
<<
"[ MemPool ] Deleted pool for process "
<<
pid_
<<
std
::
endl
;
}
void
*
allocate
(
std
::
size_t
sizeInBytes
)
...
...
@@ -78,10 +91,21 @@ namespace memory {
std
::
mutex
mutex_
;
// Mutex to protect access to the memory pool.
std
::
map
<
size_t
,
std
::
queue
<
void
*>>
memory_pool_
{};
size_t
memPoolSizeInBytes_
{
0
};
bool
enableLogging_
{
false
};
int
pid_
{
-
1
};
};
class
PinnedHostMemoryAllocatorBase
{
protected:
static
MemPool
&
get_memory_pool
()
{
static
MemPool
memory_pool
;
return
memory_pool
;
}
};
template
<
typename
T
>
class
PinnedHostMemoryAllocator
class
PinnedHostMemoryAllocator
:
public
PinnedHostMemoryAllocatorBase
{
public:
using
value_type
=
T
;
...
...
@@ -124,11 +148,6 @@ namespace memory {
void
destroy
(
U
*
p
)
noexcept
{
p
->~
U
();
}
private:
static
MemPool
&
get_memory_pool
()
{
static
MemPool
memory_pool
;
return
memory_pool
;
}
};
template
<
typename
T
,
typename
U
>
...
...
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