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

NOMERGE: Add bare-minimum Session API from proposal draft #1065

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions mpp/shmem-def.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ typedef struct {
int num_contexts;
} shmem_team_config_t;

typedef struct {
size_t total_ops;
} shmem_session_config_t;

#if SHMEM_HAVE_ATTRIBUTE_VISIBILITY == 1
__attribute__((visibility("default"))) extern shmem_team_t SHMEM_TEAM_WORLD;
__attribute__((visibility("default"))) extern shmem_team_t SHMEM_TEAM_SHARED;
Expand All @@ -116,6 +120,10 @@ typedef struct {
#define SHMEM_SIGNAL_SET 0
#define SHMEM_SIGNAL_ADD 1

#define SHMEM_SESSION_TOTAL_OPS (1l<<0)
#define SHMEM_SESSION_BATCH (1l<<0)
#define SHMEM_SESSION_SAME_AMO (1l<<1)

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
4 changes: 4 additions & 0 deletions mpp/shmem_c_func.h4
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ define(`SHMEM_C_CTX_FETCH_OR_NBI',
`SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmem_ctx_$1_atomic_fetch_or_nbi(shmem_ctx_t ctx, $2 *fetch, $2 *target, $2 value, int pe)')dnl
SHMEM_DECLARE_FOR_BITWISE_AMO(`SHMEM_C_CTX_FETCH_OR_NBI')

/* Session Routines */
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmem_session_start(shmem_ctx_t ctx, long options, const shmem_session_config_t *config, long config_mask);
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmem_session_stop(shmem_ctx_t ctx);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Might have to move them to shmemx later.

/* Team Management Routines */
SHMEM_FUNCTION_ATTRIBUTES int SHPRE()shmem_team_my_pe(shmem_team_t team);

Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ libsma_la_SOURCES = \
shmem_env_defs.h \
contexts_c.c \
contexts.c \
sessions_c.c \
perf_counters_c.c \
backtrace.c \
shmem_team.c \
Expand Down
58 changes: 58 additions & 0 deletions src/sessions_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* -*- C -*-
*
* Copyright (c) 2024 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license.
*
* This file is part of the Sandia OpenSHMEM software package. For license
* information, see the LICENSE file in the top level directory of the
* distribution.
*
*/

#include "config.h"

#define SHMEM_INTERNAL_INCLUDE
#include "shmem.h"
#include "shmem_internal.h"
#include "transport.h"

#ifdef ENABLE_PROFILING
#include "pshmem.h"

#pragma weak shmem_session_start = pshmem_session_start
#define shmem_session_start pshmem_session_start

#pragma weak shmem_session_stop = pshmem_session_stop
#define shmem_session_stop pshmem_session_stop

#endif /* ENABLE_PROFILING */

SHMEM_FUNCTION_ATTRIBUTES void
shmem_session_start(shmem_ctx_t ctx, long options, const shmem_session_config_t *config, long config_mask)
{
SHMEM_ERR_CHECK_INITIALIZED();

int ret = shmem_transport_session_start((shmem_transport_ctx_t *) ctx, options, config, config_mask);
if (0 != ret) {
DEBUG_MSG("Session did not start correctly (%d)\n", ret);
} else {
DEBUG_MSG("Session started correctly, but all hints are currently ignored\n");
}

return;
}

SHMEM_FUNCTION_ATTRIBUTES void
shmem_session_stop(shmem_ctx_t ctx)
{
SHMEM_ERR_CHECK_INITIALIZED();

int ret = shmem_transport_session_stop((shmem_transport_ctx_t *) ctx);
if (0 != ret) {
DEBUG_MSG("Session didn't stop correctly (%d)\n", ret);
} else {
DEBUG_MSG("Session stopped successfully\n");
}

return;
}
14 changes: 14 additions & 0 deletions src/transport_none.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,18 @@ void shmem_transport_pcntr_get_all(shmem_transport_ctx_t *ctx, shmemx_pcntr_t *p
return;
}

static inline
int
shmem_transport_session_start(shmem_transport_ctx_t *ctx, long options, const shmem_session_config_t *config, long config_mask)
{
return 0;
}

static inline
int
shmem_transport_session_stop(shmem_transport_ctx_t *ctx)
{
return 0;
}

#endif /* TRANSPORT_NONE_H */
10 changes: 10 additions & 0 deletions src/transport_ofi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,16 @@ void shmem_transport_ctx_destroy(shmem_transport_ctx_t *ctx)
}
}

int shmem_transport_session_start(shmem_transport_ctx_t *ctx, long options, const shmem_session_config_t *config, long config_mask)
{
return 0;
}

int shmem_transport_session_stop(shmem_transport_ctx_t *ctx)
{
return 0;
}

int shmem_transport_fini(void)
{
int ret;
Expand Down
3 changes: 3 additions & 0 deletions src/transport_ofi.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ void shmem_transport_probe(void)
int shmem_transport_ctx_create(struct shmem_internal_team_t *team, long options, shmem_transport_ctx_t **ctx);
void shmem_transport_ctx_destroy(shmem_transport_ctx_t *ctx);

int shmem_transport_session_start(shmem_transport_ctx_t *ctx, long options, const shmem_session_config_t *config, long config_mask);
int shmem_transport_session_stop(shmem_transport_ctx_t *ctx);

int shmem_transport_init(void);
int shmem_transport_startup(void);
int shmem_transport_fini(void);
Expand Down
12 changes: 12 additions & 0 deletions src/transport_portals4.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ shmem_transport_ctx_destroy(shmem_transport_ctx_t *ctx)
return;
}

int
shmem_transport_session_start(shmem_transport_ctx_t *ctx, long options, const shmem_session_config_t *config, long config_mask)
{
return 0;
}

int
shmem_transport_session_stop(shmem_transport_ctx_t *ctx)
{
return 0;
}

static
void
init_bounce_buffer(shmem_free_list_item_t *item)
Expand Down
3 changes: 3 additions & 0 deletions src/transport_portals4.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ extern shmem_transport_ctx_t shmem_transport_ctx_default;
int shmem_transport_ctx_create(struct shmem_internal_team_t *team, long options, shmem_transport_ctx_t **ctx);
void shmem_transport_ctx_destroy(shmem_transport_ctx_t *ctx);

int shmem_transport_session_start(shmem_transport_ctx_t *ctx, long options, const shmem_session_config_t *config, long config_mask);
int shmem_transport_session_stop(shmem_transport_ctx_t *ctx);

/*
* PORTALS4_GET_REMOTE_ACCESS is used to get the correct PT and offset
* from the base of the list entry on that PT for a given target
Expand Down
14 changes: 14 additions & 0 deletions src/transport_ucx.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ shmem_transport_ctx_destroy(shmem_transport_ctx_t *ctx)
return;
}

static inline
int
shmem_transport_session_start(shmem_transport_ctx_t *ctx, long options, const shmem_session_config_t *config, long config_mask)
{
return 0;
}

static inline
int
shmem_transport_session_stop(shmem_transport_ctx_t *ctx)
{
return 0;
}

static inline
int
shmem_transport_quiet(shmem_transport_ctx_t* ctx)
Expand Down
54 changes: 54 additions & 0 deletions test/spec-example/shmem_session_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* * This test program is derived from an example program in the
* OpenSHMEM specification.
*/

#include <shmem.h>
#include <stdlib.h>
#include <stdio.h>

#define N_UPDATES (1lu << 18)
#define N_INDICES (1lu << 10)
#define N_VALUES (1lu << 31)

int main(void) {

shmem_init();

uint64_t *table = shmem_calloc(N_INDICES, sizeof(uint64_t));

int mype = shmem_my_pe();
int npes = shmem_n_pes();
srand(mype);

shmem_ctx_t ctx;
int ret = shmem_ctx_create(0, &ctx);
if (ret != 0) {
printf("%d: Error creating context (%d)\n", mype, ret);
shmem_global_exit(1);
}

shmem_session_config_t config;
long config_mask;
config.total_ops = N_UPDATES;
config_mask = SHMEM_SESSION_TOTAL_OPS;

shmem_session_start(ctx, SHMEM_SESSION_SAME_AMO, &config, config_mask);

for (size_t i = 0; i < N_UPDATES; i++) {
int random_pe = rand() % npes;
size_t random_idx = rand() % N_INDICES;
uint64_t random_val = rand() % N_VALUES;
shmem_ctx_uint64_atomic_xor(ctx, &table[random_idx], random_val, random_pe);
}

shmem_session_stop(ctx);
shmem_ctx_quiet(ctx); /* shmem_session_stop() does not quiet the context. */
shmem_sync_all(); /* shmem_session_stop() does not synchronize. */

/* At this point, it is safe to check and/or validate the table result... */

shmem_ctx_destroy(ctx);
shmem_free(table);
shmem_finalize();
return 0;
}
Loading