From 1b6dee43bd5419d51c41847f32c2e23cbb49c35b Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 2 Nov 2018 16:09:59 -0400
Subject: [PATCH] P4 to Git Change 1702079 by jujiang@JJ-OCL-w8 on 2018/11/02
16:01:11
SWDEV-155310 - Request for OpenCL extension function to set stable pstate
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#60 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_profile_amd.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_profile_amd.h#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#324 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#600 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#170 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#115 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#35 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#102 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.hpp#32 edit
---
opencl/api/opencl/amdocl/cl_context.cpp | 1 +
opencl/api/opencl/amdocl/cl_profile_amd.cpp | 17 +++++++++++
opencl/api/opencl/amdocl/cl_profile_amd.h | 34 +++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/opencl/api/opencl/amdocl/cl_context.cpp b/opencl/api/opencl/amdocl/cl_context.cpp
index 5be091c464..069647d280 100644
--- a/opencl/api/opencl/amdocl/cl_context.cpp
+++ b/opencl/api/opencl/amdocl/cl_context.cpp
@@ -574,6 +574,7 @@ CL_API_ENTRY void* CL_API_CALL clGetExtensionFunctionAddress(const char* func_na
break;
case 'S':
CL_EXTENSION_ENTRYPOINT_CHECK(clSetThreadTraceParamAMD);
+ CL_EXTENSION_ENTRYPOINT_CHECK(clSetDeviceClockModeAMD);
break;
case 'U':
CL_EXTENSION_ENTRYPOINT_CHECK(clUnloadPlatformAMD);
diff --git a/opencl/api/opencl/amdocl/cl_profile_amd.cpp b/opencl/api/opencl/amdocl/cl_profile_amd.cpp
index 5e8cec3234..0359f5641b 100644
--- a/opencl/api/opencl/amdocl/cl_profile_amd.cpp
+++ b/opencl/api/opencl/amdocl/cl_profile_amd.cpp
@@ -6,6 +6,7 @@
#include "platform/context.hpp"
#include "platform/command.hpp"
#include "platform/perfctr.hpp"
+#include "device/device.hpp"
#include
/*! \addtogroup API
@@ -347,6 +348,22 @@ RUNTIME_ENTRY(cl_int, clGetPerfCounterInfoAMD,
}
RUNTIME_EXIT
+RUNTIME_ENTRY(cl_int, clSetDeviceClockModeAMD,
+ (cl_device_id device, cl_set_device_clock_mode_input_amd set_clock_mode_input,
+ cl_set_device_clock_mode_output_amd* set_clock_mode_output)) {
+ // Make sure we have a valid device object
+ if (!is_valid(device)) {
+ return CL_INVALID_DEVICE;
+ }
+ if (set_clock_mode_input.clock_mode >= CL_DEVICE_CLOCK_MODE_COUNT_AMD) {
+ return CL_INVALID_VALUE;
+ }
+ amd::Device* amdDevice = as_amd(device);
+ bool ret = amdDevice->SetClockMode(set_clock_mode_input, set_clock_mode_output);
+ return (ret == true)? CL_SUCCESS : CL_INVALID_OPERATION;
+}
+RUNTIME_EXIT
+
/*! @}
* @}
*/
diff --git a/opencl/api/opencl/amdocl/cl_profile_amd.h b/opencl/api/opencl/amdocl/cl_profile_amd.h
index 0a45d2a3f8..24d542c00a 100644
--- a/opencl/api/opencl/amdocl/cl_profile_amd.h
+++ b/opencl/api/opencl/amdocl/cl_profile_amd.h
@@ -114,6 +114,35 @@ enum PerfcounterInfo {
CL_PERFCOUNTER_LAST
};
+/*********************************
+* Set device clock mode data
+*********************************/
+enum cl_DeviceClockMode_AMD {
+ CL_DEVICE_CLOCK_MODE_DEFAULT_AMD = 0x0, /*Device clocks and other power settings are restored to default*/
+ CL_DEVICE_CLOCK_MODE_QUERY_AMD = 0x1, /*Queries the current device clock ratios. Leaves the clock mode of the device unchanged*/
+ CL_DEVICE_CLOCK_MODE_PROFILING_AMD = 0x2, /*Scale down from peak ratio*/
+ CL_DEVICE_CLOCK_MODE_MINIMUMMEMORY_AMD = 0x3, /* Memory clock is set to the lowest available level*/
+ CL_DEVICE_CLOCK_MODE_MINIMUMENGINE_AMD = 0x4, /*Engine clock is set to the lowest available level*/
+ CL_DEVICE_CLOCK_MODE_PEAK_AMD = 0x5, /*Clocks set to maximum when possible. Fan set to maximum.*/
+ CL_DEVICE_CLOCK_MODE_QUERYPROFILING_AMD = 0x6, /*Queries the profiling device clock ratios. Leaves the clock mode of the device unchanged*/
+ CL_DEVICE_CLOCK_MODE_QUERYPEAK_AMD = 0x7, /*Queries the peak device clock ratios.Leaves the clock mode of the device unchanged*/
+ CL_DEVICE_CLOCK_MODE_COUNT_AMD = 0x8, /*Maxmium count of device clock mode*/
+};
+
+typedef struct _cl_set_device_clock_mode_input_amd
+{
+ /* specify the clock mode for AMD GPU device*/
+ cl_DeviceClockMode_AMD clock_mode;
+} cl_set_device_clock_mode_input_amd;
+
+typedef struct _cl_set_device_clock_mode_output_amd
+{
+ /*Ratio of current mem clock to peak clock as obtained from DeviceProperties::maxGpuClock*/
+ cl_float memory_clock_ratio_to_peak;
+ /*Ratio of current gpu core clock to peak clock as obtained from DeviceProperties::maxGpuClock*/
+ cl_float engine_clock_ratio_to_peak;
+} cl_set_device_clock_mode_output_amd;
+
/*! \brief Creates a new HW performance counter
* for the specified OpenCL context.
*
@@ -220,6 +249,11 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetPerfCounterInfoAMD(
size_t /* param_value_size */, void* /* param_value */, size_t* /* param_value_size_ret */
) CL_API_SUFFIX__VERSION_1_0;
+extern CL_API_ENTRY cl_int CL_API_CALL clSetDeviceClockModeAMD(
+ cl_device_id /* device*/, cl_set_device_clock_mode_input_amd /* Clock_Mode_Input */,
+ cl_set_device_clock_mode_output_amd* /* Clock_Mode_Output */
+ ) CL_API_SUFFIX__VERSION_1_0;
+
#ifdef __cplusplus
} /*extern "C"*/
#endif /*__cplusplus*/