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

Enable conditional build #4

Merged
merged 1 commit into from
Mar 16, 2018
Merged
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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated files
build/

# Object files
*.o
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects
*.dll
*.so
*.so.*
*.dylib
71 changes: 43 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ SRC ?= ./src
OUT ?= ./build

CFLAGS = -Os -fPIC -g
LDFLAGS = -L$(OPENCL_LIB) -lpthread -lOpenCL
LDFLAGS = -lpthread

# FIXME: avoid hardcoded architecture flags. We might support advanced SIMD
# instructions for Intel and Arm later.
CFLAGS += -msse2

ifneq ("$(DISABLE_GPU)","1")
CFLAGS += \
-DBUILD_OPENCL \
-I$(OPENCL_PATH)/include
LDFLAGS += -L$(OPENCL_LIB) -lOpenCL
endif

ifneq ("$(DISABLE_JNI)","1")
CFLAGS += \
-I$(OPENJDK_PATH)/include \
-I$(OPENJDK_PATH)/include/linux
endif

TESTS = \
trinary \
curl \
pow_sse \
pow_sse

ifneq ("$(DISABLE_GPU)","1")
TESTS += \
pow_cl
endif

TESTS := $(addprefix $(OUT)/test_, $(TESTS))

LIBS = libdcurl.so
Expand All @@ -23,31 +45,34 @@ OBJS = \
constants.o \
trinary/trinary.o \
dcurl.o \
pow_sse.o \
pow_sse.o

ifneq ("$(DISABLE_GPU)","1")
OBJS += \
pow_cl.o \
clcontext.o
OBJS := $(addprefix $(OUT)/, $(OBJS))
deps := $(OBJS:%.o=%.o.d)
endif

# Control the build verbosity
ifeq ("$(VERBOSE)","1")
Q :=
VECHO = @true
else
Q := @
VECHO = @printf
ifneq ("$(DISABLE_JNI)","1")
OBJS += \
jni/iri-pearldiver-exlib.o
endif

OBJS := $(addprefix $(OUT)/, $(OBJS))
deps := $(OBJS:%.o=%.o.d)

SUBDIRS = \
hash \
trinary
trinary \
jni
SHELL_HACK := $(shell mkdir -p $(OUT))
SHELL_HACK := $(shell mkdir -p $(addprefix $(OUT)/,$(SUBDIRS)))

$(OUT)/test_%.o: test/test_%.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF $@.d $<

$(OUT)/jni/%.o: jni/%.c
$(OUT)/trinary/%.o: $(SRC)/trinary/%.c
$(OUT)/hash/%.o: $(SRC)/hash/%.c
$(OUT)/%.o: $(SRC)/%.c
Expand All @@ -56,22 +81,11 @@ $(OUT)/%.o: $(SRC)/%.c

$(OUT)/test_%: $(OUT)/test_%.o $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q) gcc -I$(OPENCL_PATH)/include -o $@ $^ $(LDFLAGS)

$(OUT)/libdcurl.so: ./jni/iri-pearldiver-exlib.c $(OBJS)
gcc -fPIC -msse2 -shared \
-I$(OPENJDK_PATH)/include -I$(OPENJDK_PATH)/include/linux \
-I$(OPENCL_PATH)/include -o $@ $^ $(LDFLAGS)

PASS_COLOR = \e[32;01m
NO_COLOR = \e[0m
$(Q)$(CC) -o $@ $^ $(LDFLAGS)

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PRINTF = printf
else
PRINTF = env printf
endif
$(OUT)/libdcurl.so: $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS)

$(OUT)/test_%.done: $(OUT)/test_%
$(Q)./$< && $(PRINTF) "*** $< *** $(PASS_COLOR)[ Verified ]$(NO_COLOR)\n"
Expand All @@ -80,4 +94,5 @@ check: $(addsuffix .done, $(TESTS))
clean:
$(RM) -r $(OUT)

include mk/common.mk
-include $(deps)
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ Reference Implementation (IRI).
* Only one GPU can be facilitated with dcurl at the moment.

# Build
* Build a shared library for IRI, placed in ```build```

```$ make```
* Build a shared library for IRI, generating object files in directory `build`
```shell
$ make
```
Alternatively, you can specify conditional build as following:
```shell
$ make DISABLE_GPU=1 DISABLE_JNI=1
```

# Test
* Make a test
Expand Down
18 changes: 18 additions & 0 deletions mk/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Control the build verbosity
ifeq ("$(VERBOSE)","1")
Q :=
VECHO = @true
else
Q := @
VECHO = @printf
endif

PASS_COLOR = \e[32;01m
NO_COLOR = \e[0m

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PRINTF = printf
else
PRINTF = env printf
endif
6 changes: 6 additions & 0 deletions src/dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ void dcurl_init(int max_cpu_thread, int max_gpu_thread)
pthread_mutex_init(&mtx, NULL);
sem_init(&notify, 0, 0);
pow_sse_init(MAX_CPU_THREAD);
#if defined(ENABLE_OPENCL)
pwork_ctx_init(MAX_GPU_THREAD);
#endif
}

void dcurl_destroy()
{
free(cpu_mutex_id);
free(gpu_mutex_id);
pow_sse_destroy();
#if defined(ENABLE_OPENCL)
pwork_ctx_destroy(MAX_GPU_THREAD);
#endif
}

Trytes_t *dcurl_entry(Trytes_t *trytes, int mwm)
Expand Down Expand Up @@ -107,9 +111,11 @@ Trytes_t *dcurl_entry(Trytes_t *trytes, int mwm)
case 1:
ret_trytes = PowSSE(trytes, mwm, selected_mutex_id);
break;
#if defined(ENABLE_OPENCL)
case 2:
ret_trytes = PowCL(trytes, mwm, selected_mutex_id);
break;
#endif
default:
printf("error produced\n");
exit(0);
Expand Down