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

Unify PoW implementation context #59

Merged
merged 21 commits into from
Aug 16, 2018
Merged

Unify PoW implementation context #59

merged 21 commits into from
Aug 16, 2018

Conversation

furuame
Copy link
Member

@furuame furuame commented Aug 14, 2018

implcontext.h provides a set of API for PoW Implementations for the new interface #57 :

  • registerImplContext(ImplContext *impl_ctx);
    • Register the PoW implementation into the linked list and the dcurl_entry would iterate the linked list to find the available implementation.
  • initializeImplContext(ImplContext *impl_ctx);
    • Initialize the context of PoW implmentation, which is provided by PoW implementation.
  • destroyImplContext(ImplContext *impl_ctx);
    • Free the allocated memory by PoW implementation, which is also provided by PoW implementation.
  • enterImplContext(ImplContext *impl_ctx);
    • Multi-thread management, which enables the thread get the PoW context
  • exitImplContext(ImplContext *impl_ctx);
    • Multi-thread management, which exits the critical section and let the other thread in
  • getPoWContext(ImplContext *impl_ctx, int8_t *trytes, int mwm);
    • Get the PoW context, which is provided by PoW implementation
  • doThePoW(ImplContext *impl_ctx, void *pow_ctx);
    • Do the PoW
  • freePoWContext(ImplContext *impl_ctx, void *pow_ctx);
    • Free the PoW context
  • getPoWResult(ImplContext *impl_ctx, void *pow_ctx);
    • Get the calculated trytes from PoW context

In this pull request, pure C, SSE, AVX and OpenCL implementations are updated for this new interface and pass the tests.

cwei@creeper ~/w/dcurl> make BUILD_GPU=1 BUILD_DEBUG=1 check
*** Validating build/test-trinary ***
	[ Verified ]
*** Validating build/test-curl ***
	[ Verified ]
*** Validating build/test-dcurl ***
	[ Verified ]
*** Validating build/test-multi-pow ***
	[ Verified ]
*** Validating build/test-pow_sse ***
	[ Verified ]
*** Validating build/test-pow_cl ***
	[ Verified ]

The new interface also enables multi-gpu support #24.

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.77                 Driver Version: 390.77                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:01:00.0 Off |                  N/A |
| 11%   57C    P2   103W / 151W |    445MiB /  8117MiB |     95%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 1070    Off  | 00000000:02:00.0 Off |                  N/A |
|  8%   55C    P2    79W / 151W |    445MiB /  8119MiB |    100%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0     22720      C   /usr/bin/python3                             435MiB |
|    1     22720      C   /usr/bin/python3                             435MiB |
+-----------------------------------------------------------------------------+

@furuame furuame requested a review from jserv August 14, 2018 16:36
@jserv
Copy link
Member

jserv commented Aug 15, 2018

Can you rebase?

The current version only support SSE implementation and the
multi-threaded scenario has not been tested yet. And the other
implementations in the dcurl_entry are removed in the developing
period. The dcurl_entry will be more readable and easy to add
new implmentation in the future.

Testing steps:
* make
* ./build/test-dcurl
A more general way to iterate the registered PoW implementations
The use of the semaphore can avoid unnecssary spinlock, which results in
about 5% performance loss.
Since the dcurl would be compiled for gpu or non-gpu, multi-pow test
case for gpu specifically is unnecessary.
@furuame
Copy link
Member Author

furuame commented Aug 15, 2018

done.

@DLTcollab DLTcollab deleted a comment from furuame Aug 16, 2018
src/clcontext.c Outdated
@@ -9,26 +9,14 @@
#include <stdio.h>
#include "pearl.cl.h"

#define HASH_LENGTH 243 // trits
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you refer these macro in src/constants.h?

src/clcontext.c Outdated
{
*ctx = (CLContext *) malloc(sizeof(CLContext));
ctx->kernel_info.buffer_info[0] =
Copy link
Member

Choose a reason for hiding this comment

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

These indexes look a bit ugly. Can you rewrite by mnemonic enum?

src/clcontext.c Outdated
free(devices);
}
free(platform);
exit:
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 use exit, which conflicts with system call.

src/dcurl.c Outdated
/* number of task that CPU can execute concurrently */
static int MAX_CPU_THREAD = -1;
/* check whether dcurl is initialized */
static int isInitialized = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Use <stdbool.h> instead of numbers.

src/pow_sse.h Outdated
/* Management of Multi-thread */
int indexOfContext;
/* Arguments of PoW */
int8_t input_trytes[2673]; /* 2673 */
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid the exposure of constant 2673 here?

src/pow_sse.c Outdated
@@ -169,13 +166,13 @@ static int64_t loop128(__m128i *lmid,
__m128i *hmid,
int m,
int8_t *nonce,
int id)
int *stopSignal)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if stopSignal is an effective name.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used to signal other threads stop.

Copy link
Member

Choose a reason for hiding this comment

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

It might be ambiguous to mix stop and signal especially for people thinking it as SIGSTOP.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I will fix it.

src/pow_cl.h Outdated
/* Management of Multi-thread */
int indexOfContext;
/* Arguments of PoW */
int8_t input_trytes[2673]; /* 2673 */
Copy link
Member

Choose a reason for hiding this comment

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

Ditto. All constants should be referred in unified header.

@jserv jserv changed the title A more general dcurl_entry is implemented Unify PoW implementation context Aug 16, 2018
@jserv jserv requested a review from ajblane August 16, 2018 10:23
@jserv jserv merged commit 4ffade1 into dev Aug 16, 2018
This was referenced Aug 17, 2018
@furuame furuame deleted the refactor-interface-design branch August 19, 2018 07:04
ajblane added a commit to ajblane/dcurl that referenced this pull request Aug 20, 2018
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

2 participants