Skip to content

Commit 705b997

Browse files
author
brichard19
committed
Linux conditional build for OpenCL and CUDA
1 parent d665b4a commit 705b997

File tree

9 files changed

+111
-23
lines changed

9 files changed

+111
-23
lines changed

CLKeySearchDevice/CLKeySearchDevice.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <cmath>
12
#include "Logger.h"
23
#include "util.h"
34
#include "CLKeySearchDevice.h"
@@ -86,9 +87,9 @@ CLKeySearchDevice::~CLKeySearchDevice()
8687

8788
uint64_t CLKeySearchDevice::getOptimalBloomFilterMask(double p, size_t n)
8889
{
89-
double m = 3.6 * ceil((n * log(p)) / log(1 / pow(2, log(2))));
90+
double m = 3.6 * ceil((n * std::log(p)) / std::log(1 / std::pow(2, std::log(2))));
9091

91-
unsigned int bits = ceil(log(m) / log(2));
92+
unsigned int bits = std::ceil(std::log(m) / std::log(2));
9293

9394
return ((uint64_t)1 << bits) - 1;
9495
}

CLKeySearchDevice/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
NAME=CLKeySearchDevice
2+
CPPSRC:=$(wildcard *.cpp)
3+
CUSRC:=$(wildcard *.cu)
4+
5+
all:
6+
for file in ${CPPSRC} ; do\
7+
${CXX} -c $$file ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS};\
8+
done
9+
10+
ar rvs ${LIBDIR}/lib$(NAME).a *.o
11+
12+
clean:
13+
rm -f *.o *.cu.o
14+
rm -f *.a

CudaKeySearchDevice/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
NAME=CudaKeySearchDevice
2+
CPPSRC:=$(wildcard *.cpp)
3+
CUSRC:=$(wildcard *.cu)
4+
5+
all: cuda
6+
7+
cuda:
8+
for file in ${CPPSRC} ; do\
9+
${CXX} -c $$file ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS};\
10+
done
11+
12+
for file in ${CUSRC} ; do\
13+
${NVCC} -c $$file -o $$file".o" ${NVCCFLAGS} -rdc=true ${INCLUDE} -I${CUDA_INCLUDE} -I${CUDA_MATH};\
14+
done
15+
16+
${NVCC} -dlink -o cuda_libs.o *.cu.o -lcudadevrt -lcudart
17+
18+
ar rvs ${LIBDIR}/lib$(NAME).a *.o
19+
20+
clean:
21+
rm -f *.o *.cu.o
22+
rm -f *.a

KeyFinder/DeviceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#endif
66

77
#ifdef BUILD_OPENCL
8-
#include "clUtil.h"
8+
#include "clutil.h"
99
#endif
1010

1111
std::vector<DeviceManager::DeviceInfo> DeviceManager::getDevices()

KeyFinder/DeviceManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _DEVICE_MANAGER_H
22
#define _DEVICE_MANAGER_H
33

4+
#include <stdint.h>
5+
#include <string>
46
#include <vector>
57

68
namespace DeviceManager {

KeyFinder/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
CPPSRC:=$(wildcard *.cpp)
22

33
all:
4-
${CXX} -o KeyFinder.bin ${CPPSRC} ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS} ${LIBS} -L${CUDA_LIB} -lkeyfinder -laddressutil -lsecp256k1 -lcryptoutil -lsecp256k1 -lcudadevicecontext -lcudautil -llogger -lutil -lcudadevrt -lcudart -lcmdparse
4+
ifeq ($(BUILD_CUDA), 1)
5+
${CXX} -DBUILD_CUDA -o cuKeyFinder.bin ${CPPSRC} ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS} ${LIBS} -L${CUDA_LIB} -lkeyfinder -laddressutil -lsecp256k1 -lcryptoutil -lsecp256k1 -lcudautil -llogger -lutil -lCudaKeySearchDevice -lcudadevrt -lcudart -lcmdparse
56
mkdir -p $(BINDIR)
6-
cp KeyFinder.bin $(BINDIR)/BitCrack
7+
cp cuKeyFinder.bin $(BINDIR)/cuBitCrack
8+
endif
9+
ifeq ($(BUILD_OPENCL),1)
10+
${CXX} -DBUILD_OPENCL -o clKeyFinder.bin ${CPPSRC} ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS} ${LIBS} -L${OPENCL_LIB} -lkeyfinder -laddressutil -lsecp256k1 -lcryptoutil -lsecp256k1 -lCLKeySearchDevice -lclutil -lOpenCL -llogger -lutil -lcmdparse
11+
mkdir -p $(BINDIR)
12+
cp clKeyFinder.bin $(BINDIR)/clBitCrack
13+
endif
714

815
clean:
9-
rm -rf KeyFinder.bin
16+
rm -rf cuKeyFinder.bin
17+
rm -rf clKeyFinder.bin

KeyFinderLib/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
NAME=keyfinder
22
CPPSRC:=$(wildcard *.cpp)
3-
CUSRC:=$(wildcard *.cu)
43

54
all: cuda
65

@@ -9,12 +8,6 @@ cuda:
98
${CXX} -c $$file ${INCLUDE} -I${CUDA_INCLUDE} ${CXXFLAGS};\
109
done
1110

12-
for file in ${CUSRC} ; do\
13-
${NVCC} -c $$file -o $$file".o" ${NVCCFLAGS} -rdc=true ${INCLUDE} -I${CUDA_INCLUDE} -I${CUDA_MATH};\
14-
done
15-
16-
${NVCC} -dlink -o cuda_libs.o *.cu.o -lcudadevrt -lcudart
17-
1811
ar rvs ${LIBDIR}/lib$(NAME).a *.o
1912

2013
clean:

Makefile

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
CUR_DIR=$(shell pwd)
3-
DIRS=util AddressUtil CmdParse CryptoUtil KeyFinderLib cudaDeviceContext cudaMath cudaUtil secp256k1lib Logger
3+
DIRS=util AddressUtil CmdParse CryptoUtil KeyFinderLib CLKeySearchDevice CudaKeySearchDevice cudaMath clUtil cudaUtil secp256k1lib Logger
44

55
INCLUDE = $(foreach d, $(DIRS), -I$(CUR_DIR)/$d)
66

@@ -10,17 +10,20 @@ LIBS+=-L$(LIBDIR)
1010

1111
# C++ options
1212
CXX=g++
13-
CXXFLAGS=-O2
13+
CXXFLAGS=-O2 -std=c++11
1414

1515
# CUDA variables
1616
COMPUTE_CAP=30
1717
NVCC=nvcc
18-
NVCCFLAGS=-gencode=arch=compute_${COMPUTE_CAP},code=\"sm_${COMPUTE_CAP}\" -Xptxas="-v" -Xcompiler "${CXXFLAGS}"
18+
NVCCFLAGS=-std=c++11 -gencode=arch=compute_${COMPUTE_CAP},code=\"sm_${COMPUTE_CAP}\" -Xptxas="-v" -Xcompiler "${CXXFLAGS}"
1919
CUDA_HOME=/usr/local/cuda-9.2
2020
CUDA_LIB=${CUDA_HOME}/lib64
2121
CUDA_INCLUDE=${CUDA_HOME}/include
2222
CUDA_MATH=$(CUR_DIR)/cudaMath
2323

24+
# OpenCL variables
25+
OPENCL_LIB=${CUDA_LIB}
26+
OPENCL_INCLUDE=${CUDA_INCLUDE}
2427

2528

2629
export INCLUDE
@@ -34,8 +37,28 @@ export CXXFLAGS
3437
export CUDA_LIB
3538
export CUDA_INCLUDE
3639
export CUDA_MATH
40+
export OPENCL_LIB
41+
export OPENCL_INCLUDE
42+
export BUILD_OPENCL
43+
export BUILD_CUDA
3744

38-
all: dir_addressutil dir_cmdparse dir_cryptoutil dir_keyfinderlib dir_keyfinder dir_cudadevicecontext dir_cudautil dir_secp256k1lib dir_util dir_cudainfo dir_logger
45+
TARGETS=dir_addressutil dir_cmdparse dir_cryptoutil dir_keyfinderlib dir_keyfinder dir_cudautil dir_secp256k1lib dir_util dir_cudainfo dir_logger
46+
47+
ifeq ($(BUILD_CUDA),1)
48+
TARGETS:=${TARGETS} dir_cudaKeySearchDevice dir_cudautil
49+
endif
50+
51+
ifeq ($(BUILD_OPENCL),1)
52+
TARGETS:=${TARGETS} dir_clKeySearchDevice dir_clutil
53+
endif
54+
55+
all: ${TARGETS}
56+
57+
dir_cudaKeySearchDevice: dir_keyfinderlib dir_cudautil dir_logger
58+
make --directory CudaKeySearchDevice
59+
60+
dir_clKeySearchDevice: dir_keyfinderlib dir_clutil dir_logger
61+
make --directory CLKeySearchDevice
3962

4063
dir_addressutil: dir_util dir_secp256k1lib dir_cryptoutil
4164
make --directory AddressUtil
@@ -46,18 +69,28 @@ dir_cmdparse:
4669
dir_cryptoutil:
4770
make --directory CryptoUtil
4871

49-
dir_keyfinderlib: dir_util dir_secp256k1lib dir_cryptoutil dir_addressutil dir_cudautil dir_cudadevicecontext dir_cudautil dir_logger
72+
dir_keyfinderlib: dir_util dir_secp256k1lib dir_cryptoutil dir_addressutil dir_logger
5073
make --directory KeyFinderLib
5174

52-
dir_keyfinder: dir_keyfinderlib
53-
make --directory KeyFinder
75+
KEYFINDER_DEPS=dir_keyfinderlib
76+
77+
ifeq ($(BUILD_CUDA), 1)
78+
KEYFINDER_DEPS:=$(KEYFINDER_DEPS) dir_cudaKeySearchDevice
79+
endif
5480

55-
dir_cudadevicecontext:
56-
make --directory cudaDeviceContext
81+
ifeq ($(BUILD_OPENCL),1)
82+
KEYFINDER_DEPS:=$(KEYFINDER_DEPS) dir_clKeySearchDevice
83+
endif
84+
85+
dir_keyfinder: $(KEYFINDER_DEPS)
86+
make --directory KeyFinder
5787

5888
dir_cudautil:
5989
make --directory cudaUtil
6090

91+
dir_clutil:
92+
make --directory clUtil
93+
6194
dir_secp256k1lib: dir_cryptoutil
6295
make --directory secp256k1lib
6396

@@ -76,12 +109,14 @@ clean:
76109
make --directory CryptoUtil clean
77110
make --directory KeyFinderLib clean
78111
make --directory KeyFinder clean
79-
make --directory cudaDeviceContext clean
80112
make --directory cudaUtil clean
81113
make --directory secp256k1lib clean
82114
make --directory util clean
83115
make --directory cudaInfo clean
84116
make --directory Logger clean
117+
make --directory clUtil clean
118+
make --directory CLKeySearchDevice clean
119+
make --directory CudaKeySearchDevice clean
85120

86121
rm -rf ${LIBDIR}
87122
rm -rf ${BINDIR}

clUtil/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
NAME=clutil
2+
SRC=$(wildcard *.cpp)
3+
OBJS=$(SRC:.cpp=.o)
4+
5+
all: ${SRC}
6+
for file in ${SRC} ; do\
7+
${CXX} -c $$file ${INCLUDE} -I${OPENCL_INCLUDE} ${CXXFLAGS};\
8+
done
9+
mkdir -p ${LIBDIR}
10+
ar rvs ${LIBDIR}/lib$(NAME).a ${OBJS}
11+
12+
clean:
13+
rm -rf *.o

0 commit comments

Comments
 (0)