Implemented unified cryptonight and RandomX scratchpad memory.
This commit is contained in:
parent
5699147aab
commit
20313cbc56
30 changed files with 434 additions and 297 deletions
|
@ -136,14 +136,10 @@ void xmrig::CpuBackend::printHashrate(bool details)
|
|||
|
||||
void xmrig::CpuBackend::setJob(const Job &job)
|
||||
{
|
||||
LOG_WARN("PROFILE %s %zu", d_ptr->controller->config()->cpu().threads().profileName(job.algorithm()).data(), job.algorithm().memory());
|
||||
|
||||
if (d_ptr->isReady(job.algorithm())) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO(GREEN_BOLD_S "INIT");
|
||||
|
||||
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||
const Threads<CpuThread> &threads = cpu.threads();
|
||||
|
||||
|
@ -151,7 +147,11 @@ void xmrig::CpuBackend::setJob(const Job &job)
|
|||
d_ptr->profileName = threads.profileName(job.algorithm());
|
||||
d_ptr->threads = threads.get(d_ptr->profileName);
|
||||
|
||||
LOG_INFO(BLUE_BG_S " %zu ", d_ptr->threads.size());
|
||||
LOG_INFO(GREEN_BOLD("CPU") " use profile " BLUE_BG(WHITE_BOLD_S " %s ") WHITE_BOLD_S " (" CYAN_BOLD("%zu") WHITE_BOLD(" threads)") " scratchpad " CYAN_BOLD("%zu KB"),
|
||||
d_ptr->profileName.data(),
|
||||
d_ptr->threads.size(),
|
||||
d_ptr->algo.memory() / 1024
|
||||
);
|
||||
|
||||
d_ptr->workers.stop();
|
||||
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "core/Miner.h"
|
||||
#include "crypto/cn/CnCtx.h"
|
||||
#include "crypto/cn/CryptoNight_test.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
#include "crypto/common/VirtualMemory.h"
|
||||
#include "crypto/rx/Rx.h"
|
||||
#include "crypto/rx/RxVm.h"
|
||||
#include "net/JobResults.h"
|
||||
|
@ -56,18 +58,18 @@ xmrig::CpuWorker<N>::CpuWorker(size_t index, const CpuLaunchData &data) :
|
|||
m_assembly(data.assembly),
|
||||
m_hwAES(data.hwAES),
|
||||
m_av(data.av()),
|
||||
m_miner(data.miner)
|
||||
m_miner(data.miner),
|
||||
m_ctx()
|
||||
{
|
||||
if (m_algorithm.family() != Algorithm::RANDOM_X) {
|
||||
m_memory = Mem::create(m_ctx, m_algorithm, N);
|
||||
}
|
||||
m_memory = new VirtualMemory(m_algorithm.memory() * N, data.hugePages);
|
||||
}
|
||||
|
||||
|
||||
template<size_t N>
|
||||
xmrig::CpuWorker<N>::~CpuWorker()
|
||||
{
|
||||
Mem::release(m_ctx, N, m_memory);
|
||||
CnCtx::release(m_ctx, N);
|
||||
delete m_memory;
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
delete m_vm;
|
||||
|
@ -81,7 +83,7 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
|
|||
{
|
||||
if (!m_vm) {
|
||||
RxDataset *dataset = Rx::dataset(m_job.currentJob().seedHash(), m_job.currentJob().algorithm());
|
||||
m_vm = new RxVm(dataset, true, !m_hwAES);
|
||||
m_vm = new RxVm(dataset, m_memory->scratchpad(), !m_hwAES);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -90,6 +92,14 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
|
|||
template<size_t N>
|
||||
bool xmrig::CpuWorker<N>::selfTest()
|
||||
{
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_algorithm.family() == Algorithm::RANDOM_X) {
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
||||
allocateCnCtx();
|
||||
|
||||
if (m_algorithm.family() == Algorithm::CN) {
|
||||
const bool rc = verify(Algorithm::CN_0, test_output_v0) &&
|
||||
verify(Algorithm::CN_1, test_output_v1) &&
|
||||
|
@ -136,12 +146,6 @@ bool xmrig::CpuWorker<N>::selfTest()
|
|||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_algorithm.family() == Algorithm::RANDOM_X) {
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -172,7 +176,6 @@ void xmrig::CpuWorker<N>::start()
|
|||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (job.algorithm().family() == Algorithm::RANDOM_X) {
|
||||
allocateRandomX_VM();
|
||||
randomx_calculate_hash(m_vm->get(), m_job.blob(), job.size(), m_hash);
|
||||
}
|
||||
else
|
||||
|
@ -262,10 +265,29 @@ bool CpuWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenceV
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
template<size_t N>
|
||||
void xmrig::CpuWorker<N>::allocateCnCtx()
|
||||
{
|
||||
if (m_ctx[0] == nullptr) {
|
||||
CnCtx::create(m_ctx, m_memory->scratchpad(), m_memory->size(), N);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<size_t N>
|
||||
void xmrig::CpuWorker<N>::consumeJob()
|
||||
{
|
||||
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) {
|
||||
allocateRandomX_VM();
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
allocateCnCtx();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,12 +48,12 @@ public:
|
|||
CpuWorker(size_t index, const CpuLaunchData &data);
|
||||
~CpuWorker() override;
|
||||
|
||||
inline const MemInfo &memory() const { return m_memory; }
|
||||
|
||||
protected:
|
||||
bool selfTest() override;
|
||||
void start() override;
|
||||
|
||||
inline const VirtualMemory *memory() const override { return m_memory; }
|
||||
|
||||
private:
|
||||
inline cn_hash_fun fn(const Algorithm &algorithm) const { return CnHash::fn(algorithm, m_av, m_assembly); }
|
||||
|
||||
|
@ -63,6 +63,7 @@ private:
|
|||
|
||||
bool verify(const Algorithm &algorithm, const uint8_t *referenceValue);
|
||||
bool verify2(const Algorithm &algorithm, const uint8_t *referenceValue);
|
||||
void allocateCnCtx();
|
||||
void consumeJob();
|
||||
|
||||
const Algorithm m_algorithm;
|
||||
|
@ -71,8 +72,8 @@ private:
|
|||
const CnHash::AlgoVariant m_av;
|
||||
const Miner *m_miner;
|
||||
cryptonight_ctx *m_ctx[N];
|
||||
MemInfo m_memory;
|
||||
uint8_t m_hash[N * 32];
|
||||
VirtualMemory *m_memory = nullptr;
|
||||
WorkerJob<N> m_job;
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue