Support hipFuncGetAttributes with hip-clang+Hcc RT
Fix issues of missing kernel function symbols and missing argument list via using __hipRegister* functions. Then the following tests can pass, directed_tests/runtimeApi/module/hipFuncGetAttributes directed_tests/runtimeApi/module/hipExtLaunchMultiKernelMultiDevice directed_tests/gcc/LaunchKernel Change-Id: I52135b61e8283eb4f9f10f77895151e4e55418d9
This commit is contained in:
@@ -28,6 +28,7 @@ THE SOFTWARE.
|
||||
#include "hip_hcc_internal.h"
|
||||
#include "hip_fatbin.h"
|
||||
#include "trace_helper.h"
|
||||
#include "program_state.inl"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC visibility push (default)
|
||||
@@ -94,8 +95,10 @@ __hipRegisterFatBinary(const void* data)
|
||||
agent);
|
||||
|
||||
if (module->executable.handle) {
|
||||
modules->at(deviceId) = module;
|
||||
tprintf(DB_FB, "Loaded code object for %s\n", name);
|
||||
hip_impl::program_state_impl::read_kernarg_metadata(image, module->kernargs);
|
||||
modules->at(deviceId) = module;
|
||||
|
||||
tprintf(DB_FB, "Loaded code object for %s, args size=%ld\n", name, module->kernargs.size());
|
||||
} else {
|
||||
fprintf(stderr, "Failed to load code object for %s\n", name);
|
||||
abort();
|
||||
@@ -232,7 +235,7 @@ static DeviceVar* findVar(std::string hostVar, int deviceId, hipModule_t hmod) {
|
||||
}
|
||||
|
||||
hipError_t ihipGetGlobalVar(hipDeviceptr_t* dev_ptr, size_t* size_ptr,
|
||||
const char* hostVar, hipModule_t hmod) {
|
||||
const char* hostVar, hipModule_t hmod) {
|
||||
GET_TLS();
|
||||
auto ctx = ihipGetTlsDefaultCtx();
|
||||
|
||||
@@ -425,6 +428,41 @@ extern "C" hipError_t __hipPopCallConfiguration(
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
int getCurrentDeviceId()
|
||||
{
|
||||
GET_TLS();
|
||||
|
||||
int deviceId = 0;
|
||||
auto ctx = ihipGetTlsDefaultCtx();
|
||||
|
||||
if(!ctx) return deviceId;
|
||||
|
||||
LockedAccessor_CtxCrit_t crit(ctx->criticalData());
|
||||
|
||||
if(crit->_execStack.size() != 0)
|
||||
{
|
||||
auto &exec = crit->_execStack.top();
|
||||
|
||||
if (exec._hStream) {
|
||||
deviceId = exec._hStream->getDevice()->_deviceId;
|
||||
} else if (ctx->getDevice()) {
|
||||
deviceId = ctx->getDevice()->_deviceId;
|
||||
}
|
||||
} else if (ctx->getDevice()) {
|
||||
deviceId = ctx->getDevice()->_deviceId;
|
||||
}
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
hipFunction_t ihipGetDeviceFunction(const void *hostFunction)
|
||||
{
|
||||
int deviceId = getCurrentDeviceId();
|
||||
auto it = g_functions.find(hostFunction);
|
||||
if (it == g_functions.end() || !it->second[deviceId]) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second[deviceId];
|
||||
}
|
||||
|
||||
hipError_t hipSetupArgument(
|
||||
const void *arg,
|
||||
|
||||
@@ -33,7 +33,7 @@ THE SOFTWARE.
|
||||
#include "hip_prof_api.h"
|
||||
#include "hip_util.h"
|
||||
#include "env.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#if (__hcc_workweek__ < 16354)
|
||||
#error("This version of HIP requires a newer version of HCC.");
|
||||
@@ -1079,4 +1079,14 @@ static inline ihipCtx_t* iihipGetTlsDefaultCtx(TlsData* tls) {
|
||||
return tls->defaultCtx;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get device function from host kernel function pointer
|
||||
* Needed only for clang + HIP-HCC RT
|
||||
*
|
||||
* @param [in] hostFunction host kernel function pointer
|
||||
*
|
||||
* @returns hipFuntion_t, nullptr
|
||||
*/
|
||||
hipFunction_t ihipGetDeviceFunction(const void *hostFunction);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -344,6 +344,8 @@ hipError_t ihipExtLaunchMultiKernelMultiDevice(hipLaunchParams* launchParamsList
|
||||
free(kds);
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
if (!kds[i]->_kernarg_layout.empty()) continue;
|
||||
|
||||
hip_impl::kernargs_size_align kargs = ps.get_kernargs_size_align(
|
||||
reinterpret_cast<std::uintptr_t>(lp.func));
|
||||
kds[i]->_kernarg_layout = *reinterpret_cast<const std::vector<std::pair<std::size_t, std::size_t>>*>(
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <hsa/hsa_ven_amd_loader.h>
|
||||
#include <amd_comgr.h>
|
||||
#include "hc.hpp"
|
||||
#include "hip_hcc_internal.h"
|
||||
#include "trace_helper.h"
|
||||
|
||||
#include <link.h>
|
||||
|
||||
@@ -944,14 +946,16 @@ public:
|
||||
|
||||
auto it0 = get_functions(agent).find(function_address);
|
||||
|
||||
if (it0 == get_functions(agent).cend()) {
|
||||
hip_throw(std::runtime_error{
|
||||
if (it0 != get_functions(agent).cend()) return it0->second;
|
||||
|
||||
// For hip-clang compiler + Hcc RT
|
||||
hipFunction_t f = ihipGetDeviceFunction((const void*)function_address);
|
||||
if (f) return reinterpret_cast<Kernel_descriptor&>(*f);
|
||||
|
||||
hip_throw(std::runtime_error{
|
||||
"No device code available for function: " +
|
||||
std::string(name(function_address)) +
|
||||
", for agent: " + name(agent)});
|
||||
}
|
||||
|
||||
return it0->second;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<std::size_t, std::size_t>>&
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
|
||||
/* HIT_START
|
||||
* BUILD_CMD: gpu.o %hc -I%hip-path/include -g -c %S/gpu.cpp -o %T/gpu.o EXCLUDE_HIP_PLATFORM nvcc vdi EXCLUDE_HIP_COMPILER clang
|
||||
* BUILD_CMD: launchkernel.o %hc -D__HIP_PLATFORM_HCC__ -g -I%hip-path/include -c %S/LaunchKernel.c -o %T/launchkernel.o EXCLUDE_HIP_PLATFORM nvcc vdi EXCLUDE_HIP_COMPILER clang
|
||||
* BUILD_CMD: LaunchKernel %hc %T/launchkernel.o %T/gpu.o -g -Wl,--rpath=%hip-path/lib %hip-path/lib/libhip_hcc.so -o %T/%t DEPENDS gpu.o launchkernel.o EXCLUDE_HIP_PLATFORM nvcc vdi EXCLUDE_HIP_COMPILER clang
|
||||
* TEST: %t EXCLUDE_HIP_PLATFORM nvcc vdi EXCLUDE_HIP_COMPILER clang
|
||||
* BUILD_CMD: gpu.o %hc -I%hip-path/include -g -c %S/gpu.cpp -o %T/gpu.o EXCLUDE_HIP_PLATFORM nvcc vdi
|
||||
* BUILD_CMD: launchkernel.o %hc -D__HIP_PLATFORM_HCC__ -g -I%hip-path/include -c %S/LaunchKernel.c -o %T/launchkernel.o EXCLUDE_HIP_PLATFORM nvcc vdi
|
||||
* BUILD_CMD: LaunchKernel %hc %T/launchkernel.o %T/gpu.o -g -Wl,--rpath=%hip-path/lib %hip-path/lib/libhip_hcc.so -o %T/%t DEPENDS gpu.o launchkernel.o EXCLUDE_HIP_PLATFORM nvcc vdi
|
||||
* TEST: %t EXCLUDE_HIP_PLATFORM nvcc vdi
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user