Improved error handling.

This commit is contained in:
XMRig 2019-10-27 19:51:21 +07:00
parent c9f7cbae09
commit 0e224abb0a
6 changed files with 45 additions and 18 deletions

View file

@ -54,12 +54,6 @@ static inline bool isReady() { return !Nonce::isPaused()
static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / intensity + 1; } static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / intensity + 1; }
static inline void printError(size_t id, const char *error)
{
LOG_ERR("%s" RED_S " thread " RED_BOLD("#%zu") RED_S " failed with error " RED_BOLD("%s"), cuda_tag(), id, error);
}
} // namespace xmrig } // namespace xmrig

View file

@ -26,15 +26,9 @@
#include "backend/cuda/runners/CudaBaseRunner.h" #include "backend/cuda/runners/CudaBaseRunner.h"
#include "backend/cuda/wrappers/CudaLib.h" #include "backend/cuda/wrappers/CudaLib.h"
#include "backend/cuda/CudaLaunchData.h" #include "backend/cuda/CudaLaunchData.h"
//#include "backend/opencl/cl/OclSource.h" #include "backend/common/Tags.h"
//#include "backend/opencl/OclCache.h"
//#include "backend/opencl/OclLaunchData.h"
//#include "backend/opencl/runners/tools/OclSharedState.h"
//#include "backend/opencl/wrappers/OclError.h"
//#include "backend/opencl/wrappers/OclLib.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
//#include "crypto/common/VirtualMemory.h"
xmrig::CudaBaseRunner::CudaBaseRunner(size_t id, const CudaLaunchData &data) : xmrig::CudaBaseRunner::CudaBaseRunner(size_t id, const CudaLaunchData &data) :
@ -57,7 +51,13 @@ bool xmrig::CudaBaseRunner::init()
return false; return false;
} }
return CudaLib::deviceInit(m_ctx); if (!CudaLib::deviceInit(m_ctx)) {
printError(CudaLib::lastError(m_ctx));
return false;
}
return true;
} }
@ -66,7 +66,13 @@ bool xmrig::CudaBaseRunner::set(const Job &job, uint8_t *blob)
m_height = job.height(); m_height = job.height();
m_target = job.target(); m_target = job.target();
return CudaLib::setJob(m_ctx, blob, job.size(), job.algorithm()); if (!CudaLib::setJob(m_ctx, blob, job.size(), job.algorithm())) {
printError(CudaLib::lastError(m_ctx));
return false;
}
return true;
} }
@ -74,3 +80,11 @@ size_t xmrig::CudaBaseRunner::intensity() const
{ {
return m_data.thread.threads() * m_data.thread.blocks(); return m_data.thread.threads() * m_data.thread.blocks();
} }
void xmrig::CudaBaseRunner::printError(const char *error) const
{
if (error) {
LOG_ERR("%s" RED_S " thread " RED_BOLD("#%zu") RED_S " failed with error " RED_BOLD("%s"), cuda_tag(), m_threadId, error);
}
}

View file

@ -52,6 +52,8 @@ protected:
size_t intensity() const override; size_t intensity() const override;
protected: protected:
void printError(const char *error) const;
const CudaLaunchData &m_data; const CudaLaunchData &m_data;
const size_t m_threadId; const size_t m_threadId;
nvid_ctx *m_ctx = nullptr; nvid_ctx *m_ctx = nullptr;

View file

@ -34,5 +34,11 @@ xmrig::CudaCnRunner::CudaCnRunner(size_t index, const CudaLaunchData &data) : Cu
bool xmrig::CudaCnRunner::run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce) bool xmrig::CudaCnRunner::run(uint32_t startNonce, uint32_t *rescount, uint32_t *resnonce)
{ {
return CudaLib::cnHash(m_ctx, startNonce, m_height, m_target, rescount, resnonce); if (!CudaLib::cnHash(m_ctx, startNonce, m_height, m_target, rescount, resnonce)) {
printError(CudaLib::lastError(m_ctx));
return false;
}
return true;
} }

View file

@ -55,6 +55,7 @@ static const char *kDeviceName = "deviceName";
static const char *kDeviceUint = "deviceUint"; static const char *kDeviceUint = "deviceUint";
static const char *kDeviceUlong = "deviceUlong"; static const char *kDeviceUlong = "deviceUlong";
static const char *kInit = "init"; static const char *kInit = "init";
static const char *kLastError = "lastError";
static const char *kPluginVersion = "pluginVersion"; static const char *kPluginVersion = "pluginVersion";
static const char *kRelease = "release"; static const char *kRelease = "release";
static const char *kSetJob = "setJob"; static const char *kSetJob = "setJob";
@ -72,6 +73,7 @@ using deviceName_t = const char * (*)(nvid_
using deviceUint_t = uint32_t (*)(nvid_ctx *, CudaLib::DeviceProperty); using deviceUint_t = uint32_t (*)(nvid_ctx *, CudaLib::DeviceProperty);
using deviceUlong_t = uint64_t (*)(nvid_ctx *, CudaLib::DeviceProperty); using deviceUlong_t = uint64_t (*)(nvid_ctx *, CudaLib::DeviceProperty);
using init_t = void (*)(); using init_t = void (*)();
using lastError_t = const char * (*)(nvid_ctx *);
using pluginVersion_t = const char * (*)(); using pluginVersion_t = const char * (*)();
using release_t = void (*)(nvid_ctx *); using release_t = void (*)(nvid_ctx *);
using setJob_t = bool (*)(nvid_ctx *, const void *, size_t, int32_t); using setJob_t = bool (*)(nvid_ctx *, const void *, size_t, int32_t);
@ -88,6 +90,7 @@ static deviceName_t pDeviceName = nullptr;
static deviceUint_t pDeviceUint = nullptr; static deviceUint_t pDeviceUint = nullptr;
static deviceUlong_t pDeviceUlong = nullptr; static deviceUlong_t pDeviceUlong = nullptr;
static init_t pInit = nullptr; static init_t pInit = nullptr;
static lastError_t pLastError = nullptr;
static pluginVersion_t pPluginVersion = nullptr; static pluginVersion_t pPluginVersion = nullptr;
static release_t pRelease = nullptr; static release_t pRelease = nullptr;
static setJob_t pSetJob = nullptr; static setJob_t pSetJob = nullptr;
@ -117,7 +120,7 @@ bool xmrig::CudaLib::init(const char *fileName)
} }
const char *xmrig::CudaLib::lastError() const char *xmrig::CudaLib::lastError() noexcept
{ {
return uv_dlerror(&cudaLib); return uv_dlerror(&cudaLib);
} }
@ -153,6 +156,12 @@ const char *xmrig::CudaLib::deviceName(nvid_ctx *ctx) noexcept
} }
const char *xmrig::CudaLib::lastError(nvid_ctx *ctx) noexcept
{
return pLastError(ctx);
}
const char *xmrig::CudaLib::pluginVersion() noexcept const char *xmrig::CudaLib::pluginVersion() noexcept
{ {
return pPluginVersion(); return pPluginVersion();
@ -255,6 +264,7 @@ bool xmrig::CudaLib::load()
DLSYM(DeviceUint); DLSYM(DeviceUint);
DLSYM(DeviceUlong); DLSYM(DeviceUlong);
DLSYM(Init); DLSYM(Init);
DLSYM(LastError);
DLSYM(PluginVersion); DLSYM(PluginVersion);
DLSYM(Release); DLSYM(Release);
DLSYM(SetJob); DLSYM(SetJob);

View file

@ -64,7 +64,7 @@ public:
}; };
static bool init(const char *fileName = nullptr); static bool init(const char *fileName = nullptr);
static const char *lastError(); static const char *lastError() noexcept;
static void close(); static void close();
static inline bool isInitialized() { return m_initialized; } static inline bool isInitialized() { return m_initialized; }
@ -74,6 +74,7 @@ public:
static bool deviceInit(nvid_ctx *ctx) noexcept; static bool deviceInit(nvid_ctx *ctx) noexcept;
static bool setJob(nvid_ctx *ctx, const void *data, size_t size, const Algorithm &algorithm) noexcept; static bool setJob(nvid_ctx *ctx, const void *data, size_t size, const Algorithm &algorithm) noexcept;
static const char *deviceName(nvid_ctx *ctx) noexcept; static const char *deviceName(nvid_ctx *ctx) noexcept;
static const char *lastError(nvid_ctx *ctx) noexcept;
static const char *pluginVersion() noexcept; static const char *pluginVersion() noexcept;
static int deviceInfo(nvid_ctx *ctx, int32_t blocks, int32_t threads, const Algorithm &algorithm) noexcept; static int deviceInfo(nvid_ctx *ctx, int32_t blocks, int32_t threads, const Algorithm &algorithm) noexcept;
static int32_t deviceInt(nvid_ctx *ctx, DeviceProperty property) noexcept; static int32_t deviceInt(nvid_ctx *ctx, DeviceProperty property) noexcept;