Skip to content

[libc] Use the NVIDIA device allocator for GPU malloc #124277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libc/src/stdlib/gpu/free.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

namespace LIBC_NAMESPACE_DECL {

// FIXME: For now we just default to the NVIDIA device allocator which is
// always available on NVPTX targets. This will be implemented fully later.
#ifndef LIBC_TARGET_ARCH_IS_NVPTX
LLVM_LIBC_FUNCTION(void, free, (void *ptr)) { gpu::deallocate(ptr); }
#endif

} // namespace LIBC_NAMESPACE_DECL
4 changes: 4 additions & 0 deletions libc/src/stdlib/gpu/malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

namespace LIBC_NAMESPACE_DECL {

// FIXME: For now we just default to the NVIDIA device allocator which is
// always available on NVPTX targets. This will be implemented fully later.
#ifndef LIBC_TARGET_ARCH_IS_NVPTX
LLVM_LIBC_FUNCTION(void *, malloc, (size_t size)) {
return gpu::allocate(size);
}
#endif

} // namespace LIBC_NAMESPACE_DECL
3 changes: 2 additions & 1 deletion libc/test/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ if(LLVM_LIBC_FULL_BUILD)
)

# Only baremetal and GPU has an in-tree 'malloc' implementation.
if(LIBC_TARGET_OS_IS_BAREMETAL OR LIBC_TARGET_OS_IS_GPU)
if((LIBC_TARGET_OS_IS_BAREMETAL OR LIBC_TARGET_OS_IS_GPU) AND
NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
add_libc_test(
malloc_test
HERMETIC_TEST_ONLY
Expand Down
Loading