Skip to content

Commit

Permalink
Merge pull request #132 from DLTcollab/develop
Browse files Browse the repository at this point in the history
Pre-release v0.2.0
  • Loading branch information
Wu Yu Wei committed Mar 28, 2019
2 parents a379862 + e38e1c9 commit 778dcdb
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 338 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2018 dcurl Developers.
Copyright (C) 2018-2019 BiiLabs Co., Ltd. and Contributors.
Copyright (C) 2017 IOTA AS, IOTA Foundation and Developers.
Copyright (C) 2016 Shinya Yagyu.

Expand Down
27 changes: 6 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ else ifeq ("$(BUILD_GENERIC)","1")
CFLAGS += -DENABLE_GENERIC
endif

ifeq ("$(call cpu_feature,SSE4_2)","1")
CFLAGS += -msse4.2
endif

ifeq ("$(BUILD_GPU)","1")
include mk/opencl.mk
endif
Expand All @@ -78,13 +82,8 @@ TESTS = \
trinary \
curl \
dcurl \
multi-pow \
pow

ifeq ("$(BUILD_COMPAT)", "1")
TESTS += ccurl-multi_pow
endif

TESTS := $(addprefix $(OUT)/test-, $(TESTS))

LIBS = libdcurl.so
Expand Down Expand Up @@ -132,14 +131,6 @@ 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 @@ -148,20 +139,14 @@ $(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)
$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBTUV_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)

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

$(OUT)/test-%: tests/test-%.py $(OUT)/libdcurl.so
$(Q)echo "#!$(PYTHON)" > $@
$(call py_prepare_cmd)
$(Q)chmod +x $@

include mk/common.mk
include mk/python.mk

-include $(deps)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dcurl - Multi-threaded Curl implementation

[![Build Status](https://travis-ci.org/DLTcollab/dcurl.svg?branch=dev)](https://travis-ci.org/DLTcollab/dcurl)
[![Build Status](https://travis-ci.org/DLTcollab/dcurl.svg?branch=develop)](https://travis-ci.org/DLTcollab/dcurl)
![Supported IRI version](https://img.shields.io/badge/Supported%20IRI%20Version-1.6.0-brightgreen.svg)
![Release version](https://img.shields.io/github/release-pre/DLTcollab/dcurl.svg)

Expand All @@ -23,7 +23,7 @@ After integrating dcurl into IRI, performance of [attachToTangle](https://iota.r
* Each sampling is measured with 30 transaction trytes and total 200 samples are measured.
* mwm = 14, 26 CPU threads to find nonce
* Settings: enable 2 pow tasks in CPU, 1 pow tasks in GPU at the same time
![](https://github.com/raw/DLTcollab/dcurl/dev/docs/benchmark.png)
![](https://github.com/raw/DLTcollab/dcurl/develop/docs/benchmark.png)


## IRI Adaptation
Expand Down
2 changes: 1 addition & 1 deletion deps/libtuv
2 changes: 2 additions & 0 deletions docs/build-n-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- ``BUILD_STAT``: show the statistics of the PoW information.
- ``BUILD_DEBUG``: dump verbose messages internally.
Build with the corresponding Sanitizer to detect software potential bugs if the value is `address`, `undefined` or `thread`.
- ``BOARD``: specify the board which builds the source code.
The supported boards are `de10nano` (DE10-nano board), `arrowsockit` (Arrow SoCKit board), `rpi2` and `rpi3` (Raspberry Pi 2/3 board).
* Alternatively, you can specify conditional build as following:
```shell
$ make BUILD_GPU=0 BUILD_JNI=1 BUILD_AVX=1
Expand Down
14 changes: 0 additions & 14 deletions mk/python.mk

This file was deleted.

7 changes: 6 additions & 1 deletion mk/submodule.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ ifeq ($(UNAME_S),Darwin)
# macOS
UNAME_S := darwin
endif
# For de10-nano, arrow sockit and raspberry pi 2/3 board
ifeq ($(UNAME_M),armv7l)
UNAME_M := arm
endif

# libtuv related variables
LIBTUV_PATH = deps/libtuv
LIBTUV_INCLUDE := -I $(LIBTUV_PATH)/include
LIBTUV_PLATFORM := $(UNAME_M)-$(UNAME_S)
LIBTUV_BOARD := $(BUILD_BOARD)
# PIC (Position-Independent-Code) library
LIBTUV_LIBRARY := $(LIBTUV_PATH)/build/$(LIBTUV_PLATFORM)/release/lib/libtuv.o

$(LIBTUV_PATH)/include:
git submodule update --init $(LIBTUV_PATH)

$(LIBTUV_LIBRARY):
$(MAKE) -C $(LIBTUV_PATH) TUV_BUILD_TYPE=release TUV_CREATE_PIC_LIB=yes
$(MAKE) -C $(LIBTUV_PATH) TUV_BUILD_TYPE=release TUV_CREATE_PIC_LIB=yes TUV_PLATFORM=$(LIBTUV_PLATFORM) TUV_BOARD=$(LIBTUV_BOARD)
2 changes: 1 addition & 1 deletion src/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void _transform(int8_t state[])
for (i = 0; i < STATE_TRITS_LENGTH; i++) {
int aa = indices[i];
int bb = indices[i + 1];
to[i] = truthTable[from[aa] + (from[bb] << 2) + 5];
to[i] = truthTable[from[aa] + (from[bb] * 4) + 5];
}
int8_t *tmp = from;
from = to;
Expand Down
32 changes: 5 additions & 27 deletions src/dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endif
#include "implcontext.h"
#include "trinary.h"
#include "uv.h"
#if defined(ENABLE_AVX)
#include "pow_avx.h"
#elif defined(ENABLE_SSE)
Expand All @@ -25,20 +26,9 @@
#include "pow_c.h"
#endif

#ifdef __APPLE__
#include <dispatch/dispatch.h>
#else
#include <semaphore.h>
#endif

/* check whether dcurl is initialized */
static bool isInitialized = false;

#ifdef __APPLE__
static dispatch_semaphore_t notify;
#else
static sem_t notify;
#endif
static uv_sem_t notify;

LIST_HEAD(IMPL_LIST);

Expand Down Expand Up @@ -78,11 +68,7 @@ bool dcurl_init()
ret &= registerImplContext(&PoWFPGAAccel_Context);
#endif

#ifdef __APPLE__
notify = dispatch_semaphore_create(0);
#else
sem_init(&notify, 0, 0);
#endif
uv_sem_init(&notify, 0);
return isInitialized = ret;
}

Expand Down Expand Up @@ -118,11 +104,7 @@ int8_t *dcurl_entry(int8_t *trytes, int mwm, int threads)
goto do_pow;
}
}
#ifdef __APPLE__
dispatch_semaphore_wait(notify, DISPATCH_TIME_FOREVER);
#else
sem_wait(&notify);
#endif
uv_sem_wait(&notify);
} while (1);

do_pow:
Expand All @@ -133,10 +115,6 @@ int8_t *dcurl_entry(int8_t *trytes, int mwm, int threads)
}
freePoWContext(impl, pow_ctx);
exitImplContext(impl);
#ifdef __APPLE__
dispatch_semaphore_signal(notify);
#else
sem_post(&notify);
#endif
uv_sem_post(&notify);
return res;
}
10 changes: 5 additions & 5 deletions src/implcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ void destroyImplContext(ImplContext *impl_ctx)

bool enterImplContext(ImplContext *impl_ctx)
{
pthread_mutex_lock(&impl_ctx->lock);
uv_mutex_lock(&impl_ctx->lock);
if (impl_ctx->num_working_thread >= impl_ctx->num_max_thread) {
pthread_mutex_unlock(&impl_ctx->lock);
uv_mutex_unlock(&impl_ctx->lock);
return false; /* Access Failed */
}
impl_ctx->num_working_thread++;
pthread_mutex_unlock(&impl_ctx->lock);
uv_mutex_unlock(&impl_ctx->lock);
return true; /* Access Success */
}

void exitImplContext(ImplContext *impl_ctx)
{
pthread_mutex_lock(&impl_ctx->lock);
uv_mutex_lock(&impl_ctx->lock);
impl_ctx->num_working_thread--;
pthread_mutex_unlock(&impl_ctx->lock);
uv_mutex_unlock(&impl_ctx->lock);
}

void *getPoWContext(ImplContext *impl_ctx, int8_t *trytes, int mwm, int threads)
Expand Down
4 changes: 2 additions & 2 deletions src/implcontext.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef IMPL_CTX_H_
#define IMPL_CTX_H_

#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include "common.h"
#include "list.h"
#include "uv.h"

typedef struct _impl_context ImplContext;

Expand All @@ -14,7 +14,7 @@ struct _impl_context {
char *description;

/* Multi-thread Management */
pthread_mutex_t lock;
uv_mutex_t lock;
int bitmap; /* Used to tell which slot is available */
int num_max_thread;
int num_working_thread;
Expand Down
Loading

0 comments on commit 778dcdb

Please sign in to comment.