From f898f91b38361b45ec2b4fbcc28d7c5543d23447 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 28 Nov 2017 11:41:42 -0500
Subject: [PATCH] P4 to Git Change 1487653 by wchau@wchau_OCL_boltzmann on
2017/11/28 11:28:09
SWDEV-119491 - Add support for cl_amd_assembly_program extension
This is a sub-task of SWDEV-134396. Part 1/4 of the required changes:
(1) OpenCL API / Runtime, (2) ROCm Runtime - compiler invocation, (3) ROCm Driver, (4) Enabling Extension
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_common.hpp#19 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#57 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#45 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl1.2/CL/cl_ext.h#19 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h#35 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl2.1/CL/cl_ext.h#12 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl2.2/CL/cl_ext.h#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#215 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#293 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#90 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#42 edit
[ROCm/clr commit: 1f86279494f327f2c6de3732a67f9a91c7f1b884]
---
projects/clr/rocclr/runtime/device/device.cpp | 2 +-
projects/clr/rocclr/runtime/device/device.hpp | 2 ++
projects/clr/rocclr/runtime/platform/program.cpp | 15 ++++++++++-----
projects/clr/rocclr/runtime/platform/program.hpp | 15 +++++++++++----
4 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/device.cpp b/projects/clr/rocclr/runtime/device/device.cpp
index ec060bcb63..a9b3a65f4a 100644
--- a/projects/clr/rocclr/runtime/device/device.cpp
+++ b/projects/clr/rocclr/runtime/device/device.cpp
@@ -116,7 +116,7 @@ bool Device::BlitProgram::create(amd::Device* device, const char* extraKernels,
}
// Create a program with all blit kernels
- program_ = new Program(*context_, kernels.c_str());
+ program_ = new Program(*context_, kernels.c_str(), Program::OpenCL_C);
if (program_ == NULL) {
return false;
}
diff --git a/projects/clr/rocclr/runtime/device/device.hpp b/projects/clr/rocclr/runtime/device/device.hpp
index 7451547bdc..8d58fc5a32 100644
--- a/projects/clr/rocclr/runtime/device/device.hpp
+++ b/projects/clr/rocclr/runtime/device/device.hpp
@@ -119,6 +119,7 @@ enum OclExtensions {
ClKhrIlProgram,
ClAMDLiquidFlash,
ClAmdCopyBufferP2P,
+ ClAmdAssemblyProgram,
ClExtTotal
};
@@ -161,6 +162,7 @@ static const char* OclExtensionsString[] = {"cl_khr_fp64 ",
"",
"cl_amd_liquid_flash ",
"cl_amd_copy_buffer_p2p ",
+ "cl_amd_assembly_program ",
NULL};
static constexpr int AmdVendor = 0x1002;
diff --git a/projects/clr/rocclr/runtime/platform/program.cpp b/projects/clr/rocclr/runtime/platform/program.cpp
index e5e987fff5..087ffb5fb4 100644
--- a/projects/clr/rocclr/runtime/platform/program.cpp
+++ b/projects/clr/rocclr/runtime/platform/program.cpp
@@ -52,7 +52,7 @@ cl_int Program::addDeviceProgram(Device& device, const void* image, size_t lengt
if (image != NULL && !amd::isElfMagic((const char*)image)
#if !defined(WITH_LIGHTNING_COMPILER)
&& !aclValidateBinaryImage(
- image, length, isSPIRV_ ? BINARY_TYPE_SPIRV : BINARY_TYPE_ELF | BINARY_TYPE_LLVM)
+ image, length, language_ == SPIRV ? BINARY_TYPE_SPIRV : BINARY_TYPE_ELF | BINARY_TYPE_LLVM)
#endif // !defined(WITH_LIGHTNING_COMPILER)
) {
return CL_INVALID_BINARY;
@@ -104,7 +104,7 @@ cl_int Program::addDeviceProgram(Device& device, const void* image, size_t lengt
aclBinaryFini(binary);
}
#endif // defined(WITH_COMPILER_LIB)
- options->oVariables->BinaryIsSpirv = isSPIRV_;
+ options->oVariables->BinaryIsSpirv = language_ == SPIRV;
device::Program* program = rootDev.createProgram(options);
if (program == NULL) {
return CL_OUT_OF_HOST_MEMORY;
@@ -210,7 +210,7 @@ cl_int Program::compile(const std::vector& devices, size_t numHeaders,
devProgram = getDeviceProgram(**it);
}
- if (devProgram->type() == device::Program::TYPE_INTERMEDIATE || isSPIRV_) {
+ if (devProgram->type() == device::Program::TYPE_INTERMEDIATE || language_ == SPIRV) {
continue;
}
// We only build a Device-Program once
@@ -284,8 +284,8 @@ cl_int Program::link(const std::vector& devices, size_t numInputs,
bool found = false;
for (size_t i = 0; i < numInputs; ++i) {
Program& inputProgram = *inputPrograms[i];
- if (inputProgram.isSPIRV_) {
- parsedOptions.oVariables->BinaryIsSpirv = inputProgram.isSPIRV_;
+ if (inputProgram.language_ == SPIRV) {
+ parsedOptions.oVariables->BinaryIsSpirv = true;
}
deviceprograms_t inputDevProgs = inputProgram.devicePrograms();
deviceprograms_t::const_iterator findIt = inputDevProgs.find(*it);
@@ -492,6 +492,11 @@ cl_int Program::build(const std::vector& devices, const char* options,
parsedOptions.oVariables->AssumeAlias = true;
+ if (language_ == Assembly) {
+ constexpr char asmLang[] = "asm";
+ parsedOptions.oVariables->XLang = asmLang;
+ }
+
// We only build a Device-Program once
if (devProgram->buildStatus() != CL_BUILD_NONE) {
continue;
diff --git a/projects/clr/rocclr/runtime/platform/program.hpp b/projects/clr/rocclr/runtime/platform/program.hpp
index 01008731b0..b22f82d322 100644
--- a/projects/clr/rocclr/runtime/platform/program.hpp
+++ b/projects/clr/rocclr/runtime/platform/program.hpp
@@ -72,6 +72,12 @@ class Program : public RuntimeObject {
typedef std::map deviceprograms_t;
typedef std::map symbols_t;
+ enum Language {
+ Binary = 0,
+ OpenCL_C,
+ SPIRV,
+ Assembly
+ };
private:
//! Replaces the compiled program with the new version from HD
void StubProgramSource(const std::string& app_name);
@@ -80,7 +86,7 @@ class Program : public RuntimeObject {
SharedReference context_;
std::string sourceCode_; //!< Strings that make up the source code
- bool isSPIRV_; //!< The binary image is SPIRV
+ Language language_; //!< Input source language
devicebinary_t binary_; //!< The binary image, provided by the app
symbols_t* symbolTable_; //!< The program's kernels symbol table
std::string kernelNames_; //!< The program kernel names
@@ -103,15 +109,16 @@ class Program : public RuntimeObject {
public:
//! Construct a new program to be compiled from the given source code.
- Program(Context& context, const std::string& sourceCode, bool isSPIRV = false)
+ Program(Context& context, const std::string& sourceCode, Language language)
: context_(context),
sourceCode_(sourceCode),
- isSPIRV_(isSPIRV),
+ language_(language),
symbolTable_(NULL),
programLog_() {}
//! Construct a new program associated with a context.
- Program(Context& context) : context_(context), isSPIRV_(false), symbolTable_(NULL) {}
+ Program(Context& context, Language language = Binary)
+ : context_(context), language_(language), symbolTable_(NULL) {}
//! Returns context, associated with the current program.
const Context& context() const { return context_(); }