Browse Source
Allow to get/set missing infos like the power limit on x86 squashed for a better min/max and device mapping Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>master
Tanguy Pruvot
9 years ago
7 changed files with 252 additions and 13 deletions
@ -1,2 +1,44 @@ |
|||||||
/* todo: stripped version... or not */ |
#pragma once |
||||||
|
|
||||||
#include "nvapi.h" |
#include "nvapi.h" |
||||||
|
|
||||||
|
NvAPI_Status nvapi_dll_init(); |
||||||
|
|
||||||
|
typedef struct { |
||||||
|
NvU32 version; |
||||||
|
NvU32 flags; |
||||||
|
struct |
||||||
|
{ |
||||||
|
NvU32 pstate; // Assumption
|
||||||
|
NvU32 unknown1[2]; |
||||||
|
NvU32 min_power; |
||||||
|
NvU32 unknown2[2]; |
||||||
|
NvU32 def_power; |
||||||
|
NvU32 unknown3[2]; |
||||||
|
NvU32 max_power; |
||||||
|
NvU32 unknown4; // 0
|
||||||
|
} entries[4]; |
||||||
|
} NVAPI_GPU_POWER_INFO; |
||||||
|
|
||||||
|
typedef struct { |
||||||
|
NvU32 version; |
||||||
|
NvU32 flags; |
||||||
|
struct { |
||||||
|
NvU32 unknown1; |
||||||
|
NvU32 unknown2; |
||||||
|
NvU32 power; // percent * 1000
|
||||||
|
NvU32 unknown4; |
||||||
|
} entries[4]; |
||||||
|
} NVAPI_GPU_POWER_STATUS; |
||||||
|
|
||||||
|
#define NVAPI_GPU_POWER_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_STATUS, 1) |
||||||
|
#define NVAPI_GPU_POWER_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_INFO, 1) |
||||||
|
|
||||||
|
NvAPI_Status NvAPI_DLL_GetInterfaceVersionString(NvAPI_ShortString string); |
||||||
|
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetInfo(NvPhysicalGpuHandle hPhysicalGpu, NVAPI_GPU_POWER_INFO* pInfo); |
||||||
|
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetStatus(NvPhysicalGpuHandle hPhysicalGpu, NVAPI_GPU_POWER_STATUS* pPolicies); |
||||||
|
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesSetStatus(NvPhysicalGpuHandle hPhysicalGpu, NVAPI_GPU_POWER_STATUS* pPolicies); |
||||||
|
|
||||||
|
NvAPI_Status NvAPI_DLL_Unload(); |
||||||
|
|
||||||
|
#define NV_ASSERT(x) { NvAPI_Status ret = x; if(ret != NVAPI_OK) return ret; } |
||||||
|
@ -0,0 +1,128 @@ |
|||||||
|
/**
|
||||||
|
* Wrapper to nvapi.dll to query informations missing for x86 binaries (there is no nvml x86) |
||||||
|
* based on the work of https://github.com/ircubic/lib_gpu
|
||||||
|
* |
||||||
|
* tpruvot@ccminer.org 06-2016 |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifdef _WIN32 |
||||||
|
|
||||||
|
#include <windows.h> |
||||||
|
#include <memory> |
||||||
|
#include <stdexcept> |
||||||
|
|
||||||
|
#include "compat/nvapi/nvapi_ccminer.h" |
||||||
|
|
||||||
|
class NvAPILibraryHandle |
||||||
|
{ |
||||||
|
typedef void *(*QueryPtr)(uint32_t); |
||||||
|
|
||||||
|
private: |
||||||
|
HMODULE library; |
||||||
|
QueryPtr nvidia_query; |
||||||
|
|
||||||
|
public: |
||||||
|
NvAPILibraryHandle() |
||||||
|
{ |
||||||
|
bool success = false; |
||||||
|
library = LoadLibrary("nvapi.dll"); |
||||||
|
if (library != NULL) { |
||||||
|
nvidia_query = reinterpret_cast<QueryPtr>(GetProcAddress(library, "nvapi_QueryInterface")); |
||||||
|
if (nvidia_query != NULL) { |
||||||
|
const uint32_t NVAPI_ID_INIT = 0x0150E828; |
||||||
|
auto init = static_cast<NvAPI_Status(*)()>(nvidia_query(NVAPI_ID_INIT)); |
||||||
|
NvAPI_Status ret = init(); |
||||||
|
success = (ret == NVAPI_OK); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!success) { |
||||||
|
throw std::runtime_error("Unable to locate NVAPI library!"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
~NvAPILibraryHandle() |
||||||
|
{ |
||||||
|
NvAPI_DLL_Unload(); |
||||||
|
FreeLibrary(library); |
||||||
|
} |
||||||
|
|
||||||
|
void *query(uint32_t ID) |
||||||
|
{ |
||||||
|
return nvidia_query(ID); |
||||||
|
} |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
static std::unique_ptr<NvAPILibraryHandle> nvidia_handle; |
||||||
|
bool nvapi_dll_loaded = false; |
||||||
|
|
||||||
|
NvAPI_Status nvapi_dll_init() |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!nvapi_dll_loaded) { |
||||||
|
nvidia_handle = std::make_unique<NvAPILibraryHandle>(); |
||||||
|
nvapi_dll_loaded = true; |
||||||
|
} |
||||||
|
} |
||||||
|
catch (std::runtime_error) { |
||||||
|
nvapi_dll_loaded = false; |
||||||
|
return NVAPI_ERROR; |
||||||
|
} |
||||||
|
|
||||||
|
return NVAPI_OK; |
||||||
|
} |
||||||
|
|
||||||
|
// Hidden nvapi.dll functions
|
||||||
|
|
||||||
|
#define NVAPI_ID_IFVERSION 0x01053FA5 |
||||||
|
NvAPI_Status NvAPI_DLL_GetInterfaceVersionString(NvAPI_ShortString string) { |
||||||
|
static NvAPI_Status (*pointer)(NvAPI_ShortString string) = NULL; |
||||||
|
if(!nvapi_dll_loaded) return NVAPI_API_NOT_INITIALIZED; |
||||||
|
if(!pointer) { |
||||||
|
pointer = (NvAPI_Status (*)(NvAPI_ShortString))nvidia_handle->query(NVAPI_ID_IFVERSION); |
||||||
|
} |
||||||
|
return (*pointer)(string); |
||||||
|
} |
||||||
|
|
||||||
|
#define NVAPI_ID_POWER_INFO 0x34206D86 |
||||||
|
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetInfo(NvPhysicalGpuHandle handle, NVAPI_GPU_POWER_INFO* pInfo) { |
||||||
|
static NvAPI_Status (*pointer)(NvPhysicalGpuHandle, NVAPI_GPU_POWER_INFO*) = NULL; |
||||||
|
if(!nvapi_dll_loaded) return NVAPI_API_NOT_INITIALIZED; |
||||||
|
if(!pointer) { |
||||||
|
pointer = (NvAPI_Status (*)(NvPhysicalGpuHandle, NVAPI_GPU_POWER_INFO*))nvidia_handle->query(NVAPI_ID_POWER_INFO); |
||||||
|
} |
||||||
|
return (*pointer)(handle, pInfo); |
||||||
|
} |
||||||
|
|
||||||
|
#define NVAPI_ID_POWERPOL_GET 0x70916171 |
||||||
|
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetStatus(NvPhysicalGpuHandle handle, NVAPI_GPU_POWER_STATUS* pPolicies) { |
||||||
|
static NvAPI_Status (*pointer)(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*) = NULL; |
||||||
|
if(!nvapi_dll_loaded) return NVAPI_API_NOT_INITIALIZED; |
||||||
|
if(!pointer) { |
||||||
|
pointer = (NvAPI_Status (*)(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*))nvidia_handle->query(NVAPI_ID_POWERPOL_GET); |
||||||
|
} |
||||||
|
return (*pointer)(handle, pPolicies); |
||||||
|
} |
||||||
|
|
||||||
|
#define NVAPI_ID_POWERPOL_SET 0x0AD95F5ED |
||||||
|
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesSetStatus(NvPhysicalGpuHandle handle, NVAPI_GPU_POWER_STATUS* pPolicies) { |
||||||
|
static NvAPI_Status (*pointer)(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*) = NULL; |
||||||
|
if(!nvapi_dll_loaded) return NVAPI_API_NOT_INITIALIZED; |
||||||
|
if(!pointer) { |
||||||
|
pointer = (NvAPI_Status (*)(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*))nvidia_handle->query(NVAPI_ID_POWERPOL_SET); |
||||||
|
} |
||||||
|
return (*pointer)(handle, pPolicies); |
||||||
|
} |
||||||
|
|
||||||
|
#define NVAPI_ID_UNLOAD 0xD22BDD7E |
||||||
|
NvAPI_Status NvAPI_DLL_Unload() { |
||||||
|
static NvAPI_Status (*pointer)() = NULL; |
||||||
|
if(!nvapi_dll_loaded) return NVAPI_API_NOT_INITIALIZED; |
||||||
|
if(!pointer) { |
||||||
|
pointer = (NvAPI_Status (*)())nvidia_handle->query(NVAPI_ID_UNLOAD); |
||||||
|
} |
||||||
|
return (*pointer)(); |
||||||
|
} |
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue