Skip to content

Commit

Permalink
Merge pull request #112 from marktwtn/build-without-CPU
Browse files Browse the repository at this point in the history
Enable building FPGA or GPU platform independently
  • Loading branch information
jserv committed Feb 20, 2019
2 parents e24d70f + 64a5b0c commit e89ed14
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
39 changes: 29 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,29 @@ include mk/cpu-features.mk
# Handle git submodule
include mk/submodule.mk

# Assign the hardware to CPU if no hardware is specified
PLATFORMS := $(BUILD_AVX) $(BUILD_SSE) $(BUILD_GENERIC) $(BUILD_GPU) $(BUILD_FPGA_ACCEL)
ENABLE_PLATFORMS := $(findstring 1,$(PLATFORMS))
ifneq ("$(ENABLE_PLATFORMS)","1")
ifeq ("$(call cpu_feature,AVX)","1")
BUILD_AVX = 1
else ifeq ("$(call cpu_feature,SSE)","1")
BUILD_SSE = 1
else
BUILD_GENERIC = 1
endif
endif


ifeq ("$(BUILD_AVX)","1")
CFLAGS += -mavx -DENABLE_AVX
ifeq ("$(call cpu_feature,AVX2)","1")
CFLAGS += -mavx2
endif
else
BUILD_SSE := $(call cpu_feature,SSE)
ifeq ("$(BUILD_SSE)","1")
else ifeq ("$(BUILD_SSE)","1")
CFLAGS += -msse2 -DENABLE_SSE
endif
else ifeq ("$(BUILD_GENERIC)","1")
CFLAGS += -DENABLE_GENERIC
endif

ifeq ("$(BUILD_GPU)","1")
Expand Down Expand Up @@ -87,13 +100,11 @@ OBJS = \

ifeq ("$(BUILD_AVX)","1")
OBJS += pow_avx.o
else
ifeq ("$(BUILD_SSE)","1")
else ifeq ("$(BUILD_SSE)","1")
OBJS += pow_sse.o
else
else ifeq ("$(BUILD_GENERIC)","1")
OBJS += pow_c.o
endif
endif

ifeq ("$(BUILD_GPU)","1")
OBJS += \
Expand All @@ -118,6 +129,14 @@ endif

OBJS := $(addprefix $(OUT)/, $(OBJS))

# Add the libtuv PIC(position independent code) library into the object files
# if the specified hardware is CPU
CPU_PLATFORMS := $(BUILD_AVX) $(BUILD_SSE) $(BUILD_GENERIC)
ENABLE_CPU_PLATFORMS := $(findstring 1,$(CPU_PLATFORMS))
ifeq ("$(ENABLE_CPU_PLATFORMS)","1")
OBJS += $(LIBTUV_LIBRARY)
endif

$(OUT)/test-%.o: tests/test-%.c $(LIBTUV_PATH)/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -I $(SRC) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $<
Expand All @@ -126,11 +145,11 @@ $(OUT)/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBTUV_LIBRARY)
$(OUT)/test-%: $(OUT)/test-%.o $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)

$(OUT)/libdcurl.so: $(OBJS) $(LIBTUV_LIBRARY)
$(OUT)/libdcurl.so: $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS)

Expand Down
11 changes: 8 additions & 3 deletions docs/build-n-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
## Build Instructions
* dcurl allows various combinations of build configurations to fit final use scenarios.
* You can execute `make config` and then edit file `build/local.mk` for custom build options.
- ``BUILD_AVX``: build Intel AVX-accelerated Curl backend.
- ``BUILD_GPU``: build OpenCL-based GPU accelerations.
- ``BUILD_AVX``: build the Intel AVX-accelerated Curl backend.
- ``BUILD_SSE``: build the Intel SSE-accelerated Curl backend.
- ``BUILD_GPU``: build the OpenCL-based GPU accelerations.
- ``BUILD_FPGA_ACCEL``: build the interface interacting with the Cyclone V FPGA based accelerator. Verified on DE10-nano board and Arrow SoCKit board.
- ``BUILD_JNI``: build a shared library for IRI. The build system would generate JNI header file
downloading from [latest JAVA source](https://github.com/DLTcollab/iri).
- ``BUILD_COMPAT``: build extra cCurl compatible interface.
- ``BUILD_FPGA_ACCEL``: build the interface interacting with the Cyclone V FPGA based accelerator. Verified on DE10-nano board and Arrow SoCKit board.
- ``BUILD_STAT``: show the statistics of the PoW information.
- ``BUILD_DEBUG``: dump verbose messages internally.
* Alternatively, you can specify conditional build as following:
```shell
$ make BUILD_GPU=0 BUILD_JNI=1 BUILD_AVX=1
```

## Fallback Build Instructions
* These instructions do not appear in the file `build/local.mk`.
- ``BUILD_GENERIC``: build the generic CPU Curl backend without acceleration.

## Testing and Validation
* Test with GPU
```shell
Expand Down
9 changes: 6 additions & 3 deletions mk/defs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ BUILD_DEBUG ?= 0
# Build AVX backend or not
BUILD_AVX ?= 0

# Build SSE backend or not
BUILD_SSE ?= 0

# Build OpenCL backend or not
BUILD_GPU ?= 0

# Build FPGA backend or not
BUILD_FPGA_ACCEL ?= 0

# Build JNI glue as the bridge between dcurl and IRI
BUILD_JNI ?= 0

# Build cCurl compatible interface
BUILD_COMPAT ?= 0

# Build FPGA backend or not
BUILD_FPGA_ACCEL ?= 0

# Show the PoW-related statistic messages or not
BUILD_STAT ?= 0
6 changes: 3 additions & 3 deletions src/dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "pow_avx.h"
#elif defined(ENABLE_SSE)
#include "pow_sse.h"
#else
#elif defined(ENABLE_GENERIC)
#include "pow_c.h"
#endif

Expand All @@ -46,7 +46,7 @@ LIST_HEAD(IMPL_LIST);
extern ImplContext PoWAVX_Context;
#elif defined(ENABLE_SSE)
extern ImplContext PoWSSE_Context;
#else
#elif defined(ENABLE_GENERIC)
extern ImplContext PoWC_Context;
#endif

Expand All @@ -66,7 +66,7 @@ bool dcurl_init()
ret &= registerImplContext(&PoWAVX_Context);
#elif defined(ENABLE_SSE)
ret &= registerImplContext(&PoWSSE_Context);
#else
#elif defined(ENABLE_GENERIC)
ret &= registerImplContext(&PoWC_Context);
#endif

Expand Down
7 changes: 4 additions & 3 deletions tests/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
#include "pow_avx.h"
#elif defined(ENABLE_SSE)
#include "pow_sse.h"
#elif defined(ENABLE_FPGA_ACCEL)
#include "pow_fpga_accel.h"
#else
#elif defined(ENABLE_GENERIC)
#include "pow_c.h"
#endif

#if defined(ENABLE_OPENCL)
#include "pow_cl.h"
#endif
#if defined(ENABLE_FPGA_ACCEL)
#include "pow_fpga_accel.h"
#endif

#include <stdint.h>
#include <stdlib.h>
Expand Down
6 changes: 3 additions & 3 deletions tests/test-pow.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extern ImplContext PoWAVX_Context;
#elif defined(ENABLE_SSE)
extern ImplContext PoWSSE_Context;
#else
#elif defined(ENABLE_GENERIC)
extern ImplContext PoWC_Context;
#endif

Expand All @@ -26,7 +26,7 @@ const char *description[] = {
"CPU - AVX",
#elif defined(ENABLE_SSE)
"CPU - SSE",
#else
#elif defined(ENABLE_GENERIC)
"CPU - pure C",
#endif

Expand Down Expand Up @@ -114,7 +114,7 @@ int main()
PoWAVX_Context,
#elif defined(ENABLE_SSE)
PoWSSE_Context,
#else
#elif defined(ENABLE_GENERIC)
PoWC_Context,
#endif

Expand Down

0 comments on commit e89ed14

Please sign in to comment.