rockm compile success

This commit is contained in:
Dobromir Popov
2025-09-06 11:41:40 +03:00
parent 856faefc1a
commit 27009b3d87
13 changed files with 49 additions and 25 deletions

View File

@@ -7,13 +7,14 @@
#include <dlfcn.h>
#include <cstring>
#include <cstdint>
#include <filesystem>
// HIP/ROCm runtime check (using dlopen, no direct headers needed)
// Forward declarations for GPU functions
extern "C" {
void rinhash_cuda(const uint8_t* input, size_t input_len, uint8_t* output);
void rinhash_cuda_batch(const uint8_t* block_headers, size_t block_header_len,
void rinhash_hip(const uint8_t* input, size_t input_len, uint8_t* output);
void rinhash_hip_batch(const uint8_t* block_headers, size_t block_header_len,
uint8_t* outputs, uint32_t num_blocks);
void RinHash(const uint32_t* version, const uint32_t* prev_block,
const uint32_t* merkle_root, const uint32_t* timestamp,
@@ -26,8 +27,8 @@ private:
bool gpu_available;
// Function pointers for GPU operations
decltype(&rinhash_cuda) gpu_rinhash;
decltype(&rinhash_cuda_batch) gpu_rinhash_batch;
decltype(&rinhash_hip) gpu_rinhash;
decltype(&rinhash_hip_batch) gpu_rinhash_batch;
decltype(&RinHash) gpu_RinHash;
// Mining parameters
@@ -61,30 +62,38 @@ public:
}
bool loadGPULibrary() {
// Try to load the GPU library
gpu_lib_handle = dlopen("./rocm-direct-output/gpu-libs/librinhash_hip.so", RTLD_LAZY);
if (!gpu_lib_handle) {
std::cerr << "Failed to load GPU library: " << dlerror() << std::endl;
std::cerr << "Make sure to run: sudo cp rocm-direct-output/gpu-libs/librinhash_hip.so /usr/local/lib/" << std::endl;
return false;
}
// Try to load the GPU library
std::cout << "Attempting to load GPU library..." << std::endl;
gpu_lib_handle = dlopen("./rocm-direct-output/gpu-libs/librinhash_hip.so", RTLD_LAZY);
if (!gpu_lib_handle) {
std::cerr << "Failed to load GPU library: " << dlerror() << std::endl;
std::cerr << "Make sure to run: sudo cp rocm-direct-output/gpu-libs/librinhash_hip.so /usr/local/lib/" << std::endl;
std::cerr << "Current working directory: " << std::filesystem::current_path() << std::endl;
return false;
}
std::cout << "GPU library loaded successfully!" << std::endl;
// Load function pointers
gpu_rinhash = (decltype(gpu_rinhash))dlsym(gpu_lib_handle, "rinhash_cuda");
gpu_rinhash_batch = (decltype(gpu_rinhash_batch))dlsym(gpu_lib_handle, "rinhash_cuda_batch");
gpu_RinHash = (decltype(gpu_RinHash))dlsym(gpu_lib_handle, "RinHash");
// Load function pointers
std::cout << "Loading GPU functions..." << std::endl;
gpu_rinhash = (decltype(gpu_rinhash))dlsym(gpu_lib_handle, "rinhash_hip");
gpu_rinhash_batch = (decltype(gpu_rinhash_batch))dlsym(gpu_lib_handle, "rinhash_hip_batch");
gpu_RinHash = (decltype(gpu_RinHash))dlsym(gpu_lib_handle, "RinHash");
if (!gpu_rinhash || !gpu_rinhash_batch || !gpu_RinHash) {
std::cerr << "Failed to load GPU functions: " << dlerror() << std::endl;
dlclose(gpu_lib_handle);
gpu_lib_handle = nullptr;
return false;
}
if (!gpu_rinhash) std::cerr << "Failed to load rinhash_hip" << std::endl;
if (!gpu_rinhash_batch) std::cerr << "Failed to load rinhash_hip_batch" << std::endl;
if (!gpu_RinHash) std::cerr << "Failed to load RinHash" << std::endl;
if (!gpu_rinhash || !gpu_rinhash_batch || !gpu_RinHash) {
std::cerr << "Failed to load GPU functions: " << dlerror() << std::endl;
dlclose(gpu_lib_handle);
gpu_lib_handle = nullptr;
return false;
}
std::cout << "GPU functions loaded successfully!" << std::endl;
// GPU availability will be verified by successful library loading
// and function calls working properly
std::cout << "GPU library loaded successfully!" << std::endl;
std::cout << "GPU functions ready for mining" << std::endl;
gpu_available = true;
@@ -149,7 +158,12 @@ public:
}
// Process batch on GPU
gpu_rinhash_batch(block_headers.data(), block_header_len, hashes.data(), num_nonces);
if (gpu_rinhash_batch) {
gpu_rinhash_batch(block_headers.data(), block_header_len, hashes.data(), num_nonces);
} else {
std::cerr << "GPU batch function not available" << std::endl;
return false;
}
hashes_computed += num_nonces;
// Check results