2024-02-15 09:42:48 +00:00
|
|
|
/* Copyright (c) 2015 - 2024 Advanced Micro Devices, Inc.
|
2020-02-04 08:45:01 -08:00
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE. */
|
2018-03-01 22:57:20 -05:00
|
|
|
|
|
|
|
|
#include <hip/hip_runtime.h>
|
2020-08-11 12:49:50 -04:00
|
|
|
#include <elf/elf.hpp>
|
2018-03-23 00:19:22 -04:00
|
|
|
#include <fstream>
|
2018-03-01 22:57:20 -05:00
|
|
|
|
|
|
|
|
#include "hip_internal.hpp"
|
2025-05-06 15:06:13 -04:00
|
|
|
#include "platform/ndrange.hpp"
|
2018-03-01 22:57:20 -05:00
|
|
|
#include "platform/program.hpp"
|
2018-08-02 02:14:04 -04:00
|
|
|
#include "hip_event.hpp"
|
2020-04-03 12:13:12 -04:00
|
|
|
#include "hip_platform.hpp"
|
2024-10-09 11:24:44 -07:00
|
|
|
#include "hip_comgr_helper.hpp"
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2023-04-21 10:46:05 +00:00
|
|
|
namespace hip {
|
2024-10-09 11:24:44 -07:00
|
|
|
|
2020-05-03 23:05:59 -04:00
|
|
|
hipError_t ihipModuleLoadData(hipModule_t* module, const void* mmap_ptr, size_t mmap_size);
|
2018-03-23 00:19:22 -04:00
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
extern hipError_t ihipLaunchKernel(const void* hostFunction, dim3 gridDim, dim3 blockDim,
|
|
|
|
|
void** args, size_t sharedMemBytes, hipStream_t stream,
|
|
|
|
|
hipEvent_t startEvent, hipEvent_t stopEvent, int flags);
|
2020-05-08 18:18:36 +00:00
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
const std::string& FunctionName(const hipFunction_t f) {
|
|
|
|
|
return hip::DeviceFunc::asFunction(f)->kernel()->name();
|
2019-10-07 11:55:30 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
static uint64_t ElfSize(const void* emi) { return amd::Elf::getElfSize(emi); }
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
hipError_t hipModuleUnload(hipModule_t hmod) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipModuleUnload, hmod);
|
2022-12-02 09:15:22 -05:00
|
|
|
if (hmod == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
|
|
|
|
}
|
2025-05-22 13:24:49 +05:30
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-05-18 22:40:33 -04:00
|
|
|
HIP_RETURN(PlatformState::instance().unloadModule(hmod));
|
|
|
|
|
}
|
2019-07-23 20:09:59 -04:00
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
hipError_t hipModuleLoad(hipModule_t* module, const char* fname) {
|
|
|
|
|
HIP_INIT_API(hipModuleLoad, module, fname);
|
2019-08-22 12:41:42 -04:00
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
HIP_RETURN(PlatformState::instance().loadModule(module, fname));
|
2018-03-02 17:55:48 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipModuleLoadData(hipModule_t* module, const void* image) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipModuleLoadData, module, image);
|
2020-05-18 22:40:33 -04:00
|
|
|
HIP_RETURN(PlatformState::instance().loadModule(module, 0, image));
|
2018-03-23 00:19:22 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipModuleLoadDataEx(hipModule_t* module, const void* image, unsigned int numOptions,
|
|
|
|
|
hipJitOption* options, void** optionsValues) {
|
2019-12-04 14:22:03 -05:00
|
|
|
/* TODO: Pass options to Program */
|
2020-05-14 03:50:34 -05:00
|
|
|
HIP_INIT_API(hipModuleLoadDataEx, module, image);
|
2020-05-18 22:40:33 -04:00
|
|
|
HIP_RETURN(PlatformState::instance().loadModule(module, 0, image));
|
2019-12-04 14:22:03 -05:00
|
|
|
}
|
|
|
|
|
|
2024-05-13 12:21:06 -04:00
|
|
|
extern hipError_t __hipExtractCodeObjectFromFatBinary(
|
|
|
|
|
const void* data, const std::vector<std::string>& devices,
|
|
|
|
|
std::vector<std::pair<const void*, size_t>>& code_objs);
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipModuleGetFunction(hipFunction_t* hfunc, hipModule_t hmod, const char* name) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipModuleGetFunction, hfunc, hmod, name);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2022-11-26 05:38:25 -05:00
|
|
|
if (hfunc == nullptr || name == nullptr || strlen(name) == 0) {
|
2020-10-13 01:19:47 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-11-26 05:38:25 -05:00
|
|
|
if (hmod == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
|
|
|
|
}
|
2020-10-13 01:19:47 -07:00
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
if (hipSuccess != PlatformState::instance().getDynFunc(hfunc, hmod, name)) {
|
2023-12-07 01:32:20 +00:00
|
|
|
LogPrintfError("Cannot find the function: %s for module: 0x%x", name, hmod);
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorNotFound);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2020-05-18 22:40:33 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipModuleGetGlobal(hipDeviceptr_t* dptr, size_t* bytes, hipModule_t hmod,
|
|
|
|
|
const char* name) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipModuleGetGlobal, dptr, bytes, hmod, name);
|
2018-09-11 12:26:34 -04:00
|
|
|
|
2022-12-02 09:15:22 -05:00
|
|
|
if ((dptr == nullptr && bytes == nullptr) || name == nullptr || strlen(name) == 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
if (hmod == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2020-10-13 01:19:47 -07:00
|
|
|
}
|
2019-04-04 18:22:40 -04:00
|
|
|
/* Get address and size for the global symbol */
|
2020-09-28 17:53:32 -04:00
|
|
|
if (hipSuccess != PlatformState::instance().getDynGlobalVar(name, hmod, dptr, bytes)) {
|
2023-12-07 01:32:20 +00:00
|
|
|
LogPrintfError("Cannot find global Var: %s for module: 0x%x at device: %d", name, hmod,
|
2021-02-17 23:54:39 +05:30
|
|
|
ihipGetDevice());
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotFound);
|
2019-03-18 18:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 12:26:34 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 11:22:29 +01:00
|
|
|
hipError_t hipFuncGetAttribute(int* value, hipFunction_attribute attrib, hipFunction_t hfunc) {
|
2020-04-13 19:18:07 -04:00
|
|
|
HIP_INIT_API(hipFuncGetAttribute, value, attrib, hfunc);
|
|
|
|
|
|
2024-01-02 14:56:03 +00:00
|
|
|
if (value == nullptr) {
|
2020-04-13 19:18:07 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
hip::DeviceFunc* function = hip::DeviceFunc::asFunction(hfunc);
|
2020-04-13 19:18:07 -04:00
|
|
|
if (function == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
amd::Kernel* kernel = function->kernel();
|
2020-04-13 19:18:07 -04:00
|
|
|
if (kernel == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDeviceFunction);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
const device::Kernel::WorkGroupInfo* wrkGrpInfo =
|
|
|
|
|
kernel->getDeviceKernel(*(hip::getCurrentDevice()->devices()[0]))->workGroupInfo();
|
2020-04-13 19:18:07 -04:00
|
|
|
if (wrkGrpInfo == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorMissingConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
switch (attrib) {
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES:
|
2020-05-07 19:12:10 -04:00
|
|
|
*value = static_cast<int>(wrkGrpInfo->localMemSize_);
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK:
|
2020-05-08 11:08:08 -04:00
|
|
|
*value = static_cast<int>(wrkGrpInfo->size_);
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_CONST_SIZE_BYTES:
|
2024-06-04 12:53:52 -07:00
|
|
|
*value = static_cast<int>(wrkGrpInfo->constMemSize_ - 1);
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES:
|
2020-05-07 19:12:10 -04:00
|
|
|
*value = static_cast<int>(wrkGrpInfo->privateMemSize_);
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_NUM_REGS:
|
2020-05-09 12:42:30 -04:00
|
|
|
*value = static_cast<int>(wrkGrpInfo->usedVGPRs_);
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_PTX_VERSION:
|
|
|
|
|
case HIP_FUNC_ATTRIBUTE_BINARY_VERSION:
|
2024-06-04 12:53:52 -07:00
|
|
|
*value = hip::getCurrentDevice()->devices()[0]->isa().versionMajor() * 10 +
|
|
|
|
|
hip::getCurrentDevice()->devices()[0]->isa().versionMinor();
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA:
|
2020-04-13 19:18:07 -04:00
|
|
|
*value = 0;
|
|
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES:
|
2020-05-07 19:12:10 -04:00
|
|
|
*value = static_cast<int>(wrkGrpInfo->availableLDSSize_ - wrkGrpInfo->localMemSize_);
|
2020-04-13 19:18:07 -04:00
|
|
|
break;
|
2023-10-03 11:22:29 +01:00
|
|
|
case HIP_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT:
|
2020-04-13 19:18:07 -04:00
|
|
|
*value = 0;
|
|
|
|
|
break;
|
2022-03-14 12:36:16 -04:00
|
|
|
default:
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2020-04-13 19:18:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipFuncGetAttributes(hipFuncAttributes* attr, const void* func) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipFuncGetAttributes, attr, func);
|
2018-07-05 20:29:27 -04:00
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
HIP_RETURN_ONFAIL(PlatformState::instance().getStatFuncAttr(attr, func, ihipGetDevice()));
|
2019-04-26 15:15:48 -04:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-07-05 20:29:27 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipFuncSetAttribute(const void* func, hipFuncAttribute attr, int value) {
|
2020-07-28 03:46:44 -07:00
|
|
|
HIP_INIT_API(hipFuncSetAttribute, func, attr, value);
|
|
|
|
|
|
2024-06-04 12:53:52 -07:00
|
|
|
if (func == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDeviceFunction);
|
|
|
|
|
}
|
|
|
|
|
if (attr < 0 || attr > hipFuncAttributeMax) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 15:40:52 +00:00
|
|
|
hipFunction_t h_func = nullptr;
|
|
|
|
|
const hip::DeviceFunc* function = nullptr;
|
|
|
|
|
|
|
|
|
|
hipError_t err = PlatformState::instance().getStatFunc(&h_func, func, ihipGetDevice());
|
|
|
|
|
if (h_func == nullptr) {
|
|
|
|
|
if (PlatformState::instance().isValidDynFunc((func))) {
|
|
|
|
|
function = reinterpret_cast<const hip::DeviceFunc*>(func);
|
|
|
|
|
} else {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDeviceFunction);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
function = reinterpret_cast<const hip::DeviceFunc*>(h_func);
|
2024-06-04 12:53:52 -07:00
|
|
|
}
|
2024-11-05 15:40:52 +00:00
|
|
|
|
|
|
|
|
amd::Kernel* kernel = function->kernel();
|
2024-06-04 12:53:52 -07:00
|
|
|
|
|
|
|
|
if (kernel == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDeviceFunction);
|
|
|
|
|
}
|
|
|
|
|
device::Kernel* d_kernel =
|
|
|
|
|
(device::Kernel*)(kernel->getDeviceKernel(
|
|
|
|
|
*(hip::getCurrentDevice()->devices()[0])));
|
|
|
|
|
|
|
|
|
|
if (attr == hipFuncAttributeMaxDynamicSharedMemorySize) {
|
2024-10-15 03:57:01 +00:00
|
|
|
if ((value < 0) || (value > (d_kernel->workGroupInfo()->availableLDSSize_ -
|
2024-06-04 12:53:52 -07:00
|
|
|
d_kernel->workGroupInfo()->localMemSize_))) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
d_kernel->workGroupInfo()->maxDynamicSharedSizeBytes_ = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attr == hipFuncAttributePreferredSharedMemoryCarveout) {
|
|
|
|
|
if (value < -1 || value > 100) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-28 03:46:44 -07:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipFuncSetCacheConfig(const void* func, hipFuncCache_t cacheConfig) {
|
2020-08-04 04:11:35 -07:00
|
|
|
HIP_INIT_API(hipFuncSetCacheConfig, cacheConfig);
|
|
|
|
|
|
2024-06-13 11:04:39 -07:00
|
|
|
if (func == nullptr) { HIP_RETURN(hipErrorInvalidDeviceFunction); }
|
|
|
|
|
if (cacheConfig != hipFuncCachePreferNone && cacheConfig != hipFuncCachePreferShared &&
|
|
|
|
|
cacheConfig != hipFuncCachePreferL1 && cacheConfig != hipFuncCachePreferEqual) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
// No way to set cache config yet
|
2020-08-04 04:11:35 -07:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipFuncSetSharedMemConfig(const void* func, hipSharedMemConfig config) {
|
2020-08-18 05:19:01 -07:00
|
|
|
HIP_INIT_API(hipFuncSetSharedMemConfig, func, config);
|
|
|
|
|
|
2024-06-13 11:04:39 -07:00
|
|
|
if (func == nullptr) { HIP_RETURN(hipErrorInvalidDeviceFunction); }
|
|
|
|
|
if (config != hipSharedMemBankSizeDefault && config != hipSharedMemBankSizeFourByte &&
|
|
|
|
|
config != hipSharedMemBankSizeEightByte) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No way to set shared memory config yet
|
2020-08-18 05:19:01 -07:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
hipError_t ihipLaunchKernel_validate(hipFunction_t f, const amd::LaunchParams& launch_params,
|
|
|
|
|
void** kernelParams, void** extra, int deviceId,
|
|
|
|
|
uint32_t params = 0) {
|
2020-11-18 06:31:36 -05:00
|
|
|
if (f == nullptr) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("%s", "Function passed is null");
|
2020-11-18 06:31:36 -05:00
|
|
|
return hipErrorInvalidImage;
|
|
|
|
|
}
|
|
|
|
|
if ((kernelParams != nullptr) && (extra != nullptr)) {
|
2021-03-11 12:10:49 -08:00
|
|
|
LogPrintfError("%s",
|
|
|
|
|
"Both, kernelParams and extra Params are provided, only one should be provided");
|
2025-05-21 18:29:11 +02:00
|
|
|
return hipErrorInvalidConfiguration;
|
2020-11-18 06:31:36 -05:00
|
|
|
}
|
2024-06-05 14:27:01 +02:00
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
if (launch_params.global_[0] == 0 || launch_params.global_[1] == 0
|
|
|
|
|
|| launch_params.global_[2] == 0) {
|
2025-05-21 18:29:11 +02:00
|
|
|
return hipErrorInvalidConfiguration;
|
2024-06-05 14:27:01 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
if (launch_params.local_[0] == 0 || launch_params.local_[1] == 0
|
|
|
|
|
|| launch_params.local_[2] == 0) {
|
2023-10-12 09:03:42 -04:00
|
|
|
return hipErrorInvalidConfiguration;
|
2021-01-07 05:36:04 -05:00
|
|
|
}
|
2019-09-13 11:28:33 -04:00
|
|
|
|
2021-04-27 19:03:22 -04:00
|
|
|
const amd::Device* device = g_devices[deviceId]->devices()[0];
|
2023-01-10 12:50:48 -05:00
|
|
|
const auto& info = device->info();
|
2025-05-06 15:06:13 -04:00
|
|
|
if (launch_params.sharedMemBytes_ > info.localMemSizePerCU_) { //sharedMemPerBlock
|
2023-01-10 12:50:48 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-04-03 12:13:12 -04:00
|
|
|
// Make sure dispatch doesn't exceed max workgroup size limit
|
2025-05-06 15:06:13 -04:00
|
|
|
if (launch_params.local_.product() > info.maxWorkGroupSize_) {
|
2025-05-21 18:29:11 +02:00
|
|
|
return hipErrorInvalidConfiguration;
|
2020-04-03 12:13:12 -04:00
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hip::DeviceFunc* function = hip::DeviceFunc::asFunction(f);
|
|
|
|
|
amd::Kernel* kernel = function->kernel();
|
2023-08-31 15:55:58 +01:00
|
|
|
const amd::KernelSignature& signature = kernel->signature();
|
|
|
|
|
if ((signature.numParameters() > 0) && (kernelParams == nullptr) && (extra == nullptr)) {
|
|
|
|
|
LogPrintfError("%s","At least one of kernelParams or extra Params should be provided");
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-19 09:21:25 +00:00
|
|
|
if (!kernel->getDeviceKernel(*device)) {
|
|
|
|
|
return hipErrorInvalidDevice;
|
|
|
|
|
}
|
2021-03-12 19:15:11 -05:00
|
|
|
// Make sure the launch params are not larger than if specified launch_bounds
|
2021-05-06 22:38:50 -07:00
|
|
|
// If it exceeds, then return a failure
|
2025-05-06 15:06:13 -04:00
|
|
|
if (launch_params.local_.product() > kernel->getDeviceKernel(*device)->workGroupInfo()->size_) {
|
2021-05-26 11:02:51 -07:00
|
|
|
LogPrintfError("Launch params (%u, %u, %u) are larger than launch bounds (%lu) for kernel %s",
|
2025-05-06 15:06:13 -04:00
|
|
|
launch_params.local_[0], launch_params.local_[1], launch_params.local_[2],
|
2021-05-26 11:02:51 -07:00
|
|
|
kernel->getDeviceKernel(*device)->workGroupInfo()->size_,
|
|
|
|
|
function->name().c_str());
|
2021-05-06 22:38:50 -07:00
|
|
|
return hipErrorLaunchFailure;
|
2021-03-12 19:15:11 -05:00
|
|
|
}
|
|
|
|
|
|
2020-04-03 12:13:12 -04:00
|
|
|
if (params & amd::NDRangeKernelCommand::CooperativeGroups) {
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!device->info().cooperativeGroups_) {
|
2020-04-03 12:13:12 -04:00
|
|
|
return hipErrorLaunchFailure;
|
|
|
|
|
}
|
|
|
|
|
int num_blocks = 0;
|
2020-05-27 14:39:30 -05:00
|
|
|
int max_blocks_per_grid = 0;
|
|
|
|
|
int best_block_size = 0;
|
2025-05-06 15:06:13 -04:00
|
|
|
int block_size = launch_params.local_.product();
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t err = hip_impl::ihipOccupancyMaxActiveBlocksPerMultiprocessor(
|
2025-05-06 15:06:13 -04:00
|
|
|
&num_blocks, &max_blocks_per_grid, &best_block_size, *device, f, block_size,
|
|
|
|
|
launch_params.sharedMemBytes_, true);
|
2022-03-02 11:46:56 -08:00
|
|
|
if (err != hipSuccess) {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
if (((launch_params.global_.product()) / block_size) > unsigned(max_blocks_per_grid)) {
|
2020-04-03 12:13:12 -04:00
|
|
|
return hipErrorCooperativeLaunchTooLarge;
|
|
|
|
|
}
|
2019-06-12 10:00:38 -04:00
|
|
|
}
|
2020-04-06 11:33:53 -04:00
|
|
|
if (params & amd::NDRangeKernelCommand::CooperativeMultiDeviceGroups) {
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!device->info().cooperativeMultiDeviceGroups_) {
|
2020-04-06 11:33:53 -04:00
|
|
|
return hipErrorLaunchFailure;
|
|
|
|
|
}
|
2019-06-12 10:00:38 -04:00
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipLaunchKernelCommand(amd::Command*& command, hipFunction_t f,
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::LaunchParams& launch_params, hip::Stream* stream,
|
|
|
|
|
void** kernelParams, void** extra,
|
2021-03-11 12:10:49 -08:00
|
|
|
hipEvent_t startEvent = nullptr, hipEvent_t stopEvent = nullptr,
|
|
|
|
|
uint32_t flags = 0, uint32_t params = 0, uint32_t gridId = 0,
|
|
|
|
|
uint32_t numGrids = 0, uint64_t prevGridSum = 0,
|
|
|
|
|
uint64_t allGridSum = 0, uint32_t firstDevice = 0) {
|
|
|
|
|
hip::DeviceFunc* function = hip::DeviceFunc::asFunction(f);
|
|
|
|
|
amd::Kernel* kernel = function->kernel();
|
|
|
|
|
|
|
|
|
|
size_t globalWorkOffset[3] = {0};
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::NDRangeContainer ndrange(3, globalWorkOffset, launch_params.global_.Data(),
|
|
|
|
|
launch_params.local_.Data());
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Command::EventWaitList waitList;
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2021-11-29 17:53:36 +00:00
|
|
|
bool profileNDRange = (startEvent != nullptr || stopEvent != nullptr);
|
2020-07-22 11:35:15 -07:00
|
|
|
|
2020-07-21 06:31:13 -04:00
|
|
|
// Flag set to 1 signifies that kernel can be launched in anyorder
|
|
|
|
|
if (flags & hipExtAnyOrderLaunch) {
|
2021-03-11 12:10:49 -08:00
|
|
|
params |= amd::NDRangeKernelCommand::AnyOrderLaunch;
|
2020-07-21 06:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::NDRangeKernelCommand* kernelCommand = new amd::NDRangeKernelCommand(*stream, waitList,
|
|
|
|
|
*kernel, ndrange, launch_params.sharedMemBytes_, params, gridId, numGrids, prevGridSum,
|
|
|
|
|
allGridSum, firstDevice, profileNDRange);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!kernelCommand) {
|
2018-03-01 22:57:20 -05:00
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 20:27:08 -04:00
|
|
|
address kernargs = nullptr;
|
|
|
|
|
// 'extra' is a struct that contains the following info: {
|
|
|
|
|
// HIP_LAUNCH_PARAM_BUFFER_POINTER, kernargs,
|
|
|
|
|
// HIP_LAUNCH_PARAM_BUFFER_SIZE, &kernargs_size,
|
|
|
|
|
// HIP_LAUNCH_PARAM_END }
|
|
|
|
|
if (extra != nullptr) {
|
|
|
|
|
assert(kernelParams == nullptr);
|
|
|
|
|
if (extra[0] != HIP_LAUNCH_PARAM_BUFFER_POINTER || extra[2] != HIP_LAUNCH_PARAM_BUFFER_SIZE ||
|
|
|
|
|
extra[4] != HIP_LAUNCH_PARAM_END) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
kernargs = reinterpret_cast<address>(extra[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DEBUG_HIP_KERNARG_COPY_OPT) {
|
|
|
|
|
if (CL_SUCCESS != kernelCommand->AllocCaptureSetValidate(kernelParams, kernargs)) {
|
|
|
|
|
kernelCommand->release();
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2024-07-10 15:30:15 -04:00
|
|
|
|
2024-05-15 20:27:08 -04:00
|
|
|
} else {
|
|
|
|
|
for (size_t i = 0; i < kernel->signature().numParameters(); ++i) {
|
|
|
|
|
const amd::KernelParameterDescriptor& desc = kernel->signature().at(i);
|
|
|
|
|
if (kernelParams == nullptr) {
|
|
|
|
|
assert(kernargs != nullptr);
|
|
|
|
|
kernel->parameters().set(i, desc.size_, kernargs + desc.offset_,
|
|
|
|
|
desc.type_ == T_POINTER /*svmBound*/);
|
|
|
|
|
} else {
|
|
|
|
|
kernel->parameters().set(i, desc.size_, kernelParams[i],
|
|
|
|
|
desc.type_ == T_POINTER /*svmBound*/);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Capture the kernel arguments
|
|
|
|
|
if (CL_SUCCESS != kernelCommand->captureAndValidate()) {
|
|
|
|
|
kernelCommand->release();
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2023-02-08 16:15:10 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
command = kernelCommand;
|
2023-02-08 16:15:10 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
hipError_t ihipModuleLaunchKernel(hipFunction_t f, amd::LaunchParams& launch_params,
|
|
|
|
|
hipStream_t hStream, void** kernelParams, void** extra,
|
|
|
|
|
hipEvent_t startEvent, hipEvent_t stopEvent, uint32_t flags = 0,
|
|
|
|
|
uint32_t params = 0, uint32_t gridId = 0, uint32_t numGrids = 0,
|
|
|
|
|
uint64_t prevGridSum = 0, uint64_t allGridSum = 0,
|
|
|
|
|
uint32_t firstDevice = 0) {
|
2021-04-27 19:03:22 -04:00
|
|
|
int deviceId = hip::Stream::DeviceId(hStream);
|
2022-10-10 12:38:00 +00:00
|
|
|
HIP_RETURN_ONFAIL(PlatformState::instance().initStatManagedVarDevicePtr(deviceId));
|
2022-09-14 18:13:55 -07:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (f == nullptr) {
|
|
|
|
|
LogPrintfError("%s", "Function passed is null");
|
2022-11-23 14:03:14 -05:00
|
|
|
return hipErrorInvalidResourceHandle;
|
2021-03-11 12:10:49 -08:00
|
|
|
}
|
|
|
|
|
hip::DeviceFunc* function = hip::DeviceFunc::asFunction(f);
|
|
|
|
|
amd::Kernel* kernel = function->kernel();
|
2024-10-15 03:57:01 +00:00
|
|
|
amd::ScopedLock lock (DEBUG_HIP_KERNARG_COPY_OPT ? nullptr : &function->dflock_);
|
2021-03-11 12:10:49 -08:00
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
hipError_t status = ihipLaunchKernel_validate(f, launch_params, kernelParams, extra, deviceId,
|
|
|
|
|
params);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
|
2023-04-11 17:16:49 -04:00
|
|
|
// Make sure the app doesn't launch a workgroup bigger than the global size
|
2025-05-06 15:06:13 -04:00
|
|
|
if (launch_params.global_[0] < launch_params.local_[0]) {
|
|
|
|
|
launch_params.local_[0] = launch_params.global_[0];
|
|
|
|
|
}
|
|
|
|
|
if (launch_params.global_[1] < launch_params.local_[1]) {
|
|
|
|
|
launch_params.local_[1] = launch_params.global_[1];
|
|
|
|
|
}
|
|
|
|
|
if (launch_params.global_[2] < launch_params.local_[2]) {
|
|
|
|
|
launch_params.local_[2] = launch_params.global_[2];
|
|
|
|
|
}
|
2023-04-11 17:16:49 -04:00
|
|
|
|
2023-04-17 18:41:25 -04:00
|
|
|
auto device = g_devices[deviceId]->devices()[0];
|
|
|
|
|
// Check if it's a uniform kernel and validate dimensions
|
|
|
|
|
if (kernel->getDeviceKernel(*device)->getUniformWorkGroupSize()) {
|
2025-05-06 15:06:13 -04:00
|
|
|
if (((launch_params.global_[0] % launch_params.local_[0]) != 0) ||
|
|
|
|
|
((launch_params.global_[1] % launch_params.local_[1]) != 0) ||
|
|
|
|
|
((launch_params.global_[2] % launch_params.local_[2]) != 0)) {
|
2023-04-17 18:41:25 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Command* command = nullptr;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(hStream);
|
2025-05-06 15:06:13 -04:00
|
|
|
status = ihipLaunchKernelCommand(command, f, launch_params, hip_stream, kernelParams, extra,
|
|
|
|
|
startEvent, stopEvent, flags, params, gridId, numGrids,
|
|
|
|
|
prevGridSum, allGridSum, firstDevice);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 06:41:34 -04:00
|
|
|
if (startEvent != nullptr) {
|
2021-10-19 00:01:41 -04:00
|
|
|
hip::Event* eStart = reinterpret_cast<hip::Event*>(startEvent);
|
2025-04-28 15:09:11 +05:30
|
|
|
status = eStart->addMarker(hip_stream, nullptr);
|
2021-10-19 00:01:41 -04:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
2021-10-19 00:01:41 -04:00
|
|
|
|
2020-07-14 06:41:34 -04:00
|
|
|
if (stopEvent != nullptr) {
|
2021-10-19 00:01:41 -04:00
|
|
|
hip::Event* eStop = reinterpret_cast<hip::Event*>(stopEvent);
|
2024-05-17 12:08:20 -07:00
|
|
|
if (eStop->flags_ & hipEventDisableSystemFence) {
|
2024-12-03 23:45:31 +00:00
|
|
|
command->setCommandEntryScope(amd::Device::kCacheStateIgnore);
|
2023-01-20 15:35:25 -08:00
|
|
|
} else {
|
2024-12-03 23:45:31 +00:00
|
|
|
command->setCommandEntryScope(amd::Device::kCacheStateSystem);
|
2023-01-20 15:35:25 -08:00
|
|
|
}
|
|
|
|
|
// Enqueue Dispatch and bind the stop event
|
|
|
|
|
command->enqueue();
|
2025-02-11 13:50:05 +00:00
|
|
|
eStop->BindCommand(*command);
|
2023-01-20 15:35:25 -08:00
|
|
|
} else {
|
|
|
|
|
command->enqueue();
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
2023-02-16 12:41:20 -05:00
|
|
|
|
|
|
|
|
if (command->status() == CL_INVALID_OPERATION) {
|
|
|
|
|
command->release();
|
|
|
|
|
return hipErrorIllegalState;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 22:57:20 -05:00
|
|
|
command->release();
|
|
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipModuleLaunchKernel(hipFunction_t f, uint32_t gridDimX, uint32_t gridDimY,
|
|
|
|
|
uint32_t gridDimZ, uint32_t blockDimX, uint32_t blockDimY,
|
|
|
|
|
uint32_t blockDimZ, uint32_t sharedMemBytes, hipStream_t hStream,
|
|
|
|
|
void** kernelParams, void** extra) {
|
|
|
|
|
HIP_INIT_API(hipModuleLaunchKernel, f, gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY,
|
|
|
|
|
blockDimZ, sharedMemBytes, hStream, kernelParams, extra);
|
2022-08-22 03:22:44 -07:00
|
|
|
|
2022-11-24 15:44:38 +00:00
|
|
|
if (!hip::isValid(hStream)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-22 03:22:44 -07:00
|
|
|
STREAM_CAPTURE(hipModuleLaunchKernel, hStream, f, gridDimX, gridDimY, gridDimZ, blockDimX,
|
|
|
|
|
blockDimY, blockDimZ, sharedMemBytes, kernelParams, extra);
|
2024-06-05 14:27:01 +02:00
|
|
|
|
|
|
|
|
constexpr auto int32_max = static_cast<uint64_t>(std::numeric_limits<int32_t>::max());
|
|
|
|
|
constexpr auto uint16_max = static_cast<uint64_t>(std::numeric_limits<uint16_t>::max()) + 1;
|
|
|
|
|
if (gridDimX > int32_max || gridDimY > uint16_max || gridDimZ > uint16_max) {
|
2023-04-24 21:38:53 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
|
|
|
|
|
amd::HIPLaunchParams launch_params(gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ,
|
|
|
|
|
sharedMemBytes);
|
|
|
|
|
if (!launch_params.IsValidConfig()) {
|
2020-07-14 06:41:34 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
|
|
|
|
|
HIP_RETURN(ihipModuleLaunchKernel(f, launch_params, hStream, kernelParams, extra, nullptr,
|
|
|
|
|
nullptr));
|
2018-08-02 02:14:04 -04:00
|
|
|
}
|
|
|
|
|
|
2023-12-20 11:42:11 +00:00
|
|
|
hipError_t hipExtModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
|
2019-05-06 18:02:54 -04:00
|
|
|
uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
|
|
|
|
|
uint32_t localWorkSizeX, uint32_t localWorkSizeY,
|
|
|
|
|
uint32_t localWorkSizeZ, size_t sharedMemBytes,
|
|
|
|
|
hipStream_t hStream, void** kernelParams, void** extra,
|
2022-03-14 12:36:16 -04:00
|
|
|
hipEvent_t startEvent, hipEvent_t stopEvent, uint32_t flags) {
|
2020-05-14 03:50:34 -05:00
|
|
|
HIP_INIT_API(hipExtModuleLaunchKernel, f, globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ,
|
2022-03-14 12:36:16 -04:00
|
|
|
localWorkSizeX, localWorkSizeY, localWorkSizeZ, sharedMemBytes, hStream,
|
2019-09-12 14:35:36 -04:00
|
|
|
kernelParams, extra, startEvent, stopEvent, flags);
|
|
|
|
|
|
2022-11-24 15:44:38 +00:00
|
|
|
if (!hip::isValid(hStream)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 04:37:25 -07:00
|
|
|
STREAM_CAPTURE(hipExtModuleLaunchKernel, hStream, f, globalWorkSizeX, globalWorkSizeY,
|
|
|
|
|
globalWorkSizeZ, localWorkSizeX, localWorkSizeY, localWorkSizeZ, sharedMemBytes,
|
|
|
|
|
kernelParams, extra, startEvent, stopEvent, flags);
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::LaunchParams launch_params(globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ,
|
|
|
|
|
localWorkSizeX, localWorkSizeY, localWorkSizeZ,
|
|
|
|
|
sharedMemBytes);
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipModuleLaunchKernel(f, launch_params, hStream, kernelParams, extra, startEvent,
|
|
|
|
|
stopEvent, flags));
|
2019-05-06 18:02:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-12-20 11:42:11 +00:00
|
|
|
hipError_t hipHccModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
|
2020-07-14 06:41:34 -04:00
|
|
|
uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
|
2022-03-14 12:36:16 -04:00
|
|
|
uint32_t blockDimX, uint32_t blockDimY, uint32_t blockDimZ,
|
|
|
|
|
size_t sharedMemBytes, hipStream_t hStream, void** kernelParams,
|
|
|
|
|
void** extra, hipEvent_t startEvent, hipEvent_t stopEvent) {
|
2020-07-14 06:41:34 -04:00
|
|
|
HIP_INIT_API(hipHccModuleLaunchKernel, f, globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ,
|
2022-03-14 12:36:16 -04:00
|
|
|
blockDimX, blockDimY, blockDimZ, sharedMemBytes, hStream, kernelParams, extra,
|
|
|
|
|
startEvent, stopEvent);
|
2019-09-12 14:35:36 -04:00
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::LaunchParams launch_params(globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ, blockDimX,
|
|
|
|
|
blockDimY, blockDimZ, sharedMemBytes);
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipModuleLaunchKernel(f, launch_params, hStream, kernelParams, extra, startEvent,
|
|
|
|
|
stopEvent));
|
2018-08-02 02:14:04 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-06 00:04:55 +05:30
|
|
|
hipError_t hipModuleLaunchCooperativeKernel(hipFunction_t f, unsigned int gridDimX,
|
|
|
|
|
unsigned int gridDimY, unsigned int gridDimZ,
|
|
|
|
|
unsigned int blockDimX, unsigned int blockDimY,
|
|
|
|
|
unsigned int blockDimZ, unsigned int sharedMemBytes,
|
|
|
|
|
hipStream_t stream, void** kernelParams) {
|
|
|
|
|
HIP_INIT_API(hipModuleLaunchCooperativeKernel, f, gridDimX, gridDimY, gridDimZ, blockDimX,
|
|
|
|
|
blockDimY, blockDimZ, sharedMemBytes, stream, kernelParams);
|
|
|
|
|
|
|
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 14:03:23 +02:00
|
|
|
STREAM_CAPTURE(hipModuleLaunchCooperativeKernel, stream, f, gridDimX, gridDimY, gridDimZ,
|
|
|
|
|
blockDimX, blockDimY, blockDimZ, sharedMemBytes, kernelParams);
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::HIPLaunchParams launch_params(gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ,
|
|
|
|
|
sharedMemBytes);
|
|
|
|
|
|
|
|
|
|
if (!launch_params.IsValidConfig()) {
|
2022-12-06 00:04:55 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
|
|
|
|
|
HIP_RETURN(ihipModuleLaunchKernel(f, launch_params, stream, kernelParams, nullptr, nullptr,
|
|
|
|
|
nullptr, 0, amd::NDRangeKernelCommand::CooperativeGroups));
|
2022-12-06 00:04:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipModuleLaunchCooperativeKernelMultiDevice(hipFunctionLaunchParams* launchParamsList,
|
|
|
|
|
unsigned int numDevices,
|
|
|
|
|
unsigned int flags,
|
|
|
|
|
uint32_t extFlags) {
|
|
|
|
|
int numActiveGPUs = 0;
|
|
|
|
|
hipError_t result = hipSuccess;
|
|
|
|
|
result = ihipDeviceGetCount(&numActiveGPUs);
|
|
|
|
|
|
2023-01-10 14:28:39 +00:00
|
|
|
if ((numDevices == 0) || (numDevices > numActiveGPUs)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-11 17:16:49 -04:00
|
|
|
if (flags > (hipCooperativeLaunchMultiDeviceNoPostSync +
|
2023-01-31 13:22:22 +00:00
|
|
|
hipCooperativeLaunchMultiDeviceNoPreSync)) {
|
2022-12-06 00:04:55 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t allGridSize = 0;
|
|
|
|
|
std::vector<const amd::Device*> mgpu_list(numDevices);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numDevices; ++i) {
|
|
|
|
|
uint32_t blockDims = 0;
|
|
|
|
|
const hipFunctionLaunchParams& launch = launchParamsList[i];
|
|
|
|
|
blockDims = launch.blockDimX * launch.blockDimY * launch.blockDimZ;
|
|
|
|
|
allGridSize += launch.gridDimX * launch.gridDimY * launch.gridDimZ * blockDims;
|
|
|
|
|
|
|
|
|
|
// Make sure block dimensions are valid
|
|
|
|
|
if (0 == blockDims) {
|
|
|
|
|
return hipErrorInvalidConfiguration;
|
|
|
|
|
}
|
|
|
|
|
if (launch.hStream != nullptr) {
|
|
|
|
|
// Validate devices to make sure it dosn't have duplicates
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = reinterpret_cast<hip::Stream*>(launch.hStream);
|
|
|
|
|
auto device = &hip_stream->vdev()->device();
|
2022-12-06 00:04:55 +05:30
|
|
|
for (int j = 0; j < numDevices; ++j) {
|
|
|
|
|
if (mgpu_list[j] == device) {
|
|
|
|
|
return hipErrorInvalidDevice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mgpu_list[i] = device;
|
|
|
|
|
} else {
|
|
|
|
|
return hipErrorInvalidResourceHandle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uint64_t prevGridSize = 0;
|
|
|
|
|
uint32_t firstDevice = 0;
|
|
|
|
|
|
|
|
|
|
// Sync the execution streams on all devices
|
|
|
|
|
if ((flags & hipCooperativeLaunchMultiDeviceNoPreSync) == 0) {
|
|
|
|
|
for (int i = 0; i < numDevices; ++i) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream =
|
|
|
|
|
reinterpret_cast<hip::Stream*>(launchParamsList[i].hStream);
|
|
|
|
|
hip_stream->finish();
|
2022-12-06 00:04:55 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 11:20:24 +00:00
|
|
|
// Grid and Block dimensions should match across devices, as well as sharedMemBytes
|
|
|
|
|
for (uint32_t i = 1; i < numDevices; ++i) {
|
|
|
|
|
if (launchParamsList[i - 1].gridDimX != launchParamsList[i].gridDimX ||
|
|
|
|
|
launchParamsList[i - 1].gridDimY != launchParamsList[i].gridDimY ||
|
|
|
|
|
launchParamsList[i - 1].gridDimZ != launchParamsList[i].gridDimZ ||
|
|
|
|
|
launchParamsList[i - 1].blockDimX != launchParamsList[i].blockDimX ||
|
|
|
|
|
launchParamsList[i - 1].blockDimY != launchParamsList[i].blockDimY ||
|
|
|
|
|
launchParamsList[i - 1].blockDimZ != launchParamsList[i].blockDimZ) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (launchParamsList[i - 1].sharedMemBytes != launchParamsList[i].sharedMemBytes) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 00:04:55 +05:30
|
|
|
for (int i = 0; i < numDevices; ++i) {
|
|
|
|
|
const hipFunctionLaunchParams& launch = launchParamsList[i];
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = reinterpret_cast<hip::Stream*>(launch.hStream);
|
2022-12-06 00:04:55 +05:30
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
// The order of devices in the launch may not match the order in the global array
|
|
|
|
|
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
|
|
|
|
// Find the matching device
|
2023-02-08 20:18:11 +00:00
|
|
|
if (&hip_stream->vdev()->device() == g_devices[dev]->devices()[0]) {
|
2022-12-06 00:04:55 +05:30
|
|
|
// Save ROCclr index of the first device in the launch
|
2023-02-08 20:18:11 +00:00
|
|
|
firstDevice = hip_stream->vdev()->device().index();
|
2022-12-06 00:04:55 +05:30
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::HIPLaunchParams launch_params(launch.gridDimX, launch.gridDimY, launch.gridDimZ,
|
|
|
|
|
launch.blockDimX, launch.blockDimY, launch.blockDimZ,
|
|
|
|
|
launch.sharedMemBytes);
|
|
|
|
|
|
|
|
|
|
if (!launch_params.IsValidConfig()) {
|
2022-12-06 00:04:55 +05:30
|
|
|
return hipErrorInvalidConfiguration;
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
|
2022-12-06 00:04:55 +05:30
|
|
|
result = ihipModuleLaunchKernel(
|
2025-05-06 15:06:13 -04:00
|
|
|
launch.function, launch_params, launch.hStream, launch.kernelParams,
|
2022-12-06 00:04:55 +05:30
|
|
|
nullptr, nullptr, nullptr, flags, extFlags,
|
|
|
|
|
i, numDevices, prevGridSize, allGridSize, firstDevice);
|
|
|
|
|
if (result != hipSuccess) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-05-06 15:06:13 -04:00
|
|
|
prevGridSize += launch_params.global_.product();
|
2022-12-06 00:04:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sync the execution streams on all devices
|
|
|
|
|
if ((flags & hipCooperativeLaunchMultiDeviceNoPostSync) == 0) {
|
|
|
|
|
for (int i = 0; i < numDevices; ++i) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream =
|
|
|
|
|
reinterpret_cast<hip::Stream*>(launchParamsList[i].hStream);
|
|
|
|
|
hip_stream->finish();
|
2022-12-06 00:04:55 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipModuleLaunchCooperativeKernelMultiDevice(hipFunctionLaunchParams* launchParamsList,
|
|
|
|
|
unsigned int numDevices,
|
|
|
|
|
unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipModuleLaunchCooperativeKernelMultiDevice, launchParamsList, numDevices, flags);
|
|
|
|
|
|
|
|
|
|
if (launchParamsList == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate all streams passed by user
|
|
|
|
|
for (int i = 0; i < numDevices; ++i) {
|
|
|
|
|
if (!hip::isValid(launchParamsList[i].hStream)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipModuleLaunchCooperativeKernelMultiDevice(
|
|
|
|
|
launchParamsList,
|
|
|
|
|
numDevices,
|
|
|
|
|
flags,
|
|
|
|
|
(amd::NDRangeKernelCommand::CooperativeGroups |
|
|
|
|
|
amd::NDRangeKernelCommand::CooperativeMultiDeviceGroups)));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 09:42:48 +00:00
|
|
|
hipError_t hipGetFuncBySymbol(hipFunction_t* functionPtr, const void* symbolPtr) {
|
|
|
|
|
HIP_INIT_API(hipGetFuncBySymbol, functionPtr, symbolPtr);
|
|
|
|
|
|
|
|
|
|
hipError_t hip_error = PlatformState::instance().getStatFunc(functionPtr,
|
|
|
|
|
symbolPtr, ihipGetDevice());
|
|
|
|
|
|
|
|
|
|
if ((hip_error != hipSuccess) || (functionPtr == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDeviceFunction);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-12 11:36:28 +00:00
|
|
|
hipError_t hipLaunchKernel_common(const void* hostFunction, dim3 gridDim, dim3 blockDim,
|
2022-03-14 12:36:16 -04:00
|
|
|
void** args, size_t sharedMemBytes,
|
|
|
|
|
hipStream_t stream) {
|
2022-04-13 06:35:25 +00:00
|
|
|
STREAM_CAPTURE(hipLaunchKernel, stream, hostFunction, gridDim, blockDim, args, sharedMemBytes);
|
2022-03-14 12:36:16 -04:00
|
|
|
return ihipLaunchKernel(hostFunction, gridDim, blockDim, args, sharedMemBytes, stream, nullptr,
|
|
|
|
|
nullptr, 0);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-12 11:36:28 +00:00
|
|
|
hipError_t hipLaunchKernel(const void* hostFunction, dim3 gridDim, dim3 blockDim,
|
2022-03-14 12:36:16 -04:00
|
|
|
void** args, size_t sharedMemBytes, hipStream_t stream) {
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_INIT_API(hipLaunchKernel, hostFunction, gridDim, blockDim, args, sharedMemBytes, stream);
|
2024-10-15 03:57:01 +00:00
|
|
|
HIP_RETURN_DURATION(hipLaunchKernel_common(hostFunction, gridDim, blockDim, args, sharedMemBytes, stream));
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 10:46:05 +00:00
|
|
|
hipError_t hipLaunchKernel_spt(const void* hostFunction, dim3 gridDim, dim3 blockDim,
|
2022-03-14 12:36:16 -04:00
|
|
|
void** args, size_t sharedMemBytes, hipStream_t stream) {
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_INIT_API(hipLaunchKernel, hostFunction, gridDim, blockDim, args, sharedMemBytes, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipLaunchKernel_common(hostFunction, gridDim, blockDim, args, sharedMemBytes, stream));
|
2020-05-08 18:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 10:46:05 +00:00
|
|
|
hipError_t hipExtLaunchKernel(const void* hostFunction, dim3 gridDim, dim3 blockDim,
|
2022-03-14 12:36:16 -04:00
|
|
|
void** args, size_t sharedMemBytes, hipStream_t stream,
|
|
|
|
|
hipEvent_t startEvent, hipEvent_t stopEvent, int flags) {
|
2022-09-14 18:13:55 -07:00
|
|
|
HIP_INIT_API(hipExtLaunchKernel, hostFunction, gridDim, blockDim, args, sharedMemBytes,
|
|
|
|
|
stream, startEvent, stopEvent, flags);
|
2022-12-20 15:49:15 +00:00
|
|
|
|
2024-06-03 11:17:51 +00:00
|
|
|
if (!hip::isValid(startEvent) || !hip::isValid(stopEvent)) {
|
2022-12-20 15:49:15 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 05:01:55 +00:00
|
|
|
STREAM_CAPTURE(hipExtLaunchKernel, stream, hostFunction, gridDim, blockDim, args, sharedMemBytes,
|
|
|
|
|
startEvent, stopEvent, flags);
|
2022-03-14 12:36:16 -04:00
|
|
|
HIP_RETURN(ihipLaunchKernel(hostFunction, gridDim, blockDim, args, sharedMemBytes, stream,
|
|
|
|
|
startEvent, stopEvent, flags));
|
2020-05-08 18:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipLaunchCooperativeKernel_common(const void* f, dim3 gridDim, dim3 blockDim,
|
|
|
|
|
void** kernelParams, uint32_t sharedMemBytes,
|
|
|
|
|
hipStream_t hStream) {
|
2022-01-07 09:41:24 +00:00
|
|
|
if (!hip::isValid(hStream)) {
|
2024-04-16 20:04:16 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-31 17:40:10 +01:00
|
|
|
STREAM_CAPTURE(hipLaunchCooperativeKernel, hStream, f, gridDim, blockDim, kernelParams,
|
|
|
|
|
sharedMemBytes);
|
|
|
|
|
|
2024-04-16 20:04:16 +00:00
|
|
|
if (f == nullptr) {
|
|
|
|
|
return hipErrorInvalidDeviceFunction;
|
2022-01-07 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-18 22:40:33 -04:00
|
|
|
hipFunction_t func = nullptr;
|
2021-04-27 19:03:22 -04:00
|
|
|
int deviceId = hip::Stream::DeviceId(hStream);
|
2023-03-13 13:32:55 +00:00
|
|
|
hipError_t getStatFuncError = PlatformState::instance().getStatFunc(&func, f, deviceId);
|
|
|
|
|
if (getStatFuncError != hipSuccess) {
|
|
|
|
|
return getStatFuncError;
|
|
|
|
|
}
|
2022-11-23 14:03:14 -05:00
|
|
|
const amd::Device* device = g_devices[deviceId]->devices()[0];
|
2025-05-06 15:06:13 -04:00
|
|
|
|
|
|
|
|
amd::HIPLaunchParams launch_params(gridDim.x, gridDim.y, gridDim.z, blockDim.x, blockDim.y,
|
|
|
|
|
blockDim.z, sharedMemBytes);
|
|
|
|
|
|
|
|
|
|
if (!launch_params.IsValidConfig() ||
|
|
|
|
|
launch_params.local_.product() > device->info().maxWorkGroupSize_) {
|
2023-03-13 13:32:55 +00:00
|
|
|
return hipErrorInvalidConfiguration;
|
2020-07-14 06:41:34 -04:00
|
|
|
}
|
2022-11-23 14:03:14 -05:00
|
|
|
|
2024-04-16 20:04:16 +00:00
|
|
|
if (sharedMemBytes > device->info().localMemSizePerCU_) {
|
|
|
|
|
return hipErrorCooperativeLaunchTooLarge;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
//if (globalWorkSizeX == 0 || globalWorkSizeY == 0 || globalWorkSizeZ == 0) {
|
|
|
|
|
if (launch_params.global_[0] == 0 || launch_params.global_[1] == 0
|
|
|
|
|
|| launch_params.global_[2] == 0) {
|
2025-04-22 09:17:37 -07:00
|
|
|
return hipErrorInvalidConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
return ihipModuleLaunchKernel(func, launch_params, hStream, kernelParams, nullptr,
|
|
|
|
|
nullptr, nullptr, 0, amd::NDRangeKernelCommand::CooperativeGroups);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipLaunchCooperativeKernel(const void* f, dim3 gridDim, dim3 blockDim,
|
|
|
|
|
void** kernelParams, uint32_t sharedMemBytes,
|
|
|
|
|
hipStream_t hStream) {
|
|
|
|
|
HIP_INIT_API(hipLaunchCooperativeKernel, f, gridDim, blockDim, sharedMemBytes, hStream);
|
|
|
|
|
HIP_RETURN(hipLaunchCooperativeKernel_common(f, gridDim, blockDim, kernelParams, sharedMemBytes,
|
|
|
|
|
hStream));
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipLaunchCooperativeKernel_spt(const void* f, dim3 gridDim, dim3 blockDim,
|
|
|
|
|
void** kernelParams, uint32_t sharedMemBytes,
|
|
|
|
|
hipStream_t hStream) {
|
|
|
|
|
HIP_INIT_API(hipLaunchCooperativeKernel, f, gridDim, blockDim, sharedMemBytes, hStream);
|
2022-04-13 06:35:25 +00:00
|
|
|
PER_THREAD_DEFAULT_STREAM(hStream);
|
2022-03-14 12:36:16 -04:00
|
|
|
HIP_RETURN(hipLaunchCooperativeKernel_common(f, gridDim, blockDim, kernelParams, sharedMemBytes,
|
|
|
|
|
hStream));
|
2019-06-12 10:00:38 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t ihipLaunchCooperativeKernelMultiDevice(hipLaunchParams* launchParamsList, int numDevices,
|
|
|
|
|
unsigned int flags, uint32_t extFlags) {
|
2024-09-26 17:35:43 -07:00
|
|
|
if (launchParamsList == nullptr || numDevices > g_devices.size()) {
|
2019-06-20 18:13:20 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-04-06 13:54:03 -04:00
|
|
|
|
2022-12-06 00:04:55 +05:30
|
|
|
std::vector<hipFunctionLaunchParams> functionLaunchParamsList(numDevices);
|
|
|
|
|
// Convert hipLaunchParams to hipFunctionLaunchParams
|
2019-10-16 11:24:09 -04:00
|
|
|
for (int i = 0; i < numDevices; ++i) {
|
2022-12-06 00:04:55 +05:30
|
|
|
hipLaunchParams& launch = launchParamsList[i];
|
|
|
|
|
// Validate stream passed by user
|
|
|
|
|
if (!hip::isValid(launch.stream)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
2020-04-06 11:33:53 -04:00
|
|
|
}
|
|
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(launch.stream);
|
2019-10-16 11:24:09 -04:00
|
|
|
hipFunction_t func = nullptr;
|
|
|
|
|
// The order of devices in the launch may not match the order in the global array
|
|
|
|
|
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
|
|
|
|
// Find the matching device and request the kernel function
|
2023-02-08 20:18:11 +00:00
|
|
|
if (&hip_stream->vdev()->device() == g_devices[dev]->devices()[0]) {
|
2020-05-18 22:40:33 -04:00
|
|
|
IHIP_RETURN_ONFAIL(PlatformState::instance().getStatFunc(&func, launch.func, dev));
|
2019-10-16 11:24:09 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-12 10:00:38 -04:00
|
|
|
if (func == nullptr) {
|
2022-12-06 00:04:55 +05:30
|
|
|
return hipErrorInvalidDeviceFunction;
|
2019-06-12 10:00:38 -04:00
|
|
|
}
|
2019-06-20 18:13:20 -04:00
|
|
|
|
2025-04-16 10:35:48 +02:00
|
|
|
// functions should match across all devices
|
|
|
|
|
if (i > 0 && launch.func != launchParamsList[i - 1].func) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 00:04:55 +05:30
|
|
|
functionLaunchParamsList[i].function = func;
|
|
|
|
|
functionLaunchParamsList[i].gridDimX = launch.gridDim.x;
|
|
|
|
|
functionLaunchParamsList[i].gridDimY = launch.gridDim.y;
|
|
|
|
|
functionLaunchParamsList[i].gridDimZ = launch.gridDim.z;
|
|
|
|
|
functionLaunchParamsList[i].blockDimX = launch.blockDim.x;
|
|
|
|
|
functionLaunchParamsList[i].blockDimY = launch.blockDim.y;
|
|
|
|
|
functionLaunchParamsList[i].blockDimZ = launch.blockDim.z;
|
|
|
|
|
functionLaunchParamsList[i].sharedMemBytes = launch.sharedMem;
|
|
|
|
|
functionLaunchParamsList[i].hStream = launch.stream;
|
|
|
|
|
functionLaunchParamsList[i].kernelParams = launch.args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipModuleLaunchCooperativeKernelMultiDevice(functionLaunchParamsList.data(),
|
|
|
|
|
functionLaunchParamsList.size(),
|
|
|
|
|
flags,
|
|
|
|
|
extFlags);
|
2019-06-12 10:00:38 -04:00
|
|
|
}
|
2019-06-20 18:13:20 -04:00
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipLaunchCooperativeKernelMultiDevice(hipLaunchParams* launchParamsList, int numDevices,
|
|
|
|
|
unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipLaunchCooperativeKernelMultiDevice, launchParamsList, numDevices, flags);
|
2019-08-27 20:26:25 -04:00
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
HIP_RETURN(ihipLaunchCooperativeKernelMultiDevice(
|
|
|
|
|
launchParamsList, numDevices, flags,
|
|
|
|
|
(amd::NDRangeKernelCommand::CooperativeGroups |
|
|
|
|
|
amd::NDRangeKernelCommand::CooperativeMultiDeviceGroups)));
|
2019-06-20 18:13:20 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t hipExtLaunchMultiKernelMultiDevice(hipLaunchParams* launchParamsList, int numDevices,
|
|
|
|
|
unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipExtLaunchMultiKernelMultiDevice, launchParamsList, numDevices, flags);
|
2019-08-27 20:26:25 -04:00
|
|
|
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(ihipLaunchCooperativeKernelMultiDevice(launchParamsList, numDevices, flags, 0));
|
2019-06-20 18:13:20 -04:00
|
|
|
}
|
2019-08-11 18:53:11 -04:00
|
|
|
|
|
|
|
|
hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const char* name) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipModuleGetTexRef, texRef, hmod, name);
|
2019-08-11 18:53:11 -04:00
|
|
|
|
|
|
|
|
/* input args check */
|
2022-12-26 00:41:30 -05:00
|
|
|
if ((texRef == nullptr) || (name == nullptr) || (strlen(name) == 0)) {
|
2019-08-11 18:53:11 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-12-02 09:15:22 -05:00
|
|
|
if (hmod == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 19:19:25 -04:00
|
|
|
amd::Device* device = hip::getCurrentDevice()->devices()[0];
|
|
|
|
|
const device::Info& info = device->info();
|
|
|
|
|
if (!info.imageSupport_) {
|
|
|
|
|
LogPrintfError("Texture not supported on the device %s", info.name_);
|
|
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
|
|
|
|
}
|
2019-08-11 18:53:11 -04:00
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
/* Get address and size for the global symbol */
|
2020-06-11 17:17:29 -04:00
|
|
|
if (hipSuccess != PlatformState::instance().getDynTexRef(name, hmod, texRef)) {
|
2023-12-07 01:32:20 +00:00
|
|
|
LogPrintfError("Cannot get texRef for name: %s at module:0x%x", name, hmod);
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotFound);
|
2019-08-11 18:53:11 -04:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 12:23:11 -04:00
|
|
|
// Texture references created by HIP driver API
|
|
|
|
|
// have the default read mode set to normalized float.
|
2022-05-16 11:24:09 -04:00
|
|
|
// have format set to format float
|
|
|
|
|
// set num of channels to 1
|
2020-03-18 12:23:11 -04:00
|
|
|
(*texRef)->readMode = hipReadModeNormalizedFloat;
|
2022-05-16 11:24:09 -04:00
|
|
|
(*texRef)->format = HIP_AD_FORMAT_FLOAT;
|
|
|
|
|
(*texRef)->numChannels = 1;
|
2020-03-18 12:23:11 -04:00
|
|
|
|
2022-03-02 11:46:56 -08:00
|
|
|
hipError_t err = PlatformState::instance().registerTexRef(*texRef, hmod, std::string(name));
|
2020-06-11 17:17:29 -04:00
|
|
|
|
2022-03-02 11:46:56 -08:00
|
|
|
HIP_RETURN(err);
|
2019-08-11 18:53:11 -04:00
|
|
|
}
|
2024-10-09 11:24:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
hipError_t hipLinkAddData(hipLinkState_t hip_link_state, hipJitInputType input_type, void* image,
|
|
|
|
|
size_t image_size, const char* name, unsigned int num_options,
|
|
|
|
|
hipJitOption* options_ptr, void** option_values) {
|
|
|
|
|
|
|
|
|
|
HIP_INIT_API(hipLinkAddData, hip_link_state, image, image_size, name, num_options, options_ptr, option_values);
|
|
|
|
|
|
|
|
|
|
if (image == nullptr || image_size <= 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_type == hipJitInputCubin || input_type == hipJitInputPtx ||
|
|
|
|
|
input_type == hipJitInputFatBinary || input_type == hipJitInputObject ||
|
|
|
|
|
input_type == hipJitInputLibrary || input_type == hipJitInputNvvm ||
|
|
|
|
|
input_type == hipJitInputLLVMBitcode || input_type == hipJitInputLLVMBundledBitcode ||
|
|
|
|
|
input_type == hipJitInputLLVMArchivesOfBundledBitcode ) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string input_name;
|
|
|
|
|
if (name) {
|
|
|
|
|
input_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LinkProgram* hip_link_prog_ptr =
|
|
|
|
|
reinterpret_cast<LinkProgram*>(hip_link_state);
|
|
|
|
|
|
|
|
|
|
if (!LinkProgram::isLinkerValid(hip_link_prog_ptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hip_link_prog_ptr->AddLinkerData(image, image_size, input_name, input_type)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipLinkAddFile(hipLinkState_t hip_link_state, hipJitInputType input_type, const char* file_path,
|
|
|
|
|
unsigned int num_options, hipJitOption* options_ptr, void** option_values) {
|
|
|
|
|
HIP_INIT_API(hipLinkAddFile, hip_link_state, input_type, file_path, num_options, options_ptr, option_values);
|
|
|
|
|
|
|
|
|
|
if (hip_link_state == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_type == hipJitInputCubin || input_type == hipJitInputPtx ||
|
|
|
|
|
input_type == hipJitInputFatBinary || input_type == hipJitInputObject ||
|
|
|
|
|
input_type == hipJitInputLibrary || input_type == hipJitInputNvvm ||
|
|
|
|
|
input_type == hipJitInputLLVMBitcode || input_type == hipJitInputLLVMBundledBitcode ||
|
|
|
|
|
input_type == hipJitInputLLVMArchivesOfBundledBitcode ) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LinkProgram* hip_link_prog_ptr =
|
|
|
|
|
reinterpret_cast<LinkProgram*>(hip_link_state);
|
|
|
|
|
|
|
|
|
|
if (!LinkProgram::isLinkerValid(hip_link_prog_ptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hip_link_prog_ptr->AddLinkerFile(std::string(file_path), input_type)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipLinkCreate(unsigned int num_options, hipJitOption* options_ptr,
|
|
|
|
|
void** options_vals_pptr, hipLinkState_t* hip_link_state_ptr) {
|
|
|
|
|
HIP_INIT_API(hipLinkCreate, num_options, options_ptr, options_vals_pptr, hip_link_state_ptr);
|
|
|
|
|
|
|
|
|
|
if (hip_link_state_ptr == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num_options != 0) {
|
|
|
|
|
for (int i = 0; i < num_options; i++) {
|
|
|
|
|
if (options_ptr == nullptr || options_vals_pptr == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string name("LinkerProgram");
|
|
|
|
|
LinkProgram* hip_link_prog_ptr = new LinkProgram(name);
|
|
|
|
|
if (!hip_link_prog_ptr->AddLinkerOptions(num_options, options_ptr, options_vals_pptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*hip_link_state_ptr = reinterpret_cast<hipLinkState_t>(hip_link_prog_ptr);
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipLinkComplete(hipLinkState_t hip_link_state, void** bin_out, size_t* size_out) {
|
|
|
|
|
HIP_INIT_API(hipLinkComplete, hip_link_state, bin_out, size_out);
|
|
|
|
|
|
|
|
|
|
if (bin_out == nullptr || size_out == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LinkProgram* hip_link_prog_ptr =
|
|
|
|
|
reinterpret_cast<LinkProgram*>(hip_link_state);
|
|
|
|
|
|
|
|
|
|
if (!LinkProgram::isLinkerValid(hip_link_prog_ptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hip_link_prog_ptr->LinkComplete(bin_out, size_out)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipLinkDestroy(hipLinkState_t hip_link_state) {
|
|
|
|
|
HIP_INIT_API(hipLinkDestroy, hip_link_state);
|
|
|
|
|
|
|
|
|
|
LinkProgram* hip_link_prog_ptr =
|
|
|
|
|
reinterpret_cast<LinkProgram*>(hip_link_state);
|
|
|
|
|
|
|
|
|
|
if (!LinkProgram::isLinkerValid(hip_link_prog_ptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete hip_link_prog_ptr;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-03 04:10:05 -07:00
|
|
|
hipError_t hipLaunchKernelExC(const hipLaunchConfig_t* config, const void* fPtr, void** args) {
|
|
|
|
|
HIP_INIT_API(hipLaunchKernelExC, config, fPtr, args);
|
2025-04-22 09:17:37 -07:00
|
|
|
if (fPtr == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDeviceFunction);
|
|
|
|
|
}
|
2025-04-03 04:10:05 -07:00
|
|
|
|
2025-04-22 09:17:37 -07:00
|
|
|
if (config == nullptr) {
|
2025-04-03 04:10:05 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 09:17:37 -07:00
|
|
|
if (config->numAttrs == 0) {
|
|
|
|
|
HIP_RETURN_DURATION(hipLaunchKernel_common(fPtr, config->gridDim, config->blockDim, args,
|
|
|
|
|
config->dynamicSmemBytes, config->stream));
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-03 04:10:05 -07:00
|
|
|
for (size_t attr_idx = 0; attr_idx < config->numAttrs; ++attr_idx) {
|
|
|
|
|
hipLaunchAttribute& attr = config->attrs[attr_idx];
|
|
|
|
|
switch (attr.id) {
|
|
|
|
|
case hipLaunchAttributeCooperative:
|
|
|
|
|
if (attr.val.cooperative != 0) {
|
|
|
|
|
HIP_RETURN_DURATION(
|
|
|
|
|
hipLaunchCooperativeKernel_common(fPtr, config->gridDim, config->blockDim, args,
|
|
|
|
|
config->dynamicSmemBytes, config->stream));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
LogPrintfError("Attribute %u not supported", attr.id);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDrvLaunchKernelEx(const HIP_LAUNCH_CONFIG* config, hipFunction_t f,
|
|
|
|
|
void** kernelParams, void** extra) {
|
|
|
|
|
HIP_INIT_API(hipDrvLaunchKernelEx, config, f, kernelParams, extra);
|
2025-04-22 09:17:37 -07:00
|
|
|
if (f == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
|
|
|
|
}
|
2025-04-03 04:10:05 -07:00
|
|
|
|
2025-04-22 09:17:37 -07:00
|
|
|
if (config == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2025-04-03 04:10:05 -07:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 15:06:13 -04:00
|
|
|
amd::HIPLaunchParams launch_params(config->gridDimX, config->gridDimY, config->gridDimZ,
|
|
|
|
|
config->blockDimX, config->blockDimY, config->blockDimZ,
|
|
|
|
|
config->sharedMemBytes);
|
|
|
|
|
|
|
|
|
|
if (!launch_params.IsValidConfig()) {
|
2025-04-03 04:10:05 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 09:17:37 -07:00
|
|
|
if (config->numAttrs == 0) {
|
2025-05-06 15:06:13 -04:00
|
|
|
HIP_RETURN(ihipModuleLaunchKernel(f, launch_params, config->hStream, kernelParams, nullptr,
|
|
|
|
|
nullptr, nullptr, 0));
|
2025-04-22 09:17:37 -07:00
|
|
|
}
|
|
|
|
|
|
2025-04-03 04:10:05 -07:00
|
|
|
for (size_t attr_idx = 0; attr_idx < config->numAttrs; ++attr_idx) {
|
|
|
|
|
hipLaunchAttribute& attr = config->attrs[attr_idx];
|
|
|
|
|
switch (attr.id) {
|
|
|
|
|
case hipLaunchAttributeCooperative:
|
2025-05-06 15:06:13 -04:00
|
|
|
{
|
2025-04-03 04:10:05 -07:00
|
|
|
if (attr.value.cooperative != 0) {
|
2025-05-06 15:06:13 -04:00
|
|
|
HIP_RETURN(ihipModuleLaunchKernel(f, launch_params, config->hStream, kernelParams,
|
|
|
|
|
nullptr, nullptr, nullptr, 0,
|
|
|
|
|
amd::NDRangeKernelCommand::CooperativeGroups));
|
2025-04-03 04:10:05 -07:00
|
|
|
}
|
|
|
|
|
break;
|
2025-05-06 15:06:13 -04:00
|
|
|
}
|
2025-04-03 04:10:05 -07:00
|
|
|
default:
|
|
|
|
|
LogPrintfError("Attribute %u not supported", attr.id);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipErrorInvalidConfiguration)
|
|
|
|
|
}
|
2023-04-21 10:46:05 +00:00
|
|
|
} // namespace hip
|