From ea28466b7b9c64feeba7697581f7383e2b571d3a 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
---
opencl/api/opencl/amdocl/cl_common.hpp | 8 +++
opencl/api/opencl/amdocl/cl_context.cpp | 3 +
opencl/api/opencl/amdocl/cl_program.cpp | 56 ++++++++++++++++++-
.../khronos/headers/opencl1.2/CL/cl_ext.h | 13 +++++
.../khronos/headers/opencl2.0/CL/cl_ext.h | 12 ++++
.../khronos/headers/opencl2.1/CL/cl_ext.h | 12 ++++
.../khronos/headers/opencl2.2/CL/cl_ext.h | 12 ++++
7 files changed, 114 insertions(+), 2 deletions(-)
diff --git a/opencl/api/opencl/amdocl/cl_common.hpp b/opencl/api/opencl/amdocl/cl_common.hpp
index b49ec76a42..603ff085e2 100644
--- a/opencl/api/opencl/amdocl/cl_common.hpp
+++ b/opencl/api/opencl/amdocl/cl_common.hpp
@@ -291,6 +291,14 @@ clCreateBufferFromImageAMD(
cl_mem image,
cl_int * errcode_ret);
+extern CL_API_ENTRY cl_program CL_API_CALL
+clCreateProgramWithAssemblyAMD(
+ cl_context context,
+ cl_uint count,
+ const char ** strings,
+ const size_t * lengths,
+ cl_int * errcode_ret);
+
} // extern "C"
//! \endcond
diff --git a/opencl/api/opencl/amdocl/cl_context.cpp b/opencl/api/opencl/amdocl/cl_context.cpp
index b74e32b094..8a1cfa96d8 100644
--- a/opencl/api/opencl/amdocl/cl_context.cpp
+++ b/opencl/api/opencl/amdocl/cl_context.cpp
@@ -479,6 +479,9 @@ CL_API_ENTRY void* CL_API_CALL clGetExtensionFunctionAddress(const char* func_na
#if defined(cl_khr_il_program) || defined(CL_VERSION_2_1)
CL_EXTENSION_ENTRYPOINT_CHECK2(clCreateProgramWithILKHR,clCreateProgramWithIL);
#endif // defined(cl_khr_il_program) || defined(CL_VERSION_2_1)
+#if cl_amd_assembly_program
+ CL_EXTENSION_ENTRYPOINT_CHECK(clCreateProgramWithAssemblyAMD);
+#endif // cl_amd_assembly_program
#if cl_amd_liquid_flash
CL_EXTENSION_ENTRYPOINT_CHECK(clCreateSsgFileObjectAMD);
#endif // cl_amd_liquid_flash
diff --git a/opencl/api/opencl/amdocl/cl_program.cpp b/opencl/api/opencl/amdocl/cl_program.cpp
index 84fadb96b0..d1f4ac0eb8 100644
--- a/opencl/api/opencl/amdocl/cl_program.cpp
+++ b/opencl/api/opencl/amdocl/cl_program.cpp
@@ -134,7 +134,7 @@ RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithSource,
}
// Create the program
- amd::Program* program = new amd::Program(*as_amd(context), sourceCode);
+ amd::Program* program = new amd::Program(*as_amd(context), sourceCode, amd::Program::OpenCL_C);
if (program == NULL) {
*not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY;
return (cl_program)0;
@@ -196,7 +196,7 @@ RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithIL,
}
// Create the program
- amd::Program* program = new amd::Program(*as_amd(context), "", true);
+ amd::Program* program = new amd::Program(*as_amd(context), amd::Program::SPIRV);
if (program == NULL) {
*not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY;
return (cl_program)0;
@@ -330,6 +330,58 @@ RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithBinary,
}
RUNTIME_EXIT
+RUNTIME_ENTRY_RET(cl_program, clCreateProgramWithAssemblyAMD,
+ (cl_context context, cl_uint count, const char** strings, const size_t* lengths,
+ cl_int* errcode_ret)) {
+ if (!is_valid(context)) {
+ *not_null(errcode_ret) = CL_INVALID_CONTEXT;
+ return (cl_program)0;
+ }
+ if (count == 0 || strings == NULL) {
+ *not_null(errcode_ret) = CL_INVALID_VALUE;
+ return (cl_program)0;
+ }
+
+ std::string assembly;
+ for (cl_uint i = 0; i < count; ++i) {
+ if (strings[i] == NULL) {
+ *not_null(errcode_ret) = CL_INVALID_VALUE;
+ return (cl_program)0;
+ }
+ if (lengths && lengths[i] != 0) {
+ assembly.append(strings[i], lengths[i]);
+ } else {
+ assembly.append(strings[i]);
+ }
+ }
+ if (assembly.empty()) {
+ *not_null(errcode_ret) = CL_INVALID_VALUE;
+ return (cl_program)0;
+ }
+
+ // Create the program
+ amd::Program* program = new amd::Program(*as_amd(context), assembly, amd::Program::Assembly);
+ if (program == NULL) {
+ *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY;
+ return (cl_program)0;
+ }
+
+ // Add programs for all devices in the context.
+ const std::vector& devices = as_amd(context)->devices();
+ std::vector::const_iterator it;
+ for (it = devices.begin(); it != devices.end(); ++it) {
+ if (program->addDeviceProgram(**it) == CL_OUT_OF_HOST_MEMORY) {
+ *not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY;
+ program->release();
+ return (cl_program)0;
+ }
+ }
+
+ *not_null(errcode_ret) = CL_SUCCESS;
+ return as_cl(program);
+}
+RUNTIME_EXIT
+
/*! \brief Increment the program reference count.
*
* clCreateProgram does an implicit retain.
diff --git a/opencl/api/opencl/khronos/headers/opencl1.2/CL/cl_ext.h b/opencl/api/opencl/khronos/headers/opencl1.2/CL/cl_ext.h
index 063a05dc04..45c09ae138 100644
--- a/opencl/api/opencl/khronos/headers/opencl1.2/CL/cl_ext.h
+++ b/opencl/api/opencl/khronos/headers/opencl1.2/CL/cl_ext.h
@@ -352,6 +352,19 @@ typedef CL_API_ENTRY cl_int
const cl_event* /*event_wait_list*/,
cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
+/***********************************
+* cl_amd_assembly_program extension *
+***********************************/
+#define cl_amd_assembly_program 1
+
+typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) (
+ cl_context /* context */,
+ cl_uint /* count */,
+ const char** /* strings */,
+ const size_t* /* lengths */,
+ cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2;
+
+
//
/***************************
* cl_amd_command_intercept *
diff --git a/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h b/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h
index b5cda826a9..c41b4e1053 100644
--- a/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h
+++ b/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h
@@ -371,6 +371,18 @@ typedef CL_API_ENTRY cl_int
const cl_event* /*event_wait_list*/,
cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
+/***********************************
+* cl_amd_assembly_program extension *
+***********************************/
+#define cl_amd_assembly_program 1
+
+typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) (
+ cl_context /* context */,
+ cl_uint /* count */,
+ const char** /* strings */,
+ const size_t* /* lengths */,
+ cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2;
+
//
/***************************
* cl_amd_command_intercept *
diff --git a/opencl/api/opencl/khronos/headers/opencl2.1/CL/cl_ext.h b/opencl/api/opencl/khronos/headers/opencl2.1/CL/cl_ext.h
index 06ff98af6d..317fe150a9 100644
--- a/opencl/api/opencl/khronos/headers/opencl2.1/CL/cl_ext.h
+++ b/opencl/api/opencl/khronos/headers/opencl2.1/CL/cl_ext.h
@@ -352,6 +352,18 @@ typedef CL_API_ENTRY cl_int
const cl_event* /*event_wait_list*/,
cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
+/***********************************
+* cl_amd_assembly_program extension *
+***********************************/
+#define cl_amd_assembly_program 1
+
+typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) (
+ cl_context /* context */,
+ cl_uint /* count */,
+ const char** /* strings */,
+ const size_t* /* lengths */,
+ cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2;
+
//
/***************************
* cl_amd_command_intercept *
diff --git a/opencl/api/opencl/khronos/headers/opencl2.2/CL/cl_ext.h b/opencl/api/opencl/khronos/headers/opencl2.2/CL/cl_ext.h
index 2c0eab3c62..1743e51635 100644
--- a/opencl/api/opencl/khronos/headers/opencl2.2/CL/cl_ext.h
+++ b/opencl/api/opencl/khronos/headers/opencl2.2/CL/cl_ext.h
@@ -352,6 +352,18 @@ typedef CL_API_ENTRY cl_int
const cl_event* /*event_wait_list*/,
cl_event* /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
+/***********************************
+* cl_amd_assembly_program extension *
+***********************************/
+#define cl_amd_assembly_program 1
+
+typedef CL_API_ENTRY cl_program (CL_API_CALL * clCreateProgramWithAssemblyAMD_fn) (
+ cl_context /* context */,
+ cl_uint /* count */,
+ const char** /* strings */,
+ const size_t* /* lengths */,
+ cl_int* /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2;
+
//
/***************************
* cl_amd_command_intercept *