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
这个提交包含在:
foreman
2018-03-23 00:19:22 -04:00
父节点 fe3f2b7e5d
当前提交 c531507708
修改 4 个文件,包含 49 行新增15 行删除
+4
查看文件
@@ -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;
}
+9 -8
查看文件
@@ -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 ) {
+1 -1
查看文件
@@ -39,6 +39,6 @@ THE SOFTWARE.
extern thread_local amd::Context* g_context;
extern std::vector<amd::Context*> g_devices;
hipError_t hipDeviceGetCount(int* count);
hipError_t ihipDeviceGetCount(int* count);
#endif // HIP_SRC_HIP_INTERNAL_H
+35 -6
查看文件
@@ -22,10 +22,13 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <libelf.h>
#include <fstream>
#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<char> tmp{std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
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<cl_program>(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<address>(extra[1]) + desc.offset_);
if (kernelParams == nullptr) {
assert(extra);
kernel->parameters().set(i, desc.size_, reinterpret_cast<address>(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);