245 lines
6.4 KiB
Bash
245 lines
6.4 KiB
Bash
#!/bin/bash
|
|
# Direct build script using existing cpuminer-rocm-build container
|
|
# This avoids dependency issues by using the pre-configured ROCm environment
|
|
|
|
set -e
|
|
|
|
echo "=================================================="
|
|
echo " RinHash ROCm Direct Build Script"
|
|
echo "=================================================="
|
|
|
|
# Check if Docker is available
|
|
if ! command -v docker &> /dev/null; then
|
|
echo "ERROR: Docker not found in PATH"
|
|
echo "Please install Docker first"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Docker found:"
|
|
docker --version
|
|
echo ""
|
|
|
|
# Check if the cpuminer-rocm-build container exists and is running
|
|
if ! sudo docker ps | grep -q cpuminer-rocm-build; then
|
|
echo "ERROR: cpuminer-rocm-build container is not running"
|
|
echo "Please start the container using: docker start cpuminer-rocm-build"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Found running cpuminer-rocm-build container"
|
|
echo ""
|
|
|
|
# Build directory setup
|
|
BUILD_DIR="$(dirname "$0")"
|
|
cd "$BUILD_DIR" || exit 1
|
|
|
|
echo "Building RinHash ROCm GPU support using existing container..."
|
|
echo "This includes:"
|
|
echo " - Using pre-configured ROCm environment"
|
|
echo " - Building RinHash HIP implementation"
|
|
echo " - Creating GPU-accelerated mining functions"
|
|
echo ""
|
|
|
|
# Create output directories
|
|
mkdir -p rocm-direct-output/{gpu-libs,integration}
|
|
|
|
echo "Step 1: Building RinHash HIP GPU implementation..."
|
|
echo ""
|
|
|
|
# Execute build commands in the existing ROCm container
|
|
sudo docker exec -it cpuminer-rocm-build bash -c "
|
|
set -e
|
|
|
|
echo '==============================================='
|
|
echo ' Building RinHash HIP in ROCm container'
|
|
echo '==============================================='
|
|
echo ''
|
|
|
|
# Navigate to the RinHash HIP source directory
|
|
cd /workspaces/shared/repos/d-popov.com/mines/rin/miner/gpu/RinHash-hip
|
|
|
|
echo 'Current directory:' \$(pwd)
|
|
echo ''
|
|
|
|
# Check ROCm environment
|
|
echo 'Checking ROCm environment...'
|
|
which hipcc
|
|
hipcc --version
|
|
echo ''
|
|
which rocm-smi
|
|
rocm-smi --showid
|
|
echo ''
|
|
|
|
# Build RinHash HIP library directly with hipcc
|
|
echo 'Building RinHash HIP library...'
|
|
mkdir -p build
|
|
echo 'Compiling rinhash.hip.cu...'
|
|
hipcc -c -O3 -fPIC rinhash.hip.cu -o build/rinhash.o
|
|
echo 'Compiling sha3-256.hip.cu...'
|
|
hipcc -c -O3 -fPIC sha3-256.hip.cu -o build/sha3-256.o
|
|
|
|
echo ''
|
|
echo 'Creating shared library...'
|
|
hipcc -shared -O3 \
|
|
build/rinhash.o build/sha3-256.o \
|
|
-o /workspaces/shared/repos/d-popov.com/mines/rin/miner/rocm-direct-output/gpu-libs/librinhash_hip.so \
|
|
-L/opt/rocm-6.4.3/lib -lamdhip64
|
|
|
|
echo 'Copying header files...'
|
|
cp *.cuh /workspaces/shared/repos/d-popov.com/mines/rin/miner/rocm-direct-output/gpu-libs/ 2>/dev/null || true
|
|
|
|
echo ''
|
|
echo 'Testing GPU library...'
|
|
if [ -f '/workspaces/shared/repos/d-popov.com/mines/rin/miner/rocm-direct-output/gpu-libs/librinhash_hip.so' ]; then
|
|
echo '✓ GPU library built successfully'
|
|
file /workspaces/shared/repos/d-popov.com/mines/rin/miner/rocm-direct-output/gpu-libs/librinhash_hip.so
|
|
echo 'Library size:'
|
|
du -h /workspaces/shared/repos/d-popov.com/mines/rin/miner/rocm-direct-output/gpu-libs/librinhash_hip.so
|
|
else
|
|
echo '✗ Failed to build GPU library'
|
|
exit 1
|
|
fi
|
|
|
|
echo ''
|
|
echo '==============================================='
|
|
echo ' GPU library build completed successfully!'
|
|
echo '==============================================='
|
|
"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "GPU library built successfully!"
|
|
echo ""
|
|
else
|
|
echo "GPU library build failed!"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Step 2: Creating integration files..."
|
|
echo ""
|
|
|
|
# Create integration documentation
|
|
cat > rocm-direct-output/integration/README.md << 'EOF'
|
|
# RinHash ROCm GPU Direct Integration
|
|
|
|
This build uses the existing `cpuminer-rocm-build` container to avoid dependency issues.
|
|
|
|
## Files Created
|
|
|
|
### GPU Libraries (`gpu-libs/`)
|
|
- `librinhash_hip.so` - Shared library for GPU acceleration
|
|
- `*.cuh` - Header files for GPU functions
|
|
|
|
## Usage
|
|
|
|
### 1. Copy GPU library to system
|
|
```bash
|
|
sudo cp gpu-libs/librinhash_hip.so /usr/local/lib/
|
|
sudo ldconfig
|
|
```
|
|
|
|
### 2. For cpuminer integration
|
|
Modify your cpuminer RinHash implementation to use GPU functions:
|
|
|
|
```c
|
|
#include <dlfcn.h>
|
|
|
|
// Load GPU library
|
|
void* gpu_lib = dlopen("librinhash_hip.so", RTLD_LAZY);
|
|
if (gpu_lib) {
|
|
// Use GPU functions
|
|
rinhash_cuda_function = dlsym(gpu_lib, "rinhash_cuda");
|
|
}
|
|
```
|
|
|
|
### 3. Build cpuminer with GPU support
|
|
```bash
|
|
./configure CFLAGS="-O3 -march=native"
|
|
make -j$(nproc)
|
|
```
|
|
|
|
## Testing
|
|
|
|
Test GPU support:
|
|
```bash
|
|
rocm-smi # Check GPU availability
|
|
```
|
|
|
|
Test library loading:
|
|
```bash
|
|
ldd librinhash_hip.so
|
|
```
|
|
EOF
|
|
|
|
# Create a test script
|
|
cat > rocm-direct-output/integration/test-gpu.sh << 'EOF'
|
|
#!/bin/bash
|
|
echo "Testing RinHash ROCm GPU Direct Build..."
|
|
|
|
echo "1. Testing GPU library:"
|
|
if [ -f "../gpu-libs/librinhash_hip.so" ]; then
|
|
echo "✓ GPU library found"
|
|
file ../gpu-libs/librinhash_hip.so
|
|
echo "Library size:"
|
|
du -h ../gpu-libs/librinhash_hip.so
|
|
echo "Library dependencies:"
|
|
ldd ../gpu-libs/librinhash_hip.so 2>/dev/null || echo "Could not check dependencies"
|
|
else
|
|
echo "✗ GPU library not found"
|
|
fi
|
|
|
|
echo ""
|
|
echo "2. Testing ROCm environment:"
|
|
if command -v rocm-smi &> /dev/null; then
|
|
echo "✓ ROCm runtime available"
|
|
rocm-smi --showid
|
|
rocm-smi --showmeminfo vram 2>/dev/null || echo "Could not get memory info"
|
|
else
|
|
echo "✗ ROCm runtime not available"
|
|
fi
|
|
|
|
echo ""
|
|
echo "3. Testing GPU compilation:"
|
|
if command -v hipcc &> /dev/null; then
|
|
echo "✓ HIP compiler available"
|
|
hipcc --version | head -3
|
|
else
|
|
echo "✗ HIP compiler not available"
|
|
fi
|
|
|
|
echo ""
|
|
echo "GPU test completed!"
|
|
EOF
|
|
|
|
chmod +x rocm-direct-output/integration/test-gpu.sh
|
|
|
|
echo "Integration files created!"
|
|
echo ""
|
|
|
|
# Final summary
|
|
echo "==============================================="
|
|
echo " ROCm GPU BUILD COMPLETED SUCCESSFULLY!"
|
|
echo "==============================================="
|
|
echo ""
|
|
echo "Files created in rocm-direct-output/:"
|
|
ls -la rocm-direct-output/
|
|
echo ""
|
|
echo "GPU libraries:"
|
|
ls -la rocm-direct-output/gpu-libs/ 2>/dev/null || echo "No GPU libraries"
|
|
echo ""
|
|
echo "Integration files:"
|
|
ls -la rocm-direct-output/integration/
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Test the build:"
|
|
echo " ./rocm-direct-output/integration/test-gpu.sh"
|
|
echo ""
|
|
echo " 2. Copy GPU library to system:"
|
|
echo " sudo cp rocm-direct-output/gpu-libs/librinhash_hip.so /usr/local/lib/"
|
|
echo " sudo ldconfig"
|
|
echo ""
|
|
echo " 3. Integrate with cpuminer:"
|
|
echo " See rocm-direct-output/integration/README.md"
|
|
echo ""
|
|
|
|
echo "ROCm GPU direct build completed successfully!"
|