From cdb5c96b172bd5b1b08c0dfa9eb9b660e90dbcfc Mon Sep 17 00:00:00 2001 From: Maz Date: Wed, 17 Jul 2024 00:26:01 +1000 Subject: [PATCH] Issue #71 Adding SetForcePstate for TCC cards --- NvAPIWrapper/Native/Delegates/GPU.cs | 6 +++++ NvAPIWrapper/Native/GPUApi.Performance.cs | 29 +++++++++++++++++++++++ NvAPIWrapper/Native/Helpers/FunctionId.cs | 1 + NvAPIWrapper/NvAPIWrapper.csproj | 2 +- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/NvAPIWrapper/Native/Delegates/GPU.cs b/NvAPIWrapper/Native/Delegates/GPU.cs index 5ff8659..1a5e5d9 100644 --- a/NvAPIWrapper/Native/Delegates/GPU.cs +++ b/NvAPIWrapper/Native/Delegates/GPU.cs @@ -683,6 +683,12 @@ public delegate Status NvAPI_GPU_SetPStates20( [In] ValueTypeReference performanceStatesInfo); + [FunctionId(FunctionId.NvAPI_GPU_SetForcePstate)] + public delegate Status NvAPI_GPU_SetForcePstate( + [In] PhysicalGPUHandle physicalGpu, + [In] int pstate, + [In] int int3); + [FunctionId(FunctionId.NvAPI_GPU_SetThermalPoliciesStatus)] public delegate Status NvAPI_GPU_SetThermalPoliciesStatus( [In] PhysicalGPUHandle physicalGpu, diff --git a/NvAPIWrapper/Native/GPUApi.Performance.cs b/NvAPIWrapper/Native/GPUApi.Performance.cs index 06ce3ee..543452b 100644 --- a/NvAPIWrapper/Native/GPUApi.Performance.cs +++ b/NvAPIWrapper/Native/GPUApi.Performance.cs @@ -523,5 +523,34 @@ public static void SetPerformanceStates20( } } } + + /// + /// [PRIVATE] + /// This function exists to force the P-State when SetPerformanceStates20 cannot. + /// Works with Tesla P40 and T4, likely other TCC cards. + /// + /// GPU handle to get information about. + /// The pstate you want to set. 0 is highest performance, 8 is low power, 16 is default + /// Not sure. I'm setting it to 2 for now and it seems to work. + /// Status.InvalidArgument: gpuHandle is NULL + /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle + public static void SetForcePstate( + PhysicalGPUHandle physicalGPUHandle, + int pstate, + int int3) + { + var status = DelegateFactory.GetDelegate()( + physicalGPUHandle, + pstate, + int3 + ); + + if (status != Status.Ok) + { + throw new NVIDIAApiException(status); + } + } + + } } \ No newline at end of file diff --git a/NvAPIWrapper/Native/Helpers/FunctionId.cs b/NvAPIWrapper/Native/Helpers/FunctionId.cs index 446f8b4..23c3d31 100644 --- a/NvAPIWrapper/Native/Helpers/FunctionId.cs +++ b/NvAPIWrapper/Native/Helpers/FunctionId.cs @@ -622,6 +622,7 @@ internal enum FunctionId : uint NvAPI_GPU_SetPstates20 = 0x0F4DAE6B, NvAPI_GPU_SetPstatesInfo = 0x0CDF27911, NvAPI_GPU_SetThermalPoliciesStatus = 0x034C0B13D, + NvAPI_GPU_SetForcePstate = 0x025BFB10, NvAPI_Hybrid_IsAppMigrationStateChangeable = 0x584CB0B6, NvAPI_Hybrid_QueryBlockedMigratableApps = 0x0F4C2F8CC, NvAPI_Hybrid_QueryUnblockedNonMigratableApps = 0x5F35BCB5, diff --git a/NvAPIWrapper/NvAPIWrapper.csproj b/NvAPIWrapper/NvAPIWrapper.csproj index 2a854c2..c555add 100644 --- a/NvAPIWrapper/NvAPIWrapper.csproj +++ b/NvAPIWrapper/NvAPIWrapper.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45 - 0.8.1.101 + 0.8.1.103 falahati.net NvAPIWrapper is a .Net wrapper for NVIDIA public API Soroush Falahati