Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algo balancing #152

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4ed5358
Added new --calibrate-algo and --save-config command line options
MoneroOcean Jul 28, 2018
27c508b
Report all possible algorithms to the pool
MoneroOcean Jul 28, 2018
456cbbf
Added perf algo (PerfAlgo) basic support
MoneroOcean Jul 28, 2018
96eacfb
Added support for extended threads and algo-perf config parameters
MoneroOcean Jul 28, 2018
c17bfd3
Added xmrig::Algorithm parameter to autoConf function
MoneroOcean Jul 28, 2018
692088c
Support for OpenCL object release
MoneroOcean Jul 28, 2018
5e7c5b5
Semantic bug fix for cryptonight-heavy/0 OpenCL code
MoneroOcean Jul 28, 2018
0abc185
Added algo performance calibration (benchmarking) functionality
MoneroOcean Jul 28, 2018
976973b
Added pool job algo switch functionality
MoneroOcean Jul 28, 2018
968a8f7
Set m_calibrateAlgo to false by default
MoneroOcean Aug 1, 2018
3a3c628
Set m_saveConfig to false by default
MoneroOcean Aug 1, 2018
93f34fc
Calibrate and save algo-perf automatically
MoneroOcean Aug 1, 2018
84b0240
Added --calibrate-algo-time command line switch support
MoneroOcean Aug 4, 2018
922fb98
Fixed warning about signed/unsigned comparision
MoneroOcean Aug 4, 2018
36b3494
Added user info about current benchmark round length
MoneroOcean Aug 4, 2018
979102a
Added calibrate-algo and calibrate-algo-time save in config file and …
MoneroOcean Aug 4, 2018
3a47cf5
Script for Windows build
MoneroOcean Aug 5, 2018
982eedb
Moved from PerfAlgo to Algo in threads to removed not really used cn-…
MoneroOcean Aug 6, 2018
c8c3628
ALGO_INVALID -> INVALID_ALGO
MoneroOcean Aug 6, 2018
249723f
Restore original algorithm after benchmark
MoneroOcean Aug 6, 2018
20a5398
Removed wrong const word
MoneroOcean Aug 6, 2018
cd13031
Added Algorithm.h
MoneroOcean Aug 6, 2018
a7b7902
Fixed GPU context handling bugs
MoneroOcean Aug 8, 2018
66a50b4
Allow integer algo-perf values
MoneroOcean Aug 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support for OpenCL object release
  • Loading branch information
MoneroOcean committed Jul 28, 2018
commit 692088cf7b87ba919af2707cc66a3935fc5bf262
43 changes: 42 additions & 1 deletion src/amd/GpuContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
*
* 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 All @@ -25,7 +26,7 @@
#define __GPUCONTEXT_H__


#include "3rdparty/CL/cl.h"
#include "amd/OclLib.h"


#include <stdint.h>
Expand Down Expand Up @@ -73,6 +74,46 @@ struct GpuContext
Nonce(0)
{}

void release() { // stops all opencl kernels and releases all opencl resources (in destructor and copy constructor)
if (CommandQueues) {
OclLib::finish(CommandQueues);
OclLib::releaseCommandQueue(CommandQueues);
}
if (InputBuffer) OclLib::releaseMemObject(InputBuffer);
if (OutputBuffer) OclLib::releaseMemObject(OutputBuffer);
for (int i = 0; i < 6; ++ i) if (ExtraBuffers[i]) OclLib::releaseMemObject(ExtraBuffers[i]);
for (int i = 0; i < 11; ++ i) if (Kernels[i]) OclLib::releaseKernel(Kernels[i]);
if (Program) OclLib::releaseProgram(Program);
}

~GpuContext() { release(); }

GpuContext& operator=(const GpuContext& other) { // copy contructor we need to override default one to properly release OpenCL stuff
release();

deviceIdx = other.deviceIdx;
rawIntensity = other.rawIntensity;
workSize = other.workSize;
stridedIndex = other.stridedIndex;
memChunk = other.memChunk;
compMode = other.compMode;

DeviceID = other.DeviceID;
CommandQueues = other.CommandQueues;
InputBuffer = other.InputBuffer;
OutputBuffer = other.OutputBuffer;
for (int i = 0; i < 6; ++ i) ExtraBuffers[i] = other.ExtraBuffers[i];
Program = other.Program;
for (int i = 0; i < 11; ++ i) Kernels[i] = other.Kernels[i];

freeMem = other.freeMem;
computeUnits = other.computeUnits;
name = other.name;

Nonce = other.Nonce;
return *this;
}

/*Input vars*/
size_t deviceIdx;
size_t rawIntensity;
Expand Down
6 changes: 5 additions & 1 deletion src/amd/OclGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
*
* 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 @@ -410,7 +411,10 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, xmrig::Config *config)
TempDeviceList[i] = DeviceIDList[ctx[i].deviceIdx];
}

cl_context opencl_ctx = OclLib::createContext(nullptr, num_gpus, TempDeviceList, nullptr, nullptr, &ret);
// we store previous OpenCL context in static variable to be able to release it next time we do algo switch
static cl_context opencl_ctx = nullptr;
if (opencl_ctx) OclLib::releaseContext(opencl_ctx);
opencl_ctx = OclLib::createContext(nullptr, num_gpus, TempDeviceList, nullptr, nullptr, &ret);
if(ret != CL_SUCCESS) {
return OCL_ERR_API;
}
Expand Down
60 changes: 60 additions & 0 deletions src/amd/OclLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
*
* 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 @@ -53,6 +54,11 @@ static const char *kGetPlatformInfo = "clGetPlatformInfo";
static const char *kGetProgramBuildInfo = "clGetProgramBuildInfo";
static const char *kGetProgramInfo = "clGetProgramInfo";
static const char *kSetKernelArg = "clSetKernelArg";
static const char *kReleaseContext = "clReleaseContext";
static const char *kReleaseProgram = "clReleaseProgram";
static const char *kReleaseCommandQueue = "clReleaseCommandQueue";
static const char *kReleaseMemObject = "clReleaseMemObject";
static const char *kReleaseKernel = "clReleaseKernel";

typedef cl_command_queue (CL_API_CALL *createCommandQueueWithProperties_t)(cl_context, cl_device_id, const cl_queue_properties *, cl_int *);
typedef cl_command_queue (CL_API_CALL *createCommandQueue_t)(cl_context, cl_device_id, cl_command_queue_properties, cl_int *);
Expand All @@ -73,6 +79,11 @@ typedef cl_kernel (CL_API_CALL *createKernel_t)(cl_program, const char *, cl_int
typedef cl_mem (CL_API_CALL *createBuffer_t)(cl_context, cl_mem_flags, size_t, void *, cl_int *);
typedef cl_program (CL_API_CALL *createProgramWithBinary_t)(cl_context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int *);
typedef cl_program (CL_API_CALL *createProgramWithSource_t)(cl_context, cl_uint, const char **, const size_t *, cl_int *);
typedef cl_int (CL_API_CALL *releaseContext_t)(cl_context);
typedef cl_int (CL_API_CALL *releaseProgram_t)(cl_program);
typedef cl_int (CL_API_CALL *releaseCommandQueue_t)(cl_command_queue);
typedef cl_int (CL_API_CALL *releaseMemObject_t)(cl_mem);
typedef cl_int (CL_API_CALL *releaseKernel_t)(cl_kernel);

static createCommandQueueWithProperties_t pCreateCommandQueueWithProperties = nullptr;
static createCommandQueue_t pCreateCommandQueue = nullptr;
Expand All @@ -93,6 +104,11 @@ static createKernel_t pCreateKernel = nu
static createBuffer_t pCreateBuffer = nullptr;
static createProgramWithBinary_t pCreateProgramWithBinary = nullptr;
static createProgramWithSource_t pCreateProgramWithSource = nullptr;
static releaseContext_t pReleaseContext = nullptr;
static releaseProgram_t pReleaseProgram = nullptr;
static releaseCommandQueue_t pReleaseCommandQueue = nullptr;
static releaseMemObject_t pReleaseMemObject = nullptr;
static releaseKernel_t pReleaseKernel = nullptr;

#define DLSYM(x) if (uv_dlsym(&oclLib, k##x, reinterpret_cast<void**>(&p##x)) == -1) { return false; }

Expand Down Expand Up @@ -128,6 +144,11 @@ bool OclLib::load()
DLSYM(CreateBuffer);
DLSYM(CreateProgramWithBinary);
DLSYM(CreateProgramWithSource);
DLSYM(ReleaseContext);
DLSYM(ReleaseProgram);
DLSYM(ReleaseCommandQueue);
DLSYM(ReleaseMemObject);
DLSYM(ReleaseKernel);

uv_dlsym(&oclLib, kCreateCommandQueueWithProperties, reinterpret_cast<void**>(&pCreateCommandQueueWithProperties));

Expand Down Expand Up @@ -335,3 +356,42 @@ cl_program OclLib::createProgramWithSource(cl_context context, cl_uint count, co

return result;
}

cl_int OclLib::releaseContext(cl_context context)
{
assert(pReleaseContext != nullptr);

return pReleaseContext(context);
}


cl_int OclLib::releaseProgram(cl_program program)
{
assert(pReleaseProgram != nullptr);

return pReleaseProgram(program);
}


cl_int OclLib::releaseCommandQueue(cl_command_queue command_queue)
{
assert(pReleaseCommandQueue != nullptr);

return pReleaseCommandQueue(command_queue);
}


cl_int OclLib::releaseMemObject(cl_mem memobj)
{
assert(pReleaseMemObject != nullptr);

return pReleaseMemObject(memobj);
}


cl_int OclLib::releaseKernel(cl_kernel kernel)
{
assert(pReleaseKernel != nullptr);

return pReleaseKernel(kernel);
}
7 changes: 7 additions & 0 deletions src/amd/OclLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
*
* 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 @@ -51,6 +52,12 @@ class OclLib
static cl_mem createBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret);
static cl_program createProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_int *errcode_ret);
static cl_program createProgramWithSource(cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret);
// we need to properly release OpenCL we created to be able to do algo switching
static cl_int releaseContext(cl_context context);
static cl_int releaseProgram(cl_program program);
static cl_int releaseCommandQueue(cl_command_queue command_queue);
static cl_int releaseMemObject(cl_mem memobj);
static cl_int releaseKernel(cl_kernel kernel);

private:
static bool load();
Expand Down