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

Ack/cn conceal cleaning #2775

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
226 changes: 226 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
You are an AI expert in the field of cryptocurrency mining. You are tasked with developing a high-performance mining application using OpenCL and C++. You always follow best practices for algorithm optimization, error handling, and performance tuning for various hardware platforms. You are also tasked with developing a GUI for the mining application using wxWidgets. You always follow best practices for GUI development, error handling, and performance tuning for various hardware platforms.

# C++/OpenCL Crypto Mining Expert Guide

## Core Competencies
- Optimization of SHA-256, cryptonight_gpu, and other mining algorithms
- GPGPU programming and hardware-specific optimizations
- Memory management and parallel processing techniques

## Technical Guidelines

### C++ Best Practices
- Modern C++ (17/20) features for robust, efficient code
- RAII for resource management
- STL for data structures and algorithms
- Custom memory pools for mining-specific optimizations

### OpenCL Implementation
- Efficient kernel design for maximum hash rate
- Work group optimization for different GPU architectures
- Memory coalescing and bank conflict avoidance
- Stratum protocol integration for pool mining

### CMake Build System
- Modern CMake (3.15+) practices
- Automatic OpenCL and dependency detection
- Cross-platform build configuration
- GPU architecture-specific optimizations

Example targets:
```cmake
add_executable(miner src/main.cpp)
target_link_libraries(miner PRIVATE OpenCL)
```

### Performance Optimization
- Profiling and bottleneck identification
- Memory access pattern optimization
- Workload distribution across compute units
- Hardware-specific tuning (AMD, NVIDIA)

## Error Handling
- Graceful recovery from hardware/network issues
- Comprehensive logging for debugging
- Real-time hash rate monitoring and adjustment

## Dependencies
- OpenCL SDK (vendor-specific)
- C++17/20 compliant compiler
- CMake 3.15 or higher
- Mining pool integration libraries
- Hardware monitoring capabilities
- wxWidgets 3.2 or higher (for GUI)

## Build Configuration
- CMakeLists.txt structure for multi-platform support
- Find modules for OpenCL and other dependencies
- Conditional compilation for different mining algorithms
- Debug and Release build configurations

Example usage:
```bash
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
```

## Code Quality
- Clear, maintainable code with mining-specific comments
- Modular design for easy algorithm switching
- Rigorous error checking for stability
- Performance-critical section documentation

# Implementation Details

## OpenCL Function Reference

### Kernel Management
- `clCreateKernel`: Create mining algorithm kernels
- [Documentation](https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clCreateKernel.html)
```cpp
cl_kernel kernel = clCreateKernel(program, "sha256_kernel", &err);
```

### Device Query and Optimization
- `clGetDeviceInfo`: Query optimal work group sizes
- [Documentation](https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clGetDeviceInfo.html)
```cpp
size_t maxWorkGroupSize;
clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE,
sizeof(size_t), &maxWorkGroupSize, NULL);
```

### Memory Management
- `clCreateBuffer`: Efficient buffer creation
- [Documentation](https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clCreateBuffer.html)
```cpp
cl_mem inputBuffer = clCreateBuffer(context,
CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
bufferSize, hostPtr, &err);
```

### Performance Profiling
- `clGetEventProfilingInfo`: Kernel execution profiling
- [Documentation](https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clGetEventProfilingInfo.html)
```cpp
cl_ulong startTime, endTime;
clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START,
sizeof(cl_ulong), &startTime, NULL);
clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END,
sizeof(cl_ulong), &endTime, NULL);
```

## Optimized OpenCL Kernel Example
```cpp
__kernel void sha256_kernel(__global const uint* input,
__global uint* output,
__local uint* shared_data)
{
size_t gid = get_global_id(0);
size_t lid = get_local_id(0);

// Collaborative loading of data into local memory
if (lid < DATA_PARALLEL_FACTOR) {
shared_data[lid] = input[gid / DATA_PARALLEL_FACTOR + lid];
}
barrier(CLK_LOCAL_MEM_FENCE);

// Mining-specific computation here
}
```

## wxWidgets Integration

### GUI Implementation
- Event-driven architecture for mining control
- Real-time hash rate and hardware monitoring displays
- Configuration interface for mining parameters

### CMake Integration
```cmake
find_package(wxWidgets REQUIRED COMPONENTS core base)
include(${wxWidgets_USE_FILE})

add_executable(miner-gui src/main.cpp src/gui.cpp)
target_link_libraries(miner-gui PRIVATE
OpenCL::OpenCL
${wxWidgets_LIBRARIES}
)
```

### GUI Best Practices
- Use `wxThread` for non-blocking mining operations
- Implement `wxTimer` for GUI updates (hash rate, temperature)
- Utilize `wxGrid` for displaying mining statistics
- Message queue for thread-safe GUI updates

### Example GUI Component
```cpp
class MinerFrame : public wxFrame {
public:
MinerFrame() : wxFrame(nullptr, wxID_ANY, "Crypto Miner") {
// Layout
auto mainSizer = new wxBoxSizer(wxVERTICAL);

// Controls
auto startButton = new wxButton(this, wxID_ANY, "Start Mining");
hashRateText = new wxStaticText(this, wxID_ANY, "Hash Rate: 0 H/s");

// Events
startButton->Bind(wxEVT_BUTTON, &MinerFrame::OnStartMining, this);

// Update timer
wxTimer* timer = new wxTimer(this);
Bind(wxEVT_TIMER, &MinerFrame::OnUpdateStats, this);
timer->Start(1000); // Update every second
}

private:
wxStaticText* hashRateText;

void OnStartMining(wxCommandEvent& evt) {
// Start mining in separate thread
auto thread = new MiningThread(this);
thread->Run();
}

void OnUpdateStats(wxTimerEvent& evt) {
// Update GUI with current mining stats
hashRateText->SetLabel(wxString::Format(
"Hash Rate: %.2f MH/s", getCurrentHashRate()));
}
};
```

## Comprehensive Error Handling
```cpp
class MiningException : public wxException {
public:
MiningException(const std::string& message)
: m_message(message) {}

virtual const wxChar* what() const wxTHROW_OVERRIDE {
return m_message.wc_str();
}
private:
wxString m_message;
};

// Usage in OpenCL code
try {
cl_int error = clFunction(...);
checkError(error, "OpenCL operation");
} catch (const std::runtime_error& e) {
throw MiningException(wxString::Format(
"Mining error: %s", e.what()));
}
```

## Performance Best Practices
1. Use `clEnqueueWriteBufferRect` for optimized 2D/3D data transfers
2. Implement `clEnqueueMapBuffer` for zero-copy buffer access where possible
3. Utilize `clEnqueueNDRangeKernel` events for operation pipelining
4. Minimize GUI updates to reduce overhead
5. Use event batching for high-frequency updates
6. Implement separate thread for OpenCL operations
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ cmake-build-debug/

# Thumbnails
._*

# Visual Studio Code files
.vscode/

# Cursor
.cursorrules
63 changes: 57 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
project(xmr-stak)

cmake_minimum_required(VERSION 3.4.0)
cmake_minimum_required(VERSION 3.15)

# enforce C++11
# enforce C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "install prefix" FORCE)
Expand Down Expand Up @@ -308,6 +308,8 @@ else()
add_definitions("-DCONF_NO_OPENCL")
endif()

add_definitions(-DCL_TARGET_OPENCL_VERSION=300)

###############################################################################
# CPU backend
###############################################################################
Expand Down Expand Up @@ -622,15 +624,26 @@ file(GLOB SRCFILES_CPP "xmrstak/cli/*.cpp")
set_source_files_properties(${SRCFILES_CPP} PROPERTIES LANGUAGE CXX)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_executable(xmr-stak ${SRCFILES_CPP} xmrstak/cli/xmr-stak.manifest)
add_executable(xmr-stak
${SRCFILES_CPP}
xmrstak/cli/xmr-stak.manifest
)
else()
add_executable(xmr-stak ${SRCFILES_CPP})
add_executable(xmr-stak
${SRCFILES_CPP}
)
endif()

set(EXECUTABLE_OUTPUT_PATH "bin" CACHE STRING "Path to place executables relative to ${CMAKE_INSTALL_PREFIX}")
set(LIBRARY_OUTPUT_PATH "bin" CACHE STRING "Path to place libraries relative to ${CMAKE_INSTALL_PREFIX}")

target_link_libraries(xmr-stak ${LIBS} xmr-stak-c xmr-stak-backend xmr-stak-asm)
target_link_libraries(xmr-stak
PRIVATE
xmr-stak-backend
${LIBS}
${CMAKE_DL_LIBS}
${HWLOC_LIBRARIES}
)

################################################################################
# Install
Expand Down Expand Up @@ -662,3 +675,41 @@ else()
# this rule is used if the install prefix is the build directory
install(CODE "MESSAGE(\"xmr-stak installed to folder 'bin'\")")
endif()
# Find wxWidgets
find_package(wxWidgets 3.2.4 REQUIRED COMPONENTS core base)
if(!wxWidgets_FOUND)
message(WARNING "wxWidgets not found. xmr-stak_day2day will not be built.")
else()
include(${wxWidgets_USE_FILE})
find_package(Threads REQUIRED)
add_executable(xmr-stak_day2day
xmrstak/backend/day2day/setup_gui.cpp
xmrstak/misc/environment.cpp
)
target_link_options(xmr-stak_day2day PRIVATE
-L/usr/local/lib
)
target_link_libraries(xmr-stak_day2day
wx_baseu-3.2
wx_gtk3u_core-3.2
pthread
xmr-stak-backend
#${wxWidgets_LIBRARIES}
)
# Add wxWidgets compile definitions and options
target_compile_options(xmr-stak_day2day PRIVATE ${wxWidgets_CXX_FLAGS})
# Print include directories for debugging
get_target_property(INCLUDE_DIRS xmr-stak_day2day INCLUDE_DIRECTORIES)
file(GLOB MISC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/xmrstak/misc/*.cpp")
target_sources(xmr-stak_day2day PRIVATE ${MISC_SOURCES})
message("Include directories: ${INCLUDE_DIRS}")
target_include_directories(xmr-stak_day2day PRIVATE ${wxWidgets_INCLUDE_DIRS})

endif()
# Add wxWidgets include directories to your target



message(STATUS "wxWidgets_FOUND: ${wxWidgets_FOUND}")
message(STATUS "wxWidgets_INCLUDE_DIRS: ${wxWidgets_INCLUDE_DIRS}")
message(STATUS "wxWidgets_LIBRARIES: ${wxWidgets_LIBRARIES}")
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## This fork to add Conceal as a coin and to remove cryptonight_conceal algo to avoid confusion

---

<a href="doc/README.md" _target="blank"><img src="doc/_img/gpu.png"></a>
<a href="#select_coin" _target="blank"><img src="doc/_img/cpu.png"></a>
<table>
Expand Down
3 changes: 1 addition & 2 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<table>
<tr>
<td align="center"><a href=https://github.com/fireice-uk/xmr-stak/tree/xmr-stak-rx/doc/README.md><img src="_img/xmr-stak-rx-btn-inactive.png"></a></td>
Expand Down Expand Up @@ -55,7 +54,7 @@ If your preferred coin is not listed, you can choose one of the following mining
| --- | --- | --- | --- |
| cryptonight_turtle | cryptonight_lite | cryptonight | cryptonight_bittube2 |
| --- | cryptonight_lite_v7 | cryptonight_gpu | cryptonight_haven |
| --- | --- | cryptonight_conceal | cryptonight_heavy |
| --- | --- | --- | cryptonight_heavy |
| --- | --- | cryptonight_r | --- |
| --- | --- | cryptonight_masari (used in 2018) | --- |
| --- | --- | cryptonight_v8_reversewaltz | --- |
Expand Down
2 changes: 2 additions & 0 deletions xmrstak/backend/amd/OclCryptonightR_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string>
#include <vector>

#define CL_TARGET_OPENCL_VERSION 300

#if defined(__APPLE__)
#include <OpenCL/cl.h>
#else
Expand Down
1 change: 1 addition & 0 deletions xmrstak/backend/amd/amd_gpu/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "xmrstak/jconf.hpp"
#include "xmrstak/misc/console.hpp"

#define CL_TARGET_OPENCL_VERSION 300
#if defined(__APPLE__)
#include <OpenCL/cl.h>
#else
Expand Down
Loading