Added support for alternative CUDA plugin API.

This commit is contained in:
XMRig 2019-12-25 00:35:43 +07:00
parent a95b179a60
commit ecb46643e2
No known key found for this signature in database
GPG key ID: 446A53638BE94409
6 changed files with 49 additions and 16 deletions

View file

@ -50,6 +50,7 @@ static const char *kAlloc = "alloc";
static const char *kCnHash = "cnHash";
static const char *kDeviceCount = "deviceCount";
static const char *kDeviceInfo = "deviceInfo";
static const char *kDeviceInfo_v2 = "deviceInfo_v2";
static const char *kDeviceInit = "deviceInit";
static const char *kDeviceInt = "deviceInt";
static const char *kDeviceName = "deviceName";
@ -62,6 +63,7 @@ static const char *kRelease = "release";
static const char *kRxHash = "rxHash";
static const char *kRxPrepare = "rxPrepare";
static const char *kSetJob = "setJob";
static const char *kSetJob_v2 = "setJob_v2";
static const char *kSymbolNotFound = "symbol not found";
static const char *kVersion = "version";
@ -70,6 +72,7 @@ using alloc_t = nvid_ctx * (*)(uint32_
using cnHash_t = bool (*)(nvid_ctx *, uint32_t, uint64_t, uint64_t, uint32_t *, uint32_t *);
using deviceCount_t = uint32_t (*)();
using deviceInfo_t = int32_t (*)(nvid_ctx *, int32_t, int32_t, int32_t, int32_t);
using deviceInfo_v2_t = bool (*)(nvid_ctx *, int32_t, int32_t, const char *, int32_t);
using deviceInit_t = bool (*)(nvid_ctx *);
using deviceInt_t = int32_t (*)(nvid_ctx *, CudaLib::DeviceProperty);
using deviceName_t = const char * (*)(nvid_ctx *);
@ -82,6 +85,7 @@ using release_t = void (*)(nvid_ctx *);
using rxHash_t = bool (*)(nvid_ctx *, uint32_t, uint64_t, uint32_t *, uint32_t *);
using rxPrepare_t = bool (*)(nvid_ctx *, const void *, size_t, bool, uint32_t);
using setJob_t = bool (*)(nvid_ctx *, const void *, size_t, int32_t);
using setJob_v2_t = bool (*)(nvid_ctx *, const void *, size_t, const char *);
using version_t = uint32_t (*)(Version);
@ -89,6 +93,7 @@ static alloc_t pAlloc = nullptr;
static cnHash_t pCnHash = nullptr;
static deviceCount_t pDeviceCount = nullptr;
static deviceInfo_t pDeviceInfo = nullptr;
static deviceInfo_v2_t pDeviceInfo_v2 = nullptr;
static deviceInit_t pDeviceInit = nullptr;
static deviceInt_t pDeviceInt = nullptr;
static deviceName_t pDeviceName = nullptr;
@ -101,6 +106,7 @@ static release_t pRelease = nullptr;
static rxHash_t pRxHash = nullptr;
static rxPrepare_t pRxPrepare = nullptr;
static setJob_t pSetJob = nullptr;
static setJob_v2_t pSetJob_v2 = nullptr;
static version_t pVersion = nullptr;
@ -145,6 +151,18 @@ bool xmrig::CudaLib::cnHash(nvid_ctx *ctx, uint32_t startNonce, uint64_t height,
}
bool xmrig::CudaLib::deviceInfo(nvid_ctx *ctx, int32_t blocks, int32_t threads, const Algorithm &algorithm, int32_t dataset_host) noexcept
{
const Algorithm algo = RxAlgo::id(algorithm);
if (pDeviceInfo_v2) {
return pDeviceInfo_v2(ctx, blocks, threads, algo.isValid() ? algo.shortName() : nullptr, dataset_host);
}
return pDeviceInfo(ctx, blocks, threads, algo, dataset_host) == 0;
}
bool xmrig::CudaLib::deviceInit(nvid_ctx *ctx) noexcept
{
return pDeviceInit(ctx);
@ -165,7 +183,12 @@ bool xmrig::CudaLib::rxPrepare(nvid_ctx *ctx, const void *dataset, size_t datase
bool xmrig::CudaLib::setJob(nvid_ctx *ctx, const void *data, size_t size, const Algorithm &algorithm) noexcept
{
return pSetJob(ctx, data, size, RxAlgo::id(algorithm));
const Algorithm algo = RxAlgo::id(algorithm);
if (pSetJob_v2) {
return pSetJob_v2(ctx, data, size, algo.shortName());
}
return pSetJob(ctx, data, size, algo);
}
@ -187,12 +210,6 @@ const char *xmrig::CudaLib::pluginVersion() noexcept
}
int xmrig::CudaLib::deviceInfo(nvid_ctx *ctx, int32_t blocks, int32_t threads, const Algorithm &algorithm, int32_t dataset_host) noexcept
{
return pDeviceInfo(ctx, blocks, threads, RxAlgo::id(algorithm), dataset_host);
}
int32_t xmrig::CudaLib::deviceInt(nvid_ctx *ctx, DeviceProperty property) noexcept
{
return pDeviceInt(ctx, property);
@ -292,11 +309,13 @@ bool xmrig::CudaLib::load()
return false;
}
uv_dlsym(&cudaLib, kDeviceInfo_v2, reinterpret_cast<void**>(&pDeviceInfo_v2));
uv_dlsym(&cudaLib, kSetJob_v2, reinterpret_cast<void**>(&pSetJob_v2));
try {
DLSYM(Alloc);
DLSYM(CnHash);
DLSYM(DeviceCount);
DLSYM(DeviceInfo);
DLSYM(DeviceInit);
DLSYM(DeviceInt);
DLSYM(DeviceName);
@ -308,8 +327,15 @@ bool xmrig::CudaLib::load()
DLSYM(Release);
DLSYM(RxHash);
DLSYM(RxPrepare);
DLSYM(SetJob);
DLSYM(Version);
if (!pDeviceInfo_v2) {
DLSYM(DeviceInfo);
}
if (!pSetJob_v2) {
DLSYM(SetJob);
}
} catch (std::exception &ex) {
return false;
}