Skip to content
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

[flang][cuda] Force default allocator in device code #102238

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions flang/runtime/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,17 @@ RT_API_ATTRS int Descriptor::Allocate() {
elementBytes = raw_.elem_len = 0;
}
std::size_t byteSize{Elements() * elementBytes};

// Force default allocator in device code.
#ifdef RT_DEVICE_COMPILATION
clementval marked this conversation as resolved.
Show resolved Hide resolved
AllocFct alloc{allocatorRegistry.GetAllocator(kDefaultAllocator)};
#else
AllocFct alloc{allocatorRegistry.GetAllocator(GetAllocIdx())};
#endif

// Zero size allocation is possible in Fortran and the resulting
// descriptor must be allocated/associated. Since std::malloc(0)
// result is implementation defined, always allocate at least one byte.

AllocFct alloc{allocatorRegistry.GetAllocator(GetAllocIdx())};
void *p{alloc(byteSize ? byteSize : 1)};
if (!p) {
return CFI_ERROR_MEM_ALLOCATION;
Expand Down Expand Up @@ -209,7 +215,12 @@ RT_API_ATTRS int Descriptor::Deallocate() {
if (!descriptor.base_addr) {
return CFI_ERROR_BASE_ADDR_NULL;
} else {
// Force default deallocator in device code.
#ifdef RT_DEVICE_COMPILATION
FreeFct free{allocatorRegistry.GetDeallocator(kDefaultAllocator)};
#else
FreeFct free{allocatorRegistry.GetDeallocator(GetAllocIdx())};
#endif
free(descriptor.base_addr);
descriptor.base_addr = nullptr;
return CFI_SUCCESS;
Expand Down
Loading