Skip to content

Commit

Permalink
Issue falahati#71 Adding SetForcePstate for TCC cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Maz committed Jul 16, 2024
1 parent 2a41eb4 commit cdb5c96
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions NvAPIWrapper/Native/Delegates/GPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions NvAPIWrapper/Native/GPUApi.Performance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,5 +523,34 @@ public static void SetPerformanceStates20(
}
}
}

/// <summary>
/// [PRIVATE]
/// This function exists to force the P-State when SetPerformanceStates20 cannot.
/// Works with Tesla P40 and T4, likely other TCC cards.
/// </summary>
/// <param name="physicalGPUHandle">GPU handle to get information about.</param>
/// <param name="pstate">The pstate you want to set. 0 is highest performance, 8 is low power, 16 is default</param>
/// <param name="int3">Not sure. I'm setting it to 2 for now and it seems to work.</param>
/// <exception cref="NVIDIAApiException">Status.InvalidArgument: gpuHandle is NULL</exception>
/// <exception cref="NVIDIAApiException">Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle</exception>
public static void SetForcePstate(
PhysicalGPUHandle physicalGPUHandle,
int pstate,
int int3)
{
var status = DelegateFactory.GetDelegate<Delegates.GPU.NvAPI_GPU_SetForcePstate>()(
physicalGPUHandle,
pstate,
int3
);

if (status != Status.Ok)
{
throw new NVIDIAApiException(status);
}
}


}
}
1 change: 1 addition & 0 deletions NvAPIWrapper/Native/Helpers/FunctionId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion NvAPIWrapper/NvAPIWrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.8.1.101</Version>
<Version>0.8.1.103</Version>
<Company>falahati.net</Company>
<Description>NvAPIWrapper is a .Net wrapper for NVIDIA public API</Description>
<Authors>Soroush Falahati</Authors>
Expand Down

0 comments on commit cdb5c96

Please sign in to comment.