Skip to content

Commit

Permalink
Added an option to use host-allocated dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Jul 21, 2019
1 parent be5d405 commit 6479aab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
5 changes: 4 additions & 1 deletion RandomX_OpenCL/RandomX_OpenCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int main(int argc, char** argv)
uint32_t bfactor = 5;
uint32_t high_precision = 1;
bool portable = false;
bool dataset_host_allocated = false;
bool validate = false;

for (int i = 1; i < argc; ++i)
Expand All @@ -64,12 +65,14 @@ int main(int argc, char** argv)
high_precision = 0;
else if (strcmp(argv[i], "--portable") == 0)
portable = true;
else if (strcmp(argv[i], "--dataset_host") == 0)
dataset_host_allocated = true;
else if (strcmp(argv[i], "--validate") == 0)
validate = true;
}

if (strcmp(argv[1], "--mine") == 0)
return test_mining(platform_id, device_id, intensity, start_nonce, workers_per_hash, bfactor, high_precision, portable, validate) ? 0 : 1;
return test_mining(platform_id, device_id, intensity, start_nonce, workers_per_hash, bfactor, high_precision, portable, dataset_host_allocated, validate) ? 0 : 1;
else if (strcmp(argv[1], "--test") == 0)
return tests(platform_id, device_id, intensity) ? 0 : 1;

Expand Down
26 changes: 20 additions & 6 deletions RandomX_OpenCL/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.

using namespace std::chrono;

bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uint32_t start_nonce, uint32_t workers_per_hash, uint32_t bfactor, uint32_t high_precision, bool portable, bool validate)
bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uint32_t start_nonce, uint32_t workers_per_hash, uint32_t bfactor, uint32_t high_precision, bool portable, bool dataset_host_allocated, bool validate)
{
std::cout << "Initializing GPU #" << device_id << " on OpenCL platform #" << platform_id << std::endl << std::endl;

Expand Down Expand Up @@ -104,14 +104,18 @@ bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uin
intensity -= (intensity & 63);

const size_t dataset_size = randomx_dataset_item_count() * RANDOMX_DATASET_ITEM_SIZE;
ALLOCATE_DEVICE_MEMORY(dataset_gpu, ctx, dataset_size);

std::cout << "Allocated " << (dataset_size / 1048576.0) << " MB dataset" << std::endl;
cl_int err;
cl_mem dataset_gpu = nullptr;
if (!dataset_host_allocated)
{
dataset_gpu = clCreateBuffer(ctx.context, CL_MEM_READ_ONLY, dataset_size, nullptr, &err);
CL_CHECK_RESULT(clCreateBuffer);
std::cout << "Allocated " << (dataset_size / 1048576.0) << " MB dataset on GPU" << std::endl;
}
std::cout << "Initializing dataset...";

randomx_dataset *myDataset;
bool large_pages_available = true;
cl_int err;
{
auto t1 = high_resolution_clock::now();

Expand Down Expand Up @@ -162,11 +166,21 @@ bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uin
}
}

CL_CHECKED_CALL(clEnqueueWriteBuffer, ctx.queue, dataset_gpu, CL_TRUE, 0, dataset_size, randomx_get_dataset_memory(myDataset), 0, nullptr, nullptr);
if (!dataset_host_allocated)
{
CL_CHECKED_CALL(clEnqueueWriteBuffer, ctx.queue, dataset_gpu, CL_TRUE, 0, dataset_size, randomx_get_dataset_memory(myDataset), 0, nullptr, nullptr);
}

std::cout << "done in " << (duration_cast<nanoseconds>(high_resolution_clock::now() - t1).count() / 1e9) << " seconds" << std::endl;
}

if (dataset_host_allocated)
{
dataset_gpu = clCreateBuffer(ctx.context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, dataset_size, randomx_get_dataset_memory(myDataset), &err);
CL_CHECK_RESULT(clCreateBuffer);
std::cout << "Using host-allocated " << (dataset_size / 1048576.0) << " MB dataset" << std::endl;
}

ALLOCATE_DEVICE_MEMORY(scratchpads_gpu, ctx, intensity * (SCRATCHPAD_SIZE + 64));
std::cout << "Allocated " << intensity << " scratchpads\n" << std::endl;

Expand Down
2 changes: 1 addition & 1 deletion RandomX_OpenCL/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.

#pragma once

bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uint32_t start_nonce, uint32_t workers_per_hash, uint32_t bfactor, uint32_t high_precision, bool portable, bool validate);
bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uint32_t start_nonce, uint32_t workers_per_hash, uint32_t bfactor, uint32_t high_precision, bool portable, bool dataset_host_allocated, bool validate);

0 comments on commit 6479aab

Please sign in to comment.