Skip to content

Commit

Permalink
api: also fix nvapi mapping and double swap on histo
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Nov 18, 2014
1 parent 582c971 commit 17cf376
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
15 changes: 6 additions & 9 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ extern uint32_t rejected_count;
extern int device_map[8];
extern char *device_name[8];

#define gpu_threads opt_n_threads

/***************************************************************/

static void gpustatus(int thr_id)
{
if (thr_id >= 0 && thr_id < gpu_threads) {
if (thr_id >= 0 && thr_id < opt_n_threads) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
int gpuid = cgpu->gpu_id;
char buf[512]; *buf = '\0';
Expand Down Expand Up @@ -156,9 +154,9 @@ static void gpustatus(int thr_id)

card = device_name[gpuid];

snprintf(buf, sizeof(buf), "GPU=%d;CARD=%s;TEMP=%.1f;FAN=%d;"
snprintf(buf, sizeof(buf), "THR=%d;GPU=%d;CARD=%s;TEMP=%.1f;FAN=%d;"
"FREQ=%d;PST=%s;KHS=%.2f;HWF=%d;I=%d|",
thr_id, card, cgpu->gpu_temp, cgpu->gpu_fan,
thr_id, gpuid, card, cgpu->gpu_temp, cgpu->gpu_fan,
cgpu->gpu_clock, pstate, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity);

Expand Down Expand Up @@ -186,7 +184,7 @@ static char *getsummary(char *params)
"ALGO=%s;GPUS=%d;KHS=%.2f;ACC=%d;REJ=%d;"
"ACCMN=%.3f;DIFF=%.6f;UPTIME=%.0f;TS=%u|",
PACKAGE_NAME, PACKAGE_VERSION, APIVERSION,
algo, gpu_threads, (double)global_hashrate / 1000.0,
algo, opt_n_threads, (double)global_hashrate / 1000.0,
accepted_count, rejected_count,
accps, global_diff, uptime, (uint32_t) ts);
return buffer;
Expand All @@ -198,7 +196,7 @@ static char *getsummary(char *params)
static char *getthreads(char *params)
{
*buffer = '\0';
for (int i = 0; i < gpu_threads; i++)
for (int i = 0; i < opt_n_threads; i++)
gpustatus(i);
return buffer;
}
Expand All @@ -211,10 +209,9 @@ static char *gethistory(char *params)
{
struct stats_data data[20];
int thrid = params ? atoi(params) : -1;
int gpuid = params ? device_map[(thrid & 0x7)] : -1;
char *p = buffer;
*buffer = '\0';
int records = stats_get_history(gpuid, data, ARRAY_SIZE(data));
int records = stats_get_history(thrid, data, ARRAY_SIZE(data));
for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_stat;
p += sprintf(p, "THR=%d|GPU=%d;KHS=%.2f;DIFF=%.6f;"
Expand Down
5 changes: 4 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function getdataFromPears()

function ignoreField($key)
{
$ignored = array('API','VER','GPU','CARD','GPUS','CPU','TS');
$ignored = array(
'API','VER','THR','GPU',
'CARD','GPUS','CPU','TS',
);
return in_array($key, $ignored);
}

Expand Down
20 changes: 10 additions & 10 deletions nvml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ int wrap_nvml_destroy(wrap_nvml_handle *nvmlh)
#ifdef WIN32
#include "nvapi/nvapi_ccminer.h"

static int nvapi_dev_map[NVAPI_MAX_PHYSICAL_GPUS] = { 0 };
static int nvapi_dev_map[8] = { 0 };
static NvDisplayHandle hDisplay_a[NVAPI_MAX_PHYSICAL_GPUS * 2] = { 0 };
static NvPhysicalGpuHandle phys[NVAPI_MAX_PHYSICAL_GPUS] = { 0 };
static NvU32 nvapi_dev_cnt = 0;
Expand Down Expand Up @@ -469,24 +469,24 @@ int wrap_nvapi_init()
cudaDeviceProp props;
if (cudaGetDeviceProperties(&props, g) == cudaSuccess)
device_bus_ids[g] = props.pciBusID;
nvapi_dev_map[g] = g;// default mapping
}

for (NvU8 i = 0; i < nvapi_dev_cnt; i++) {
NvAPI_ShortString name;
nvapi_dev_map[i] = i; // default mapping
ret = NvAPI_GPU_GetFullName(phys[i], name);
if (ret == NVAPI_OK) {
for (int g = 0; g < num_processors; g++) {
NvU32 busId;
ret = NvAPI_GPU_GetBusId(phys[i], &busId);
if (ret == NVAPI_OK && busId == device_bus_ids[g]) {
nvapi_dev_map[i] = g;
nvapi_dev_map[g] = i;
if (opt_debug)
applog(LOG_DEBUG, "CUDA GPU[%d] matches NVAPI GPU[%d]",
g, i);
break;
}
}
if (opt_debug)
applog(LOG_DEBUG, "CUDA GPU[%d] matches NVAPI GPU[%d]",
nvapi_dev_map[i], i);
} else {
NvAPI_ShortString string;
NvAPI_GetErrorMessage(ret, string);
Expand Down Expand Up @@ -518,7 +518,7 @@ int gpu_fanpercent(struct cgpu_info *gpu)
#ifdef WIN32
else {
unsigned int rpm = 0;
nvapi_fanspeed(nvapi_dev_map[gpu->thr_id], &rpm);
nvapi_fanspeed(nvapi_dev_map[gpu->gpu_id], &rpm);
pct = (rpm * 100) / fan_speed_max;
if (pct > 100) {
pct = 100;
Expand All @@ -539,7 +539,7 @@ float gpu_temp(struct cgpu_info *gpu)
}
#ifdef WIN32
else {
nvapi_temperature(nvapi_dev_map[gpu->thr_id], &tmp);
nvapi_temperature(nvapi_dev_map[gpu->gpu_id], &tmp);
tc = (float)tmp;
}
#endif
Expand All @@ -555,7 +555,7 @@ int gpu_clock(struct cgpu_info *gpu)
}
#ifdef WIN32
if (support == -1) {
nvapi_getclock(nvapi_dev_map[gpu->thr_id], &freq);
nvapi_getclock(nvapi_dev_map[gpu->gpu_id], &freq);
}
#endif
return (int) freq;
Expand All @@ -571,7 +571,7 @@ int gpu_pstate(struct cgpu_info *gpu)
#ifdef WIN32
if (support == -1) {
unsigned int pst = 0;
nvapi_getpstate(nvapi_dev_map[gpu->thr_id], &pst);
nvapi_getpstate(nvapi_dev_map[gpu->gpu_id], &pst);
pstate = (int) pst;
}
#endif
Expand Down

0 comments on commit 17cf376

Please sign in to comment.