Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Provider ID starts from 1
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAR2 committed Jun 10, 2021
1 parent 4d5aabb commit 3bc7d70
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {
#define SPACEMESH_API_ERROR_CANCELED -4
#define SPACEMESH_API_ERROR_NO_COMPOTE_OPTIONS -5
#define SPACEMESH_API_ERROR_INVALID_PARAMETER -6
#define SPACEMESH_API_ERROR_INVALID_PROVIDER_ID -7

#define SPACEMESH_API_THROTTLED_MODE 0x00008000

Expand Down
2 changes: 1 addition & 1 deletion src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int scryptPositions(
cgpu = spacemesh_api_get_gpu(provider_id);

if (NULL == cgpu) {
return SPACEMESH_API_ERROR_INVALID_PARAMETER;
return SPACEMESH_API_ERROR_INVALID_PROVIDER_ID;
}
if (options & SPACEMESH_API_COMPUTE_LEAFS) {
if (NULL == out) {
Expand Down
10 changes: 7 additions & 3 deletions src/api_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ extern "C" void spacemesh_api_init()
extern "C" struct cgpu_info * spacemesh_api_get_gpu(int id)
{
spacemesh_api_init();
if (id >= 0 && id < s_total_devices) {
if (id < 1) {
return nullptr;
}
id--;
if (id < s_total_devices) {
return &s_gpus[id];
}
if (id == s_total_devices && s_cpu.available) {
Expand Down Expand Up @@ -168,7 +172,7 @@ extern "C" int spacemesh_api_get_providers(
else {
providers->compute_api = COMPUTE_API_CLASS_VULKAN;
}
providers->id = i;
providers->id = i + 1;
memcpy(providers->model, s_gpus[i].name, min(sizeof(providers->model), sizeof(s_gpus[i].name)));
providers->model[sizeof(providers->model) - 1] = 0;

Expand All @@ -179,7 +183,7 @@ extern "C" int spacemesh_api_get_providers(

if (s_cpu.available && current_providers < max_providers) {
providers->compute_api = COMPUTE_API_CLASS_CPU;
providers->id = i;
providers->id = i + 1;
providers->model[0] = 'C';
providers->model[1] = 'P';
providers->model[2] = 'U';
Expand Down
2 changes: 1 addition & 1 deletion test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void do_providers_list()
if (spacemesh_api_get_providers(providers, providersCount) == providersCount) {
printf("Available POST compute providers:\n");
for (int i = 0; i < providersCount; i++) {
printf("%3d: [%s] %s\n", i, getProviderClassString(providers[i].compute_api), providers[i].model);
printf("%3d: [%s] %s\n", providers[i].id, getProviderClassString(providers[i].compute_api), providers[i].model);
}
}

Expand Down

0 comments on commit 3bc7d70

Please sign in to comment.