88#define GS_UTOFU_PUT_FLAGS_BASE \
89 (UTOFU_ONESIDED_FLAG_TCQ_NOTICE | UTOFU_ONESIDED_FLAG_REMOTE_MRQ_NOTICE)
107#define GS_UTOFU_PEND_STRIDE 32
147 while (utofu_poll_tcq(
gs_utofu_vcq[k], 0, &cbdata) == UTOFU_SUCCESS) {
148 if (cbdata != NULL) (*(
long *) cbdata)--;
181 int *nrvcq_out, uint64_t *edata_max,
int *ierr)
186 utofu_tni_id_t *tnis = NULL;
189 if (utofu_get_onesided_tnis(&tnis, &num_tnis) != UTOFU_SUCCESS
195 size_t want_tni = (ntni_req > 0) ? (
size_t) ntni_req : 1;
196 if (want_tni > num_tnis) want_tni = num_tnis;
200 for (
size_t k = 0; k < num_tnis; k++)
213 size_t want_vcq = (nthreads > 0) ? (
size_t) nthreads : 1;
214 const char *nv = getenv(
"NEKO_GS_UTOFU_NVCQ");
216 long cap = strtol(nv, NULL, 10);
217 if (cap > 0 && (
size_t) cap < want_vcq)
218 want_vcq = (size_t) cap;
229 for (
size_t s = 0; s < want_tni && !created; s++) {
231 UTOFU_VCQ_FLAG_THREAD_SAFE,
255 const char *nr = getenv(
"NEKO_GS_UTOFU_NRVCQ");
257 long v = strtol(nr, NULL, 10);
263 struct utofu_onesided_caps *caps = NULL;
264 if (utofu_query_onesided_caps(tnis[0], &caps) == UTOFU_SUCCESS
266 size_t eb = caps->max_edata_size;
274 const char *ci = getenv(
"NEKO_GS_UTOFU_CACHE_INJECT");
276 if (ci == NULL || ci[0] !=
'0')
282 const char *mi = getenv(
"NEKO_GS_UTOFU_MASTER_INJECT");
311 void *recv_buf,
size_t recv_bytes,
312 void **ctx_out,
int *nrvcq_out,
313 uint64_t *recv_vcq_id, uint64_t *recv_stadd,
337 utofu_tni_id_t rtni =
348 if (ctx->
nrvcq == 0) {
354 if (utofu_reg_mem(
gs_utofu_vcq[k], send_buf, send_bytes, 0,
360 for (
size_t r = 0; r < ctx->
nrvcq; r++) {
361 if (utofu_reg_mem(ctx->
recv_vcq[r], recv_buf, recv_bytes, 0,
368 for (
size_t r = 0; r < ctx->
nrvcq; r++) {
370 if (utofu_query_vcq_id(ctx->
recv_vcq[r], &vid) != UTOFU_SUCCESS) {
374 recv_vcq_id[r] = (uint64_t) vid;
375 recv_stadd[r] = (uint64_t) ctx->
recv_stadd[r];
378 *nrvcq_out = (int) ctx->
nrvcq;
386 if (ctx == NULL)
return;
391 for (
int h = 0; h < 2; h++)
398 for (
size_t r = 0; r < ctx->
nrvcq; r++) {
416 const int64_t *send_off,
const int64_t *send_len,
417 const uint64_t *rmt_vcq_id,
418 const uint64_t *rmt_stadd,
419 const int64_t *dst_off0,
const int64_t *dst_off1,
420 const int *dst_tag,
int parity, int64_t send_base,
423 const int64_t doff = parity ? dst_off1[
i] : dst_off0[
i];
427 + (utofu_stadd_t)((send_base + send_off[
i]) * elem_size);
428 utofu_stadd_t rmt = (utofu_stadd_t) rmt_stadd[
i]
429 + (utofu_stadd_t)(doff * elem_size);
430 size_t len = (size_t)(send_len[
i] * elem_size);
431 uint64_t edata = (uint64_t) dst_tag[
i] * 2u + (uint64_t) parity;
435 rc = utofu_put(
gs_utofu_vcq[k], (utofu_vcq_id_t) rmt_vcq_id[
i],
438 if (rc == UTOFU_ERR_BUSY)
440 }
while (rc == UTOFU_ERR_BUSY);
442 if (rc == UTOFU_SUCCESS)
464 const int64_t *send_off,
const int64_t *send_len,
465 const uint64_t *rmt_vcq_id,
const uint64_t *rmt_stadd,
466 const int64_t *dst_off0,
const int64_t *dst_off1,
467 const int *dst_tag,
int parity, int64_t send_base,
468 int elem_size,
int *ierr)
474 if (tid != 0)
return;
475 for (
int i = 0;
i < nsend;
i++) {
478 rmt_stadd, dst_off0, dst_off1, dst_tag, parity,
479 send_base, elem_size) != UTOFU_SUCCESS) {
488 if (tid >= npost)
return;
490 for (
int i = tid;
i < nsend;
i += npost) {
492 rmt_vcq_id, rmt_stadd, dst_off0, dst_off1, dst_tag,
493 parity, send_base, elem_size) != UTOFU_SUCCESS) {
510 int *ncompleted,
int *out_idx,
int *ierr)
518 for (
int s = 0; s < ctx->
stash_n; s++) {
519 uint64_t ed = ctx->
stash[s];
520 if ((
int)(ed & 1u) == parity && n < cap)
521 out_idx[n++] = (int)(ed >> 1) + 1;
531 struct utofu_mrq_notice notice;
532 for (
size_t r = 0; r < ctx->
nrvcq && n < cap; r++) {
534 int rc = utofu_poll_mrq(ctx->
recv_vcq[r], 0, ¬ice);
535 if (rc == UTOFU_ERR_NOT_FOUND)
break;
536 if (rc != UTOFU_SUCCESS) {
541 if (notice.notice_type != UTOFU_MRQ_TYPE_RMT_PUT)
continue;
543 uint64_t ed = notice.edata;
544 if ((
int)(ed & 1u) == parity)
545 out_idx[n++] = (int)(ed >> 1) + 1;
566 for (
size_t k = (
size_t) tid; k <
gs_utofu_nvcq; k += (size_t) nteam)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
static int gs_utofu_ready
static void gs_utofu_stash_push(gs_utofu_ctx_t *ctx, uint64_t edata)
static int gs_utofu_master_inject
#define GS_UTOFU_PUT_FLAGS_BASE
static utofu_vcq_hdl_t * gs_utofu_vcq
static size_t gs_utofu_ntni
static size_t gs_utofu_nalltni
static int gs_utofu_recv_rr
static unsigned long gs_utofu_put_flags
#define GS_UTOFU_PEND_STRIDE
void gs_utofu_post_puts(void *vctx, int tid, int nteam, int nsend, const int64_t *send_off, const int64_t *send_len, const uint64_t *rmt_vcq_id, const uint64_t *rmt_stadd, const int64_t *dst_off0, const int64_t *dst_off1, const int *dst_tag, int parity, int64_t send_base, int elem_size, int *ierr)
void gs_utofu_ctx_free(void *vctx, int *ierr)
static void gs_utofu_drain_tcq(size_t k)
void gs_utofu_poll_recv(void *vctx, int parity, int cap, int *ncompleted, int *out_idx, int *ierr)
void gs_utofu_ctx_create(void *send_buf, size_t send_bytes, void *recv_buf, size_t recv_bytes, void **ctx_out, int *nrvcq_out, uint64_t *recv_vcq_id, uint64_t *recv_stadd, int *ierr)
static long * gs_utofu_pend_slot(gs_utofu_ctx_t *ctx, size_t k, int half)
static size_t gs_utofu_nrvcq_def
static utofu_tni_id_t * gs_utofu_alltni
static size_t gs_utofu_nvcq
void gs_utofu_drain_half(void *vctx, int half, int tid, int nteam, int *ierr)
void gs_utofu_init(int ntni_req, int nthreads, int *ntni_out, int *nvcq_out, int *nrvcq_out, uint64_t *edata_max, int *ierr)
static uint64_t gs_utofu_edata_max
static int gs_utofu_put_one(gs_utofu_ctx_t *ctx, size_t k, int i, const int64_t *send_off, const int64_t *send_len, const uint64_t *rmt_vcq_id, const uint64_t *rmt_stadd, const int64_t *dst_off0, const int64_t *dst_off1, const int *dst_tag, int parity, int64_t send_base, int elem_size)
utofu_stadd_t * recv_stadd
utofu_vcq_hdl_t * recv_vcq
utofu_stadd_t * send_stadd