Skip to content

Commit

Permalink
2.14.3
Browse files Browse the repository at this point in the history
  • Loading branch information
IndeedMiners committed Mar 16, 2019
1 parent df31868 commit 943894f
Show file tree
Hide file tree
Showing 43 changed files with 423 additions and 269 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v2.14.1
- [#228](https://github.com/xmrig/xmrig-amd/issues/228#issuecomment-472287697) Fixed macOS support.
- [#235](https://github.com/xmrig/xmrig-amd/issues/235) Fixed autoconf for `cn/r` and other recently added algorithms.
- [#241](https://github.com/xmrig/xmrig-amd/issues/241) Fixed memory leak if used `cn/r` algorithm.

# v2.14.0
- **[#227](https://github.com/xmrig/xmrig-amd/pull/227) Added new algorithm `cryptonight/rwz`, short alias `cn/rwz` (also known as CryptoNight ReverseWaltz), for upcoming [Graft](https://www.graft.network/) fork.**
- **[#931](https://github.com/xmrig/xmrig/issues/931) Added new algorithm `cryptonight/zls`, short alias `cn/zls` for [Zelerius Network](https://zelerius.org) fork.**
Expand Down
2 changes: 1 addition & 1 deletion src/Mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)

uint8_t* p = reinterpret_cast<uint8_t*>(allocateExecutableMemory(0x4000));
c->generated_code = reinterpret_cast<cn_mainloop_fun_ms_abi>(p);
c->generated_code_double = reinterpret_cast<cn_mainloop_double_fun_ms_abi>(p + 0x2000);
c->generated_code_double = reinterpret_cast<cn_mainloop_fun_ms_abi>(p + 0x2000);

c->generated_code_data.variant = xmrig::VARIANT_MAX;
c->generated_code_data.height = (uint64_t)(-1);
Expand Down
18 changes: 1 addition & 17 deletions src/amd/OclCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,7 @@ bool OclCache::load()
}

if (OclLib::buildProgram(m_ctx->Program, 1, &m_ctx->DeviceID, options) != CL_SUCCESS) {
size_t len = 0;

if (OclLib::getProgramBuildInfo(m_ctx->Program, m_ctx->DeviceID, CL_PROGRAM_BUILD_LOG, 0, nullptr, &len) != CL_SUCCESS) {
return false;
}

char *buildLog = new char[len + 1]();

if (OclLib::getProgramBuildInfo(m_ctx->Program, m_ctx->DeviceID, CL_PROGRAM_BUILD_LOG, len, buildLog, nullptr) != CL_SUCCESS) {
delete [] buildLog;
return false;
}

Log::i()->text("Build log:");
std::cerr << buildLog << std::endl;

delete [] buildLog;
printf("Build log:\n%s\n", OclLib::getProgramBuildLog(m_ctx->Program, m_ctx->DeviceID).data());
return false;
}

Expand Down
117 changes: 68 additions & 49 deletions src/amd/OclCryptonightR_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,79 @@
#include <string>
#include <sstream>
#include <mutex>
/* XMRig
* Copyright 2010 Jeff Garzik <[email protected]>
* Copyright 2012-2014 pooler <[email protected]>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <[email protected]>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstring>
#include <mutex>
#include <sstream>
#include <string>
#include <thread>
#include "crypto/CryptoNight_monero.h"
#include "amd/OclCryptonightR_gen.h"
#include "amd/OclLib.h"


#include "amd/OclCache.h"
#include "amd/OclCryptonightR_gen.h"
#include "amd/OclError.h"
#include "amd/OclLib.h"
#include "common/log/Log.h"
#include "crypto/CryptoNight_monero.h"


static std::string get_code(const V4_Instruction* code, int code_size)
{
std::stringstream s;

for (int i = 0; i < code_size; ++i)
for (int i = 0; i < code_size; ++i)
{
const V4_Instruction inst = code[i];
const V4_Instruction inst = code[i];

const uint32_t a = inst.dst_index;
const uint32_t b = inst.src_index;
const uint32_t a = inst.dst_index;
const uint32_t b = inst.src_index;

switch (inst.opcode)
switch (inst.opcode)
{
case MUL:
s << 'r' << a << "*=r" << b << ';';
break;
case MUL:
s << 'r' << a << "*=r" << b << ';';
break;

case ADD:
case ADD:
s << 'r' << a << "+=r" << b << '+' << inst.C << "U;";
break;
break;

case SUB:
case SUB:
s << 'r' << a << "-=r" << b << ';';
break;
break;

case ROR:
case ROR:
case ROL:
s << 'r' << a << "=rotate(r" << a << ((inst.opcode == ROR) ? ",ROT_BITS-r" : ",r") << b << ");";
break;
break;

case XOR:
s << 'r' << a << "^=r" << b << ';';
break;
}
case XOR:
s << 'r' << a << "^=r" << b << ';';
break;
}

s << '\n';
}
s << '\n';
}

return s.str();
}
Expand Down Expand Up @@ -122,19 +149,9 @@ static void background_exec(T&& func)
}
}

static cl_program CryptonightR_build_program(
const GpuContext* ctx,
xmrig::Variant variant,
uint64_t height,
cl_kernel old_kernel,
std::string source,
std::string options,
std::string hash)
{
if (old_kernel) {
OclLib::releaseKernel(old_kernel);
}

static cl_program CryptonightR_build_program(const GpuContext *ctx, xmrig::Variant variant, uint64_t height, const std::string &source, const std::string &options, std::string hash)
{
std::vector<cl_program> old_programs;
old_programs.reserve(32);
{
Expand All @@ -146,7 +163,7 @@ static cl_program CryptonightR_build_program(
const CacheEntry& entry = CryptonightR_cache[i];
if ((entry.variant == variant) && (entry.height + PRECOMPILATION_DEPTH < height))
{
//LOG_INFO("CryptonightR: program for height %llu released (old program)", entry.height);
LOG_DEBUG("CryptonightR: program for height %" PRIu64 " released (old program)", entry.height);
old_programs.push_back(entry.program);
CryptonightR_cache[i] = std::move(CryptonightR_cache.back());
CryptonightR_cache.pop_back();
Expand Down Expand Up @@ -193,22 +210,22 @@ static cl_program CryptonightR_build_program(
}

ret = OclLib::buildProgram(program, 1, &ctx->DeviceID, options.c_str());
if (ret != CL_SUCCESS)
{
OclLib::releaseProgram(program);
if (ret != CL_SUCCESS) {
LOG_ERR("CryptonightR: clBuildProgram returned error %s", OclError::toString(ret));
printf("Build log:\n%s\n", OclLib::getProgramBuildLog(program, ctx->DeviceID).data());

OclLib::releaseProgram(program);
return nullptr;
}

ret = OclCache::wait_build(program, ctx->DeviceID);
if (ret != CL_SUCCESS)
{
if (ret != CL_SUCCESS) {
OclLib::releaseProgram(program);
LOG_ERR("CryptonightR: wait_build returned error %s", OclError::toString(ret));
return nullptr;
}

//LOG_INFO("CryptonightR: program for height %llu compiled", height);
LOG_DEBUG("CryptonightR: program for height %" PRIu64 " compiled", height);

{
std::lock_guard<std::mutex> g(CryptonightR_cache_mutex);
Expand All @@ -217,15 +234,17 @@ static cl_program CryptonightR_build_program(
return program;
}


static bool is_64bit(xmrig::Variant variant)
{
return false;
}

cl_program CryptonightR_get_program(GpuContext* ctx, xmrig::Variant variant, uint64_t height, bool background, cl_kernel old_kernel)

cl_program CryptonightR_get_program(GpuContext* ctx, xmrig::Variant variant, uint64_t height, bool background)
{
if (background) {
background_exec([=](){ CryptonightR_get_program(ctx, variant, height, false, old_kernel); });
background_exec([=](){ CryptonightR_get_program(ctx, variant, height, false); });
return nullptr;
}

Expand Down Expand Up @@ -287,11 +306,11 @@ cl_program CryptonightR_get_program(GpuContext* ctx, xmrig::Variant variant, uin
{
if ((entry.variant == variant) && (entry.height == height) && (entry.deviceIdx == ctx->deviceIdx) && (entry.hash == hash))
{
//LOG_INFO("CryptonightR: program for height %llu found in cache", height);
LOG_DEBUG("CryptonightR: program for height %" PRIu64 " found in cache", height);
return entry.program;
}
}
}

return CryptonightR_build_program(ctx, variant, height, old_kernel, source, options, hash);
return CryptonightR_build_program(ctx, variant, height, source, options, hash);
}
32 changes: 28 additions & 4 deletions src/amd/OclCryptonightR_gen.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
#ifndef __OCLCRYPTONIGHTR_GEN_H__
#define __OCLCRYPTONIGHTR_GEN_H__
/* XMRig
* Copyright 2010 Jeff Garzik <[email protected]>
* Copyright 2012-2014 pooler <[email protected]>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <[email protected]>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef XMRIG_OCLCRYPTONIGHTR_GEN_H
#define XMRIG_OCLCRYPTONIGHTR_GEN_H

#include "amd/GpuContext.h"

Expand All @@ -9,6 +33,6 @@ enum
};
static_assert((PRECOMPILATION_DEPTH >= 1) && (PRECOMPILATION_DEPTH <= 10), "Invalid precompilation depth");

cl_program CryptonightR_get_program(GpuContext* ctx, xmrig::Variant variant, uint64_t height, bool background = false, cl_kernel old_kernel = nullptr);
cl_program CryptonightR_get_program(GpuContext* ctx, xmrig::Variant variant, uint64_t height, bool background = false);

#endif
#endif /* XMRIG_OCLCRYPTONIGHTR_GEN_H */
10 changes: 5 additions & 5 deletions src/amd/OclGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,20 +620,20 @@ size_t XMRSetJob(GpuContext *ctx, uint8_t *input, size_t input_len, uint64_t tar
cl_int ret;
cl_kernel kernel = OclLib::createKernel(program, "cn1_cryptonight_r", &ret);

cl_kernel old_kernel = nullptr;
if (ret != CL_SUCCESS) {
LOG_ERR("CryptonightR: clCreateKernel returned error %s", OclError::toString(ret));
}
else {
old_kernel = ctx->Kernels[cn1_kernel_offset];
OclLib::releaseKernel(ctx->Kernels[cn1_kernel_offset]);
ctx->Kernels[cn1_kernel_offset] = kernel;
}

ctx->ProgramCryptonightR = program;

// Precompile next program in background
CryptonightR_get_program(ctx, variant, height + 1, true, old_kernel);
for (int i = 2; i <= PRECOMPILATION_DEPTH; ++i)
CryptonightR_get_program(ctx, variant, height + i, true, nullptr);
for (size_t i = 1; i <= PRECOMPILATION_DEPTH; ++i) {
CryptonightR_get_program(ctx, variant, height + i, true);
}

# ifdef APP_DEBUG
const int64_t timeFinish = xmrig::steadyTimestamp();
Expand Down
25 changes: 24 additions & 1 deletion src/amd/OclLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <[email protected]>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -345,6 +346,10 @@ cl_int OclLib::releaseKernel(cl_kernel kernel)
{
assert(pReleaseKernel != nullptr);

if (kernel == nullptr) {
return CL_SUCCESS;
}

const cl_int ret = pReleaseKernel(kernel);
if (ret != CL_SUCCESS) {
LOG_ERR(kErrorTemplate, OclError::toString(ret), kReleaseKernel);
Expand Down Expand Up @@ -521,3 +526,21 @@ xmrig::String OclLib::getDeviceName(cl_device_id id)

return buf;
}


xmrig::String OclLib::getProgramBuildLog(cl_program program, cl_device_id device)
{
size_t size = 0;
if (getProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, nullptr, &size) != CL_SUCCESS) {
return xmrig::String();
}

char *log = new char[size + 1]();

if (OclLib::getProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, size, log, nullptr) != CL_SUCCESS) {
delete [] log;
return xmrig::String();
}

return log;
}
4 changes: 3 additions & 1 deletion src/amd/OclLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <[email protected]>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -73,6 +74,7 @@ class OclLib
static xmrig::OclVendor getDeviceVendor(cl_device_id id);
static xmrig::String getDeviceBoardName(cl_device_id id);
static xmrig::String getDeviceName(cl_device_id id);
static xmrig::String getProgramBuildLog(cl_program program, cl_device_id device);

private:
static bool load();
Expand Down
Loading

0 comments on commit 943894f

Please sign in to comment.