From c531507708259cdaf93acd3defe06bc319c8a925 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 23 Mar 2018 00:19:22 -0400
Subject: [PATCH] P4 to Git Change 1531138 by cpaquot@cpaquot-ocl-lc-lnx on
2018/03/23 00:10:40
SWDEV-145570 - [HIP] Module
Check for correct device id in hipDeviceGetAttribute
Implement hipModuleLoad
Handle kernelParams in hipModuleLaunchKernel
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#3 edit
---
hipamd/api/hip/hip_device.cpp | 4 +++
hipamd/api/hip/hip_device_runtime.cpp | 17 +++++------
hipamd/api/hip/hip_internal.hpp | 2 +-
hipamd/api/hip/hip_module.cpp | 41 +++++++++++++++++++++++----
4 files changed, 49 insertions(+), 15 deletions(-)
diff --git a/hipamd/api/hip/hip_device.cpp b/hipamd/api/hip/hip_device.cpp
index 66bae6174e..efb77fb7b0 100644
--- a/hipamd/api/hip/hip_device.cpp
+++ b/hipamd/api/hip/hip_device.cpp
@@ -89,6 +89,10 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
hipError_t hipDeviceGetCount(int* count) {
HIP_INIT_API(count);
+ return ihipDeviceGetCount(count);
+}
+
+hipError_t ihipDeviceGetCount(int* count) {
if (count == nullptr) {
return hipErrorInvalidValue;
}
diff --git a/hipamd/api/hip/hip_device_runtime.cpp b/hipamd/api/hip/hip_device_runtime.cpp
index bbd0838f76..4d8ac9cec0 100644
--- a/hipamd/api/hip/hip_device_runtime.cpp
+++ b/hipamd/api/hip/hip_device_runtime.cpp
@@ -35,7 +35,7 @@ hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
*device = 0;
cl_uint maxMatchedCount = 0;
int count = 0;
- hipDeviceGetCount(&count);
+ ihipDeviceGetCount(&count);
for (cl_int i = 0; i< count; ++i) {
hipDeviceProp_t currentProp = {0};
@@ -146,10 +146,11 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
return hipErrorInvalidValue;
}
- //if (unsigned(device) >= g_context->devices().size()) {
- // return hipErrorInvalidDevice;
- //}
- //auto* deviceHandle = g_context->devices()[device];
+ int count = 0;
+ ihipDeviceGetCount(&count);
+ if (device < 0 || device >= count) {
+ return hipErrorInvalidDevice;
+ }
//FIXME: should we cache the props, or just select from deviceHandle->info_?
hipDeviceProp_t prop = {0};
@@ -253,7 +254,7 @@ hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) {
if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
int count = 0;
- hipDeviceGetCount(&count);
+ ihipDeviceGetCount(&count);
for (cl_int i = 0; i < count; i++) {
int pi = 0;
hipDevice_t dev;
@@ -312,7 +313,7 @@ hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) {
HIP_INIT_API((void*)pciBusId, len, device);
int count;
- hipDeviceGetCount(&count);
+ ihipDeviceGetCount(&count);
if (device < 0 || device > count) {
return hipErrorInvalidDevice;
}
@@ -393,7 +394,7 @@ hipError_t hipGetDevice ( int* deviceId ) {
hipError_t hipGetDeviceCount ( int* count ) {
HIP_INIT_API(count);
- return hipDeviceGetCount(count);
+ return ihipDeviceGetCount(count);
}
hipError_t hipGetDeviceFlags ( unsigned int* flags ) {
diff --git a/hipamd/api/hip/hip_internal.hpp b/hipamd/api/hip/hip_internal.hpp
index ba9446f2c1..239538e613 100644
--- a/hipamd/api/hip/hip_internal.hpp
+++ b/hipamd/api/hip/hip_internal.hpp
@@ -39,6 +39,6 @@ THE SOFTWARE.
extern thread_local amd::Context* g_context;
extern std::vector g_devices;
-hipError_t hipDeviceGetCount(int* count);
+hipError_t ihipDeviceGetCount(int* count);
#endif // HIP_SRC_HIP_INTERNAL_H
diff --git a/hipamd/api/hip/hip_module.cpp b/hipamd/api/hip/hip_module.cpp
index fd7729c6e5..6fd0cc9ac9 100644
--- a/hipamd/api/hip/hip_module.cpp
+++ b/hipamd/api/hip/hip_module.cpp
@@ -22,10 +22,13 @@ THE SOFTWARE.
#include
#include
+#include
#include "hip_internal.hpp"
#include "platform/program.hpp"
+hipError_t ihipModuleLoadData(hipModule_t *module, const void *image);
+
static uint64_t ElfSize(const void *emi)
{
const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)emi;
@@ -51,9 +54,19 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname)
{
HIP_INIT_API(module, fname);
- assert(0 && "Unimplemented");
+ if (!fname) {
+ return hipErrorInvalidValue;
+ }
- return hipErrorUnknown;
+ std::ifstream file{fname};
+
+ if (!file.is_open()) {
+ return hipErrorFileNotFound;
+ }
+
+ std::vector tmp{std::istreambuf_iterator{file}, std::istreambuf_iterator{}};
+
+ return ihipModuleLoadData(module, tmp.data());
}
@@ -61,15 +74,26 @@ hipError_t hipModuleUnload(hipModule_t hmod)
{
HIP_INIT_API(hmod);
- assert(0 && "Unimplemented");
+ if (hmod == nullptr) {
+ return hipErrorUnknown;
+ }
- return hipErrorUnknown;
+ amd::Program* program = as_amd(reinterpret_cast(hmod));
+
+ program->release();
+
+ return hipSuccess;
}
hipError_t hipModuleLoadData(hipModule_t *module, const void *image)
{
HIP_INIT_API(module, image);
+ return ihipModuleLoadData(module, image);
+}
+
+hipError_t ihipModuleLoadData(hipModule_t *module, const void *image)
+{
amd::Program* program = new amd::Program(*g_context);
if (program == NULL) {
return hipErrorOutOfMemory;
@@ -133,11 +157,16 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
amd::NDRangeContainer ndrange(3, globalWorkOffset, globalWorkSize, localWorkSize);
amd::Command::EventWaitList waitList;
- assert(!kernelParams && extra && "check this code");
const amd::KernelSignature& signature = kernel->signature();
for (size_t i = 0; i < signature.numParameters(); ++i) {
const amd::KernelParameterDescriptor& desc = signature.at(i);
- kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_);
+ if (kernelParams == nullptr) {
+ assert(extra);
+ kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_);
+ } else {
+ assert(!extra);
+ kernel->parameters().set(i, desc.size_, kernelParams[i]);
+ }
}
amd::NDRangeKernelCommand* command = new amd::NDRangeKernelCommand(*queue, waitList, *kernel, ndrange);