Skip to content

Commit 66fa2b3

Browse files
committed
Substitute correct device ID for AMD driver
1 parent 561a723 commit 66fa2b3

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

RandomX_OpenCL/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uin
109109

110110
options.str("");
111111
options << "-D RANDOMX_PROGRAM_ITERATIONS=" << RANDOMX_PROGRAM_ITERATIONS;
112-
if (!ctx.Compile(gcn_binary, { RANDOMX_RUN_CL }, { CL_RANDOMX_RUN }, options.str(), ALWAYS_USE_BINARY))
112+
if (!ctx.Compile(gcn_binary, { RANDOMX_RUN_CL }, { CL_RANDOMX_RUN }, options.str(), ALWAYS_USE_BINARY, ctx.elf_binary_flags))
113113
{
114114
return false;
115115
}

RandomX_OpenCL/opencl_helpers.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ bool OpenCLContext::Init(uint32_t platform_id, uint32_t device_id)
104104
return true;
105105
}
106106

107-
bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list<std::string>& source_files, const std::initializer_list<std::string>& kernel_names, const std::string& options, CachingParameters caching)
107+
bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list<std::string>& source_files, const std::initializer_list<std::string>& kernel_names, const std::string& options, CachingParameters caching, uint32_t force_elf_binary_flags)
108108
{
109109
std::vector<std::string> source;
110110
source.reserve(source_files.size());
@@ -138,7 +138,11 @@ bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list
138138
buf.insert(buf.begin(), std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
139139

140140
const size_t data_length = buf.size();
141+
if (force_elf_binary_flags)
142+
*(uint32_t*)(buf.data() + 0x30) = force_elf_binary_flags;
143+
141144
const unsigned char* binary_data = reinterpret_cast<const unsigned char*>(buf.data());
145+
142146
program = clCreateProgramWithBinary(context, 1, &device, &data_length, &binary_data, nullptr, &err);
143147
CL_CHECK_RESULT(clCreateProgramWithBinary);
144148

@@ -187,15 +191,17 @@ bool OpenCLContext::Compile(const char* binary_name, const std::initializer_list
187191
}
188192
std::cout << "done" << std::endl;
189193

190-
if (!created_with_binary)
191-
{
192-
size_t bin_size;
193-
CL_CHECKED_CALL(clGetProgramInfo, program, CL_PROGRAM_BINARY_SIZES, sizeof(bin_size), &bin_size, nullptr);
194+
size_t bin_size;
195+
CL_CHECKED_CALL(clGetProgramInfo, program, CL_PROGRAM_BINARY_SIZES, sizeof(bin_size), &bin_size, nullptr);
194196

195-
std::vector<char> binary_data(bin_size);
196-
char* tmp[1] = { binary_data.data() };
197-
CL_CHECKED_CALL(clGetProgramInfo, program, CL_PROGRAM_BINARIES, sizeof(tmp), tmp, NULL);
197+
std::vector<char> binary_data(bin_size);
198+
char* tmp[1] = { binary_data.data() };
199+
CL_CHECKED_CALL(clGetProgramInfo, program, CL_PROGRAM_BINARIES, sizeof(tmp), tmp, NULL);
198200

201+
elf_binary_flags = (bin_size >= 0x34) ? *(uint32_t*)(binary_data.data() + 0x30) : 0;
202+
203+
if (!created_with_binary)
204+
{
199205
std::ofstream f(binary_name, std::ios::binary);
200206
f.write(tmp[0], bin_size);
201207
f.close();

RandomX_OpenCL/opencl_helpers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ struct OpenCLContext
5656
OpenCLContext()
5757
: context(0)
5858
, queue(0)
59+
, elf_binary_flags(0)
5960
{}
6061

6162
~OpenCLContext();
6263

6364
bool Init(uint32_t platform_id, uint32_t device_id);
64-
bool Compile(const char* binary_name, const std::initializer_list<std::string>& source_files, const std::initializer_list<std::string>& kernel_names, const std::string& options = std::string(), CachingParameters caching = ALWAYS_COMPILE);
65+
bool Compile(const char* binary_name, const std::initializer_list<std::string>& source_files, const std::initializer_list<std::string>& kernel_names, const std::string& options = std::string(), CachingParameters caching = ALWAYS_COMPILE, uint32_t force_elf_binary_flags = 0);
6566

6667
cl_device_id device;
6768
cl_context context;
6869
cl_command_queue queue;
70+
uint32_t elf_binary_flags;
6971
std::map<std::string, cl_kernel> kernels;
7072

7173
std::vector<char> device_name;

0 commit comments

Comments
 (0)