Skip to content

Commit 2b79f8f

Browse files
committed
[AMDGPU] Remove uses of deprecreated HSA executable functions
Summary: These functions were deprecated in ROCR 1.3 which was released quite some time ago. The main functionality that was lost was modifying and inspecting the code object indepedently of the executable, however we do all of that custom through our ELF API. This should be within the versions of other functions we use.
1 parent 905e831 commit 2b79f8f

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ int load(int argc, const char **argv, const char **envp, void *image,
371371
handle_error(err);
372372

373373
// Load the code object's ISA information and executable data segments.
374-
hsa_code_object_t object;
375-
if (hsa_status_t err = hsa_code_object_deserialize(image, size, "", &object))
374+
hsa_code_object_reader_t reader;
375+
if (hsa_status_t err =
376+
hsa_code_object_reader_create_from_memory(image, size, &reader))
376377
handle_error(err);
377378

378379
hsa_executable_t executable;
@@ -381,8 +382,9 @@ int load(int argc, const char **argv, const char **envp, void *image,
381382
&executable))
382383
handle_error(err);
383384

384-
if (hsa_status_t err =
385-
hsa_executable_load_code_object(executable, dev_agent, object, ""))
385+
hsa_loaded_code_object_t object;
386+
if (hsa_status_t err = hsa_executable_load_agent_code_object(
387+
executable, dev_agent, reader, "", &object))
386388
handle_error(err);
387389

388390
// No modifications to the executable are allowed after this point.
@@ -397,6 +399,9 @@ int load(int argc, const char **argv, const char **envp, void *image,
397399
if (result)
398400
handle_error(HSA_STATUS_ERROR);
399401

402+
if (hsa_status_t err = hsa_code_object_reader_destroy(reader))
403+
handle_error(err);
404+
400405
// Obtain memory pools to exchange data between the host and the device. The
401406
// fine-grained pool acts as pinned memory on the host for DMA transfers to
402407
// the device, the coarse-grained pool is for allocations directly on the
@@ -617,9 +622,6 @@ int load(int argc, const char **argv, const char **envp, void *image,
617622
if (hsa_status_t err = hsa_executable_destroy(executable))
618623
handle_error(err);
619624

620-
if (hsa_status_t err = hsa_code_object_destroy(object))
621-
handle_error(err);
622-
623625
if (hsa_status_t err = hsa_shut_down())
624626
handle_error(err);
625627

offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ DLWRAP(hsa_amd_register_system_event_handler, 2)
6868
DLWRAP(hsa_amd_signal_create, 5)
6969
DLWRAP(hsa_amd_signal_async_handler, 5)
7070
DLWRAP(hsa_amd_pointer_info, 5)
71+
DLWRAP(hsa_code_object_reader_create_from_memory, 3)
72+
DLWRAP(hsa_code_object_reader_destroy, 1)
73+
DLWRAP(hsa_executable_load_agent_code_object, 5)
7174

7275
DLWRAP_FINALIZE()
7376

offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ typedef struct hsa_agent_s {
5050
uint64_t handle;
5151
} hsa_agent_t;
5252

53+
typedef struct hsa_loaded_code_object_s {
54+
uint64_t handle;
55+
} hsa_loaded_code_object_t;
56+
57+
typedef struct hsa_code_object_reader_s {
58+
uint64_t handle;
59+
} hsa_code_object_reader_t;
60+
5361
typedef enum {
5462
HSA_DEVICE_TYPE_CPU = 0,
5563
HSA_DEVICE_TYPE_GPU = 1,
@@ -364,6 +372,18 @@ hsa_status_t hsa_amd_signal_async_handler(hsa_signal_t signal,
364372
hsa_amd_signal_handler handler,
365373
void *arg);
366374

375+
hsa_status_t hsa_code_object_reader_create_from_memory(
376+
const void *code_object, size_t size,
377+
hsa_code_object_reader_t *code_object_reader);
378+
379+
hsa_status_t
380+
hsa_code_object_reader_destroy(hsa_code_object_reader_t code_object_reader);
381+
382+
hsa_status_t hsa_executable_load_agent_code_object(
383+
hsa_executable_t executable, hsa_agent_t agent,
384+
hsa_code_object_reader_t code_object_reader, const char *options,
385+
hsa_loaded_code_object_t *loaded_code_object);
386+
367387
#ifdef __cplusplus
368388
}
369389
#endif

offload/plugins-nextgen/amdgpu/src/rtl.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,7 @@ struct AMDGPUDeviceImageTy : public DeviceImageTy {
468468
/// Unload the executable.
469469
Error unloadExecutable() {
470470
hsa_status_t Status = hsa_executable_destroy(Executable);
471-
if (auto Err = Plugin::check(Status, "Error in hsa_executable_destroy: %s"))
472-
return Err;
473-
474-
Status = hsa_code_object_destroy(CodeObject);
475-
return Plugin::check(Status, "Error in hsa_code_object_destroy: %s");
471+
return Plugin::check(Status, "Error in hsa_executable_destroy: %s");
476472
}
477473

478474
/// Get the executable.
@@ -499,7 +495,6 @@ struct AMDGPUDeviceImageTy : public DeviceImageTy {
499495
private:
500496
/// The exectuable loaded on the agent.
501497
hsa_executable_t Executable;
502-
hsa_code_object_t CodeObject;
503498
StringMap<offloading::amdgpu::AMDGPUKernelMetaData> KernelInfoMap;
504499
uint16_t ELFABIVersion;
505500
};
@@ -2954,10 +2949,11 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
29542949
};
29552950

29562951
Error AMDGPUDeviceImageTy::loadExecutable(const AMDGPUDeviceTy &Device) {
2957-
hsa_status_t Status;
2958-
Status = hsa_code_object_deserialize(getStart(), getSize(), "", &CodeObject);
2959-
if (auto Err =
2960-
Plugin::check(Status, "Error in hsa_code_object_deserialize: %s"))
2952+
hsa_code_object_reader_t Reader;
2953+
hsa_status_t Status =
2954+
hsa_code_object_reader_create_from_memory(getStart(), getSize(), &Reader);
2955+
if (auto Err = Plugin::check(
2956+
Status, "Error in hsa_code_object_reader_create_from_memory: %s"))
29612957
return Err;
29622958

29632959
Status = hsa_executable_create_alt(
@@ -2966,10 +2962,11 @@ Error AMDGPUDeviceImageTy::loadExecutable(const AMDGPUDeviceTy &Device) {
29662962
Plugin::check(Status, "Error in hsa_executable_create_alt: %s"))
29672963
return Err;
29682964

2969-
Status = hsa_executable_load_code_object(Executable, Device.getAgent(),
2970-
CodeObject, "");
2971-
if (auto Err =
2972-
Plugin::check(Status, "Error in hsa_executable_load_code_object: %s"))
2965+
hsa_loaded_code_object_t Object;
2966+
Status = hsa_executable_load_agent_code_object(Executable, Device.getAgent(),
2967+
Reader, "", &Object);
2968+
if (auto Err = Plugin::check(
2969+
Status, "Error in hsa_executable_load_agent_code_object: %s"))
29732970
return Err;
29742971

29752972
Status = hsa_executable_freeze(Executable, "");
@@ -2984,6 +2981,11 @@ Error AMDGPUDeviceImageTy::loadExecutable(const AMDGPUDeviceTy &Device) {
29842981
if (Result)
29852982
return Plugin::error("Loaded HSA executable does not validate");
29862983

2984+
Status = hsa_code_object_reader_destroy(Reader);
2985+
if (auto Err =
2986+
Plugin::check(Status, "Error in hsa_code_object_reader_destroy: %s"))
2987+
return Err;
2988+
29872989
if (auto Err = hsa_utils::readAMDGPUMetaDataFromImage(
29882990
getMemoryBuffer(), KernelInfoMap, ELFABIVersion))
29892991
return Err;

0 commit comments

Comments
 (0)