MCPcopy Create free account
hub / github.com/ROCm/clr / hipMallocAsync

Function hipMallocAsync

hipamd/src/hip_mempool.cpp:85–115  ·  view source on GitHub ↗

================================================================================================

Source from the content-addressed store, hash-verified

83
84// ================================================================================================
85hipError_t hipMallocAsync(void** dev_ptr, size_t size, hipStream_t stream) {
86 HIP_INIT_API(hipMallocAsync, dev_ptr, size, stream);
87 if (dev_ptr == nullptr) {
88 HIP_RETURN(hipErrorInvalidValue);
89 }
90 getStreamPerThread(stream);
91 if (size == 0) {
92 *dev_ptr = nullptr;
93 HIP_RETURN(hipSuccess);
94 }
95 hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
96 auto hip_stream =
97 (stream == nullptr || stream == hipStreamLegacy) ? hip::getCurrentDevice()->NullStream() : s;
98 auto device = hip_stream->GetDevice();
99 auto mem_pool = device->GetCurrentMemoryPool();
100
101 // Return error if any stream other than the current stream is in capture mode
102 if (device->StreamCaptureBlocking()) {
103 if (s->GetCaptureStatus() != hipStreamCaptureStatusActive) {
104 return hipErrorStreamCaptureUnsupported;
105 }
106 }
107
108 STREAM_CAPTURE(hipMallocAsync, stream, reinterpret_cast<hipMemPool_t>(mem_pool), size, dev_ptr);
109
110 *dev_ptr = mem_pool->AllocateMemory(size, hip_stream);
111 if (*dev_ptr == nullptr) {
112 HIP_RETURN(hipErrorOutOfMemory);
113 }
114 HIP_RETURN(hipSuccess);
115}
116
117// ================================================================================================
118// @note: Runtime needs the new command for MT path, since the app can execute hipFreeAsync()

Callers

nothing calls this directly

Calls 8

getStreamPerThreadFunction · 0.85
getCurrentDeviceFunction · 0.85
NullStreamMethod · 0.80
GetDeviceMethod · 0.80
GetCurrentMemoryPoolMethod · 0.80
GetCaptureStatusMethod · 0.80
StreamCaptureBlockingMethod · 0.45
AllocateMemoryMethod · 0.45

Tested by

no test coverage detected