Skip to content

Commit f8f0260

Browse files
author
limingming
committed
gpu
1 parent 75e274b commit f8f0260

File tree

4 files changed

+687
-6
lines changed

4 files changed

+687
-6
lines changed

BytomPoW.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern"C" {
1010
#include <assert.h>
1111
#include <vector>
1212
#include <stdint.h>
13-
13+
#include "matrixMulCUBLAS.h"
1414
#define FNV(v1,v2) int32_t( ((v1)*FNV_PRIME) ^ (v2) )
1515
const int FNV_PRIME = 0x01000193;
1616

@@ -66,7 +66,7 @@ struct Mat256x256i8 {
6666
copyFrom_helper(ltcMem, 1);
6767
}
6868

69-
void mul(const Mat256x256i8& a, const Mat256x256i8& b) {
69+
void mulcpu(const Mat256x256i8& a, const Mat256x256i8& b) {
7070
double *ma = (double *)calloc(256*256, sizeof(double));
7171
double *mb = (double *)calloc(256*256, sizeof(double));
7272
double *mc = (double *)calloc(256*256, sizeof(double));
@@ -91,7 +91,9 @@ struct Mat256x256i8 {
9191
free(mb);
9292
free(mc);
9393
}
94-
94+
void mul(const Mat256x256i8& a, const Mat256x256i8& b) {
95+
bytomcall(1,NULL,a.d,b.d);
96+
}
9597
void add(Mat256x256i8& a, Mat256x256i8& b) {
9698
for(int i=0; i<256; i++) {
9799
for(int j=0; j<256; j++) {

Makefile

Lines changed: 287 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,289 @@
1-
all:
2-
g++ byte_order.c sha3.c test_BytomPoW.cpp -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas -lpthread -O3
1+
################################################################################
2+
#
3+
# Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
4+
#
5+
# NOTICE TO USER:
6+
#
7+
# This source code is subject to NVIDIA ownership rights under U.S. and
8+
# international Copyright laws.
9+
#
10+
# NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
11+
# CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
12+
# IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
13+
# REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
14+
# MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
15+
# IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
16+
# OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
17+
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
18+
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
19+
# OR PERFORMANCE OF THIS SOURCE CODE.
20+
#
21+
# U.S. Government End Users. This source code is a "commercial item" as
22+
# that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
23+
# "commercial computer software" and "commercial computer software
24+
# documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
25+
# and is provided to the U.S. Government only as a commercial end item.
26+
# Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
27+
# 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
28+
# source code with only those rights set forth herein.
29+
#
30+
################################################################################
31+
#
32+
# Makefile project only supported on Mac OS X and Linux Platforms)
33+
#
34+
################################################################################
35+
36+
# Location of the CUDA Toolkit
37+
CUDA_PATH ?= /usr/local/cuda-9.1
38+
39+
##############################
40+
# start deprecated interface #
41+
##############################
42+
ifeq ($(x86_64),1)
43+
$(info WARNING - x86_64 variable has been deprecated)
44+
$(info WARNING - please use TARGET_ARCH=x86_64 instead)
45+
TARGET_ARCH ?= x86_64
46+
endif
47+
ifeq ($(ARMv7),1)
48+
$(info WARNING - ARMv7 variable has been deprecated)
49+
$(info WARNING - please use TARGET_ARCH=armv7l instead)
50+
TARGET_ARCH ?= armv7l
51+
endif
52+
ifeq ($(aarch64),1)
53+
$(info WARNING - aarch64 variable has been deprecated)
54+
$(info WARNING - please use TARGET_ARCH=aarch64 instead)
55+
TARGET_ARCH ?= aarch64
56+
endif
57+
ifeq ($(ppc64le),1)
58+
$(info WARNING - ppc64le variable has been deprecated)
59+
$(info WARNING - please use TARGET_ARCH=ppc64le instead)
60+
TARGET_ARCH ?= ppc64le
61+
endif
62+
ifneq ($(GCC),)
63+
$(info WARNING - GCC variable has been deprecated)
64+
$(info WARNING - please use HOST_COMPILER=$(GCC) instead)
65+
HOST_COMPILER ?= $(GCC)
66+
endif
67+
ifneq ($(abi),)
68+
$(error ERROR - abi variable has been removed)
69+
endif
70+
############################
71+
# end deprecated interface #
72+
############################
73+
74+
# architecture
75+
HOST_ARCH := $(shell uname -m)
76+
TARGET_ARCH ?= $(HOST_ARCH)
77+
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le armv7l))
78+
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
79+
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le))
80+
TARGET_SIZE := 64
81+
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
82+
TARGET_SIZE := 32
83+
endif
84+
else
85+
TARGET_SIZE := $(shell getconf LONG_BIT)
86+
endif
87+
else
88+
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
89+
endif
90+
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
91+
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-ppc64le))
92+
$(error ERROR - cross compiling from $(HOST_ARCH) to $(TARGET_ARCH) is not supported!)
93+
endif
94+
endif
95+
96+
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
97+
ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_SIZE),aarch64-aarch64-32)
98+
TARGET_ARCH = armv7l
99+
endif
100+
101+
# operating system
102+
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
103+
TARGET_OS ?= $(HOST_OS)
104+
ifeq (,$(filter $(TARGET_OS),linux darwin qnx android))
105+
$(error ERROR - unsupported value $(TARGET_OS) for TARGET_OS!)
106+
endif
107+
108+
# host compiler
109+
ifeq ($(TARGET_OS),darwin)
110+
ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
111+
HOST_COMPILER ?= clang++
112+
endif
113+
else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
114+
ifeq ($(HOST_ARCH)-$(TARGET_ARCH),x86_64-armv7l)
115+
ifeq ($(TARGET_OS),linux)
116+
HOST_COMPILER ?= arm-linux-gnueabihf-g++
117+
else ifeq ($(TARGET_OS),qnx)
118+
ifeq ($(QNX_HOST),)
119+
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
120+
endif
121+
ifeq ($(QNX_TARGET),)
122+
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
123+
endif
124+
export QNX_HOST
125+
export QNX_TARGET
126+
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
127+
else ifeq ($(TARGET_OS),android)
128+
HOST_COMPILER ?= arm-linux-androideabi-g++
129+
endif
130+
else ifeq ($(TARGET_ARCH),aarch64)
131+
ifeq ($(TARGET_OS), linux)
132+
HOST_COMPILER ?= aarch64-linux-gnu-g++
133+
else ifeq ($(TARGET_OS),qnx)
134+
ifeq ($(QNX_HOST),)
135+
$(error ERROR - QNX_HOST must be passed to the QNX host toolchain)
136+
endif
137+
ifeq ($(QNX_TARGET),)
138+
$(error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
139+
endif
140+
export QNX_HOST
141+
export QNX_TARGET
142+
HOST_COMPILER ?= $(QNX_HOST)/usr/bin/aarch64-unknown-nto-qnx7.0.0-g++
143+
else ifeq ($(TARGET_OS), android)
144+
HOST_COMPILER ?= aarch64-linux-android-g++
145+
endif
146+
else ifeq ($(TARGET_ARCH),ppc64le)
147+
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
148+
endif
149+
endif
150+
HOST_COMPILER ?= g++
151+
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(HOST_COMPILER)
152+
153+
# internal flags
154+
NVCCFLAGS := -m${TARGET_SIZE}
155+
CCFLAGS :=
156+
LDFLAGS :=
157+
158+
# build flags
159+
ifeq ($(TARGET_OS),darwin)
160+
LDFLAGS += -rpath $(CUDA_PATH)/lib
161+
CCFLAGS += -arch $(HOST_ARCH)
162+
else ifeq ($(HOST_ARCH)-$(TARGET_ARCH)-$(TARGET_OS),x86_64-armv7l-linux)
163+
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
164+
CCFLAGS += -mfloat-abi=hard
165+
else ifeq ($(TARGET_OS),android)
166+
LDFLAGS += -pie
167+
CCFLAGS += -fpie -fpic -fexceptions
168+
endif
169+
170+
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
171+
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
172+
ifneq ($(TARGET_FS),)
173+
GCCVERSIONLTEQ46 := $(shell expr `$(HOST_COMPILER) -dumpversion` \<= 4.6)
174+
ifeq ($(GCCVERSIONLTEQ46),1)
175+
CCFLAGS += --sysroot=$(TARGET_FS)
176+
endif
177+
LDFLAGS += --sysroot=$(TARGET_FS)
178+
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
179+
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
180+
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
181+
endif
182+
endif
183+
endif
184+
185+
ifeq ($(TARGET_OS),qnx)
186+
CCFLAGS += -DWIN_INTERFACE_CUSTOM
187+
LDFLAGS += -lsocket
188+
endif
189+
190+
# Install directory of different arch
191+
CUDA_INSTALL_TARGET_DIR :=
192+
ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
193+
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
194+
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
195+
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
196+
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
197+
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
198+
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
199+
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
200+
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-qnx)
201+
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
202+
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-qnx)
203+
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
204+
else ifeq ($(TARGET_ARCH),ppc64le)
205+
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
206+
endif
207+
208+
# Debug build flags
209+
ifeq ($(dbg),1)
210+
NVCCFLAGS += -g -G
211+
BUILD_TYPE := debug
212+
else
213+
BUILD_TYPE := release
214+
endif
215+
216+
ALL_CCFLAGS :=
217+
ALL_CCFLAGS += $(NVCCFLAGS)
218+
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
219+
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
220+
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))
221+
222+
SAMPLE_ENABLED := 1
223+
224+
ALL_LDFLAGS :=
225+
ALL_LDFLAGS += $(ALL_CCFLAGS)
226+
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
227+
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))
228+
229+
# Common includes and paths for CUDA
230+
INCLUDES := -I../../common/inc
231+
LIBRARIES :=
232+
233+
################################################################################
234+
235+
# Gencode arguments
236+
SMS ?= 30 35 37 50 52 60 61 70
237+
238+
ifeq ($(SMS),)
239+
$(info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
240+
SAMPLE_ENABLED := 0
241+
endif
242+
243+
ifeq ($(GENCODE_FLAGS),)
244+
# Generate SASS code for each SM architecture listed in $(SMS)
245+
$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))
246+
247+
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
248+
HIGHEST_SM := $(lastword $(sort $(SMS)))
249+
ifneq ($(HIGHEST_SM),)
250+
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
251+
endif
252+
endif
253+
254+
LIBRARIES += -lcublas -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas -lpthread -O3
255+
256+
ifeq ($(SAMPLE_ENABLED),0)
257+
EXEC ?= @echo "[@]"
258+
endif
259+
260+
################################################################################
261+
262+
# Target rules
263+
all: build
264+
265+
build: test_BytomPoW
266+
267+
check.deps:
268+
ifeq ($(SAMPLE_ENABLED),0)
269+
@echo "Sample will be waived due to the above missing dependencies"
270+
else
271+
@echo "Sample is ready - all dependencies have been met"
272+
endif
273+
274+
test_BytomPoW.o:byte_order.c sha3.c test_BytomPoW.cpp
275+
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
276+
277+
test_BytomPoW: test_BytomPoW.o
278+
$(EXEC) $(NVCC) $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)
279+
$(EXEC) mkdir -p ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
280+
$(EXEC) cp $@ ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
281+
282+
run: build
283+
$(EXEC) ./test_BytomPoW
284+
3285
clean:
4-
rm a.out
286+
rm -f test_BytomPoW test_BytomPoW.o
287+
rm -rf ../../bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)/test_BytomPoW
5288

289+
clobber: clean

Makefilebak

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all:
2+
g++ byte_order.c sha3.c test_BytomPoW.cpp -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas -lpthread -O3
3+
clean:
4+
rm a.out
5+

0 commit comments

Comments
 (0)