[libc-commits] [libc] 8c6a6f1 - [libc] Make RPC malloc implementation return 'nullptr' on alloc failure
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Tue Aug 6 09:03:50 PDT 2024
Author: Joseph Huber
Date: 2024-08-06T11:03:40-05:00
New Revision: 8c6a6f1a707af5bd1afd79d8aa62570b7091801a
URL: https://github.com/llvm/llvm-project/commit/8c6a6f1a707af5bd1afd79d8aa62570b7091801a
DIFF: https://github.com/llvm/llvm-project/commit/8c6a6f1a707af5bd1afd79d8aa62570b7091801a.diff
LOG: [libc] Make RPC malloc implementation return 'nullptr' on alloc failure
Summary:
`malloc` is supposed to return `nullptr` if it fails, not exit with an
error code.
Added:
Modified:
libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp
libc/utils/gpu/loader/nvptx/nvptx-loader.cpp
Removed:
################################################################################
diff --git a/libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp b/libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp
index c1dcce84a1c24..1beef8170475a 100644
--- a/libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp
+++ b/libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp
@@ -180,7 +180,7 @@ hsa_status_t launch_kernel(hsa_agent_t dev_agent, hsa_executable_t executable,
if (hsa_status_t err =
hsa_amd_memory_pool_allocate(pool, size,
/*flags=*/0, &dev_ptr))
- handle_error(err);
+ dev_ptr = nullptr;
hsa_amd_agents_allow_access(1, &dev_agent, nullptr, dev_ptr);
buffer->data[0] = reinterpret_cast<uintptr_t>(dev_ptr);
};
diff --git a/libc/utils/gpu/loader/nvptx/nvptx-loader.cpp b/libc/utils/gpu/loader/nvptx/nvptx-loader.cpp
index 9fd3de2beb723..1b210b9e7a896 100644
--- a/libc/utils/gpu/loader/nvptx/nvptx-loader.cpp
+++ b/libc/utils/gpu/loader/nvptx/nvptx-loader.cpp
@@ -198,7 +198,7 @@ CUresult launch_kernel(CUmodule binary, CUstream stream,
uint64_t size = buffer->data[0];
CUdeviceptr dev_ptr;
if (CUresult err = cuMemAllocAsync(&dev_ptr, size, memory_stream))
- handle_error(err);
+ dev_ptr = 0UL;
// Wait until the memory allocation is complete.
while (cuStreamQuery(memory_stream) == CUDA_ERROR_NOT_READY)
More information about the libc-commits
mailing list