-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
259 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#include "amdapi_adl.h" | ||
#include <QDebug> | ||
|
||
void* __stdcall ADL_Main_Memory_Alloc ( int iSize ) | ||
{ | ||
void* lpBuffer = malloc ( iSize ); | ||
return lpBuffer; | ||
} | ||
|
||
// Optional Memory de-allocation function | ||
void __stdcall ADL_Main_Memory_Free ( void** lpBuffer ) | ||
{ | ||
if ( NULL != *lpBuffer ) | ||
{ | ||
free ( *lpBuffer ); | ||
*lpBuffer = NULL; | ||
} | ||
} | ||
|
||
|
||
amdapi_adl::amdapi_adl() : QLibrary("atiadlxx") | ||
, _isInitialized(false) | ||
, _gpuCount(0) | ||
, _lpAdapterInfo(nullptr) | ||
, _context(nullptr) | ||
{ | ||
|
||
ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) resolve("ADL_Main_Control_Create"); | ||
ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) resolve("ADL_Main_Control_Destroy"); | ||
ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) resolve("ADL_Adapter_NumberOfAdapters_Get"); | ||
ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) resolve("ADL_Adapter_AdapterInfo_Get"); | ||
ADL_AdapterX2_Caps = (ADL_ADAPTERX2_CAPS) resolve( "ADL_AdapterX2_Caps"); | ||
ADL2_Adapter_Active_Get = (ADL2_ADAPTER_ACTIVE_GET)resolve( "ADL2_Adapter_Active_Get"); | ||
ADL2_OverdriveN_Capabilities_Get = (ADL2_OVERDRIVEN_CAPABILITIES_GET) resolve ( "ADL2_OverdriveN_Capabilities_Get"); | ||
ADL2_OverdriveN_SystemClocks_Get = (ADL2_OVERDRIVEN_SYSTEMCLOCKS_GET) resolve ( "ADL2_OverdriveN_SystemClocks_Get"); | ||
ADL2_OverdriveN_SystemClocks_Set = (ADL2_OVERDRIVEN_SYSTEMCLOCKS_SET) resolve ( "ADL2_OverdriveN_SystemClocks_Set"); | ||
ADL2_OverdriveN_MemoryClocks_Get = (ADL2_OVERDRIVEN_MEMORYCLOCKS_GET) resolve ( "ADL2_OverdriveN_MemoryClocks_Get"); | ||
ADL2_OverdriveN_MemoryClocks_Set = (ADL2_OVERDRIVEN_MEMORYCLOCKS_SET) resolve ( "ADL2_OverdriveN_MemoryClocks_Set"); | ||
ADL2_OverdriveN_PerformanceStatus_Get = (ADL2_OVERDRIVEN_PERFORMANCESTATUS_GET) resolve ("ADL2_OverdriveN_PerformanceStatus_Get"); | ||
ADL2_OverdriveN_FanControl_Get = (ADL2_OVERDRIVEN_FANCONTROL_GET) resolve ( "ADL2_OverdriveN_FanControl_Get"); | ||
ADL2_OverdriveN_FanControl_Set = (ADL2_OVERDRIVEN_FANCONTROL_SET) resolve ( "ADL2_OverdriveN_FanControl_Set"); | ||
ADL2_OverdriveN_PowerLimit_Get = (ADL2_OVERDRIVEN_POWERLIMIT_GET) resolve ( "ADL2_OverdriveN_PowerLimit_Get"); | ||
ADL2_OverdriveN_PowerLimit_Set = (ADL2_OVERDRIVEN_POWERLIMIT_SET) resolve ( "ADL2_OverdriveN_PowerLimit_Set"); | ||
ADL2_OverdriveN_Temperature_Get = (ADL2_OVERDRIVEN_TEMPERATURE_GET) resolve ( "ADL2_OverdriveN_Temperature_Get"); | ||
ADL2_Overdrive_Caps = (ADL2_OVERDRIVE_CAPS) resolve ( "ADL2_Overdrive_Caps"); | ||
if ( NULL == ADL_Main_Control_Create || | ||
NULL == ADL_Main_Control_Destroy || | ||
NULL == ADL_Adapter_NumberOfAdapters_Get|| | ||
NULL == ADL_Adapter_AdapterInfo_Get || | ||
NULL == ADL_AdapterX2_Caps || | ||
NULL == ADL2_Adapter_Active_Get || | ||
NULL == ADL2_OverdriveN_Capabilities_Get || | ||
NULL == ADL2_OverdriveN_SystemClocks_Get || | ||
NULL == ADL2_OverdriveN_SystemClocks_Set || | ||
NULL == ADL2_OverdriveN_MemoryClocks_Get || | ||
NULL == ADL2_OverdriveN_MemoryClocks_Set || | ||
NULL == ADL2_OverdriveN_PerformanceStatus_Get || | ||
NULL == ADL2_OverdriveN_FanControl_Get || | ||
NULL == ADL2_OverdriveN_FanControl_Set || | ||
NULL == ADL2_Overdrive_Caps | ||
) | ||
{ | ||
qDebug("Failed to get ADL function pointers"); | ||
return; | ||
} | ||
|
||
if (ADL_OK != ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1)) | ||
{ | ||
qDebug("Failed to initialize nested ADL2 context"); | ||
return ; | ||
} | ||
|
||
getGPUCount(); | ||
|
||
if(_gpuCount) | ||
{ | ||
_lpAdapterInfo = (LPAdapterInfo)malloc ( sizeof (AdapterInfo) * _gpuCount ); | ||
memset ( _lpAdapterInfo,'\0', sizeof (AdapterInfo) * _gpuCount ); | ||
|
||
// Get the AdapterInfo structure for all adapters in the system | ||
ADL_Adapter_AdapterInfo_Get (_lpAdapterInfo, sizeof (AdapterInfo) * _gpuCount); | ||
} | ||
|
||
_isInitialized = true; | ||
} | ||
|
||
|
||
amdapi_adl::~amdapi_adl() | ||
{ | ||
|
||
free(_lpAdapterInfo); | ||
ADL_Main_Control_Destroy(); | ||
} | ||
|
||
int amdapi_adl::getGPUCount() | ||
{ | ||
if ( ADL_OK != ADL_Adapter_NumberOfAdapters_Get ( &_gpuCount ) ) | ||
{ | ||
qDebug("Cannot get the number of adapters!"); | ||
return 0; | ||
} | ||
|
||
return _gpuCount; | ||
} | ||
|
||
int amdapi_adl::getGpuTemperature(int gpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::getGPUOffset(int gpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::getMemOffset(int gpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::getGpuClock(int gpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::getPowerLimit(int gpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::getFanSpeed(int gpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::setMemClockOffset(int gpu, int clock) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::setGPUOffset(int gpu, int offset) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::setPowerLimitPercent(int gpu, unsigned int percent) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::setTempLimitOffset(int gpu, unsigned int offset) | ||
{ | ||
return 0; | ||
} | ||
|
||
int amdapi_adl::setFanSpeed(int gpu, unsigned int percent) | ||
{ | ||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#ifndef AMDAPI_ADL_H | ||
#define AMDAPI_ADL_H | ||
|
||
#include <QMutex> | ||
#include <QLibrary> | ||
#include <QObject> | ||
|
||
#include "adl_sdk.h" | ||
#include "adl_structures.h" | ||
|
||
class amdapi_adl : public QLibrary | ||
{ | ||
|
||
public: | ||
amdapi_adl(); | ||
~amdapi_adl(); | ||
|
||
int getGPUCount(); | ||
|
||
int getGpuTemperature(int gpu); | ||
|
||
int getGPUOffset(int gpu); | ||
int getMemOffset(int gpu); | ||
|
||
int getGpuClock(int gpu); | ||
int getPowerLimit(int gpu); | ||
int getFanSpeed(int gpu); | ||
|
||
|
||
int setMemClockOffset(int gpu, int clock); | ||
int setGPUOffset(int gpu, int offset); | ||
int setPowerLimitPercent(int gpu, unsigned int percent); | ||
int setTempLimitOffset(int gpu, unsigned int offset); | ||
int setFanSpeed(int gpu, unsigned int percent); | ||
|
||
|
||
private: | ||
|
||
// Definitions of the used function pointers. Add more if you use other ADL APIs | ||
typedef int ( *ADL_MAIN_CONTROL_CREATE )(ADL_MAIN_MALLOC_CALLBACK, int ); | ||
typedef int ( *ADL_MAIN_CONTROL_DESTROY )(); | ||
typedef int ( *ADL_FLUSH_DRIVER_DATA)(int); | ||
typedef int (*ADL2_ADAPTER_ACTIVE_GET ) (ADL_CONTEXT_HANDLE, int, int* ); | ||
|
||
typedef int ( *ADL_ADAPTER_NUMBEROFADAPTERS_GET ) ( int* ); | ||
typedef int ( *ADL_ADAPTER_ADAPTERINFO_GET ) ( LPAdapterInfo, int ); | ||
typedef int ( *ADL_ADAPTERX2_CAPS) (int, int*); | ||
typedef int ( *ADL2_OVERDRIVE_CAPS) (ADL_CONTEXT_HANDLE context, int iAdapterIndex, int * iSupported, int * iEnabled, int * iVersion); | ||
typedef int ( *ADL2_OVERDRIVEN_CAPABILITIES_GET) (ADL_CONTEXT_HANDLE, int, ADLODNCapabilities*); | ||
typedef int ( *ADL2_OVERDRIVEN_SYSTEMCLOCKS_GET) (ADL_CONTEXT_HANDLE, int, ADLODNPerformanceLevels*); | ||
typedef int ( *ADL2_OVERDRIVEN_SYSTEMCLOCKS_SET) (ADL_CONTEXT_HANDLE, int, ADLODNPerformanceLevels*); | ||
typedef int ( *ADL2_OVERDRIVEN_MEMORYCLOCKS_GET) (ADL_CONTEXT_HANDLE, int, ADLODNPerformanceLevels*); | ||
typedef int ( *ADL2_OVERDRIVEN_MEMORYCLOCKS_SET) (ADL_CONTEXT_HANDLE, int, ADLODNPerformanceLevels*); | ||
typedef int ( *ADL2_OVERDRIVEN_PERFORMANCESTATUS_GET) (ADL_CONTEXT_HANDLE, int, ADLODNPerformanceStatus*); | ||
typedef int ( *ADL2_OVERDRIVEN_FANCONTROL_GET) (ADL_CONTEXT_HANDLE, int, ADLODNFanControl*); | ||
typedef int ( *ADL2_OVERDRIVEN_FANCONTROL_SET) (ADL_CONTEXT_HANDLE, int, ADLODNFanControl*); | ||
typedef int ( *ADL2_OVERDRIVEN_POWERLIMIT_GET) (ADL_CONTEXT_HANDLE, int, ADLODNPowerLimitSetting*); | ||
typedef int ( *ADL2_OVERDRIVEN_POWERLIMIT_SET) (ADL_CONTEXT_HANDLE, int, ADLODNPowerLimitSetting*); | ||
typedef int ( *ADL2_OVERDRIVEN_TEMPERATURE_GET) (ADL_CONTEXT_HANDLE, int, int, int*); | ||
|
||
ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create = NULL; | ||
ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy = NULL; | ||
ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get = NULL; | ||
ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get = NULL; | ||
ADL_ADAPTERX2_CAPS ADL_AdapterX2_Caps = NULL; | ||
ADL2_ADAPTER_ACTIVE_GET ADL2_Adapter_Active_Get=NULL; | ||
ADL2_OVERDRIVEN_CAPABILITIES_GET ADL2_OverdriveN_Capabilities_Get = NULL; | ||
ADL2_OVERDRIVEN_SYSTEMCLOCKS_GET ADL2_OverdriveN_SystemClocks_Get = NULL; | ||
ADL2_OVERDRIVEN_SYSTEMCLOCKS_SET ADL2_OverdriveN_SystemClocks_Set = NULL; | ||
ADL2_OVERDRIVEN_PERFORMANCESTATUS_GET ADL2_OverdriveN_PerformanceStatus_Get = NULL; | ||
ADL2_OVERDRIVEN_FANCONTROL_GET ADL2_OverdriveN_FanControl_Get =NULL; | ||
ADL2_OVERDRIVEN_FANCONTROL_SET ADL2_OverdriveN_FanControl_Set=NULL; | ||
ADL2_OVERDRIVEN_POWERLIMIT_GET ADL2_OverdriveN_PowerLimit_Get =NULL; | ||
ADL2_OVERDRIVEN_POWERLIMIT_SET ADL2_OverdriveN_PowerLimit_Set=NULL; | ||
ADL2_OVERDRIVEN_MEMORYCLOCKS_GET ADL2_OverdriveN_MemoryClocks_Get = NULL; | ||
ADL2_OVERDRIVEN_MEMORYCLOCKS_GET ADL2_OverdriveN_MemoryClocks_Set = NULL; | ||
ADL2_OVERDRIVE_CAPS ADL2_Overdrive_Caps = NULL; | ||
ADL2_OVERDRIVEN_TEMPERATURE_GET ADL2_OverdriveN_Temperature_Get = NULL; | ||
|
||
private: | ||
|
||
bool _isInitialized; | ||
|
||
int _gpuCount; | ||
|
||
ADL_CONTEXT_HANDLE _context; | ||
|
||
LPAdapterInfo _lpAdapterInfo; | ||
|
||
}; | ||
|
||
#endif // AMDAPI_ADL_H |