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

Integrate FPGA-accelerated PoW #50

Merged
merged 50 commits into from
Aug 22, 2018
Merged

Integrate FPGA-accelerated PoW #50

merged 50 commits into from
Aug 22, 2018

Conversation

ajblane
Copy link
Collaborator

@ajblane ajblane commented Jul 27, 2018

No description provided.

@jserv jserv requested review from furuame and jserv August 1, 2018 08:12
@jserv jserv changed the title Integrate Lampa Lab's FPGA PoW into dcurl Integrate Lampa Lab's FPGA-accelerated PoW Aug 2, 2018
src/converter.c Outdated
@@ -88,7 +88,7 @@ void getTrits(const char* bytes, int bytelength, char* const trits,
}
}

char* trits_from_trytes(const char* trytes, int length) {
char* trits_from_trytes_aj(const char* trytes, int length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't append _aj suffix.

mk/defs.mk Outdated
@@ -12,3 +12,6 @@ BUILD_JNI ?= 0

# Build cCurl compatible interface
BUILD_COMPAT ?= 0

# Build FPGA backend of LampaLab or not
BUILD_FPGA_LAMPALAB ?= 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be BUILD_FPGA_ACCEL.

src/dcurl.c Outdated
@@ -15,6 +15,8 @@
#include "pow_avx.h"
#elif defined(ENABLE_SSE)
#include "pow_sse.h"
#elif defined(ENABLE_FPGA_LAMPALAB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accordingly, use consistent naming.

#include <unistd.h>
#include "trinary.h"

FILE *ctrl_fd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to expose these symbols? Can you make them with static?

src/trinary.c Outdated
#include "trinary.h"
#include <stdint.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't perform such change.

src/pow_sse.h Outdated
#include <stdint.h>
#include "trinary.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Minimize functional changes.

@@ -0,0 +1,69 @@
/* Test program for pow_sse */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not pow_sse.

@jserv jserv changed the title Integrate Lampa Lab's FPGA-accelerated PoW Integrate FPGA-accelerated PoW Aug 2, 2018
#define MWM_MASK_REG_OFFSET 3
#define CPOW_BASE 0

#define HINTS \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is obsolete. Drop it.

@ajblane ajblane force-pushed the fpga-pow-accel branch 5 times, most recently from ca8f5b0 to 9854378 Compare August 4, 2018 13:48
Makefile Outdated
@@ -39,6 +39,10 @@ ifeq ("$(BUILD_GPU)","1")
include mk/opencl.mk
endif

ifeq ("$(BUILD_FPGA_ACCEL)","1")
include mk/fpgaaccel.mk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to mk/fpga-accel.mk.

mk/fpgaaccel.mk Outdated
@@ -0,0 +1 @@
CFLAGS += -DENABLE_FPGA_ACCEL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set CFLAGS in Makefile. The reason why mk/fpga-accel.mk exists is to provide modularized build procedures.

#include <sys/mman.h>
#include <unistd.h>
#include "trinary.h"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid extra blank lines.


if (ctrl_fd == NULL) {
perror("cpow-ctrl open fail");
exit(EXIT_FAILURE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the dcurl would be used by IRI via JNI, the use of exit(3) would cause the entire process terminated.

fpga_regs_map = 0;
cpow_map = 0;

ctrl_fd = fopen("/dev/cpow-ctrl", "r+");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this "/dev/cpow-ctrl" be passed as an argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not known what you mean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/dev/cpow-ctrl is a device file created by the kernel module, which communicates to FPGA. It would be better if we define several macros to specify these device files in advance.


int8_t *PowFPGAAccel(int8_t *itrytes, int mwm, int index)
{
char nonce_trits[NONCE_LEN];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain the consistency and portability, could char be replaced with int8_t?

#include <unistd.h>
#include "trinary.h"

FILE *ctrl_fd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These global variables, which only be used in this scope, would be dangerous if not declared as static variables.

perror("devmem munmap");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't exit at this time, because the destroy function is not the end of the program.

size_t itrytelen = 0;
size_t itritlen = 0;

itrytelen = strnlen((char *) itrytes, TRANSACTION_LEN);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the length of transaction trytes should be fixed, which is always 2673 in IOTA.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you say that I agree, but it can be used to check whether length of transaction trytes is correct, e.g. https://github.com/LampaLab/iota_fpga/blob/master/pow_accel_soc/software/curl_pow_hard/curl_pow_hard.c#L82

Copy link
Member

@furuame furuame Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the length of itrytes is not equal to TRANSACTION_LEN, it should return an error instead of continuing to do PoW.
I think every implementation should also add this check like this.

if (strlen((char *) itrytes) != TRANSACTION_LEN) return NULL;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is added in dcurl_entry() before doing PoW. Would it be better?

exit(EXIT_SUCCESS);
}

int8_t *PowFPGAAccel(int8_t *itrytes, int mwm, int index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parameter, index, can just be removed if the FPGA solution can only be used to calculate one PoW at a time?

@ajblane ajblane force-pushed the fpga-pow-accel branch 2 times, most recently from 24f22b0 to e2dbc28 Compare August 4, 2018 15:10
README.md Outdated
@@ -12,6 +12,7 @@ Reference Implementation (IRI).
* Check JDK installation and set JAVA_HOME if you wish to specify.
* Only one GPU can be facilitated with dcurl at the moment.
* If your platform doesn't support Intel SSE, dcurl would be compiled with naive implementation.
* For the IOTA hardware accelerator, we integrate [Lampa Lab's Cyclone V FPGA PoW](https://github.com/LampaLab/iota_fpga) into dcurl. Lampa Lab supports soc_system.rbf only for DE10-nano board. You need to synthesis to get soc_system.rbf for using Arrow SoCKit board.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/synthesis/synthesize/

README.md Outdated
@@ -22,6 +23,7 @@ Reference Implementation (IRI).
from downloading from
[latest JAVA source](https://github.com/chenwei-tw/iri/tree/feat/new_pow_interface).
- ``BUILD_COMPAT``: build extra cCurl compatible interface.
- ``BUILD_FPGA_ACCEL``: build the dcurl interface in communication with the IOTA hardware accelerator on the Cyclone V FPGA board, e.g. DE10-nano board and Arrow SoCKit board.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the statement to "build the interface interacting with the Cyclone V FPGA based accelerator. Verified on DE10-nano board and Arrow SoCKit board."

@@ -0,0 +1,18 @@
#ifndef POW_FPGA_LAMPALAB_H_
#define POW_FPGA_LAMPALAB_H_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is inconsistent. Change to POW_FPGA_ACCEL_H_.

#define CPOW_BASE 0

/* Set FPGA configuration for device files */
#define CTRL_FPGA_POW "/dev/cpow-ctrl"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename CTRL_FPGA_POW to DEV_CTRL_FPGA to represent the usage of device file(s).

devmem_fd = open("/dev/mem", O_RDWR | O_SYNC);

if (devmem_fd < 0) {
perror("devmem open");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly use goto to reduce the lines for exception handling.


return 1;

fail_dev_open_mem_map:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to fail_to_open_memmap would be mnemonic.


fail_dev_open_mem_map:
close(devmem_fd);
fail_dev_open_mem_open:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

README.md Outdated
@@ -12,6 +12,7 @@ Reference Implementation (IRI).
* Check JDK installation and set JAVA_HOME if you wish to specify.
* Only one GPU can be facilitated with dcurl at the moment.
* If your platform doesn't support Intel SSE, dcurl would be compiled with naive implementation.
* For the IOTA hardware accelerator, we integrate [Lampa Lab's Cyclone V FPGA PoW](https://github.com/LampaLab/iota_fpga) into dcurl. Lampa Lab supports soc_system.rbf only for DE10-nano board. You need to synthesize to get soc_system.rbf for using Arrow SoCKit board.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why you adopted the FPGA implementation of Lampa Lab should be addressed as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is necessary to maintain our own fork for FPGA-based implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is necessary to do it. As we know, RocketBoards.org provides Golden System Reference Design (GSRD) [0] includes Linux drivers, OS, boot loader and GHRD for Cyclone V SoC. In the future, we need to integrate the OPTEE-related solution and the Mender-related solution into own modified GSRD and rebuild the SD card image. For GHRD, we maybe provide new HDL-implemented PoW for new PoW algorithm and rebuild the RBF.

[0] Arria V & Cyclone V Golden System Reference Design(GSRD)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajblane, got it. Let's fork the repository from Lampa Lab.

@furuame
Copy link
Member

furuame commented Aug 17, 2018

@ajblane I am waiting for your commit for the new dcurl interface 👍

@furuame
Copy link
Member

furuame commented Aug 21, 2018

The commit 119e67d for the new ducrl interface is reviewed.
@jserv @ajblane I think it's time to merge it. Should we do it?

Copy link
Member

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the previous requests are fixed, I would approve and merge this pull request.


ifeq ("$(BUILD_GPU)","1")
include mk/opencl.mk
endif

ifeq ("$(BUILD_FPGA_ACCEL)","1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix?

README.md Outdated
@@ -66,6 +68,27 @@ $ make BUILD_AVX=1 check
[ Verified ]
```

* Test with Arrow SoCKit board with [Download](https://github.com/LampaLab/iota_fpga/releases/tag/v0.1) Linux sd-card image, root password is 123456 and you need to download dcurl into root directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@@ -0,0 +1,22 @@

IOTA FPGA-accelerated solution for Dcurl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use # IOTA FPGA-accelerated solution for dcurl for consistent Markdown style.

IOTA FPGA-accelerated solution for Dcurl
----------------------------------------

Dcurl supports IOTA FPGA-accelerated solutions to improve PoW performance. PoW calculation time for MWM=14 is between 0.001 and 0.8 second and 0.14 second in average and The time for MWM=15 is between 0.01 and 2 second and 0.42 second in average. Currently, it is experimented and verfied on Arrow Sockit board and Intel FPGA DE10-Nano board. We reuse the Lampa Lab-provied FPGA-accelerated solution.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually call it dcurl in lowercase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "verfied"

* Resynthesize the POW hardware accelerator for Arrow Sockit board and flash it into the board
* Integrate the IOTA PoW hardware accelerator into dcurl's implementation interface
* Test and verify it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't append trailing space lines.

* Use System Verilog and UVM to verify the accelerators
* Synthesize Curl & POW hardware accelerators for Intel FPGA DE10-Nano board and flash it into the board
* Write Linux drivers in Gloden System Reference Design for Curl & POW hardware accelerators and verify them
You want to known it much more and further look at [LampaLab/iota_fpga](https://github.com/LampaLab/iota_fpga)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace "You want to known it much more and further look at" with "More information: ".

if (!ctx)
goto fail_to_malloc;

for (i = 0; i < impl_ctx->num_max_thread; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move int i from Line 49 to the scope in for iteration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault. Skip the previous comment.

@jserv jserv merged commit c341faa into DLTcollab:dev Aug 22, 2018
@ajblane ajblane deleted the fpga-pow-accel branch August 27, 2018 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants