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

Signal set add APIs #1109

Closed
wants to merge 5 commits into from
Closed
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
12 changes: 12 additions & 0 deletions mpp/shmemx.h4
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ include(shmemx_c_func.h4)dnl
/* C11 Generic Macros */
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(SHMEM_INTERNAL_INCLUDE))

#define shmemx_signal_set(...) \
_Generic(SHMEM_C11_TYPE_EVAL_PTR_OR_SCALAR(SHMEM_C11_ARG0(__VA_ARGS__)), \
shmem_ctx_t: shmemx_ctx_signal_set, \
uint64_t*: shmemx_signal_set \
)(__VA_ARGS__)

#define shmemx_signal_add(...) \
_Generic(SHMEM_C11_TYPE_EVAL_PTR_OR_SCALAR(SHMEM_C11_ARG0(__VA_ARGS__)), \
shmem_ctx_t: shmemx_ctx_signal_add, \
uint64_t*: shmemx_signal_add \
)(__VA_ARGS__)

#endif /* C11 */

#endif /* SHMEMX_H */
6 changes: 6 additions & 0 deletions mpp/shmemx_c_func.h4
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_pcntr_get_completed_read(shmem_ctx_
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_pcntr_get_completed_target(uint64_t *cntr_value);
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_pcntr_get_all(shmem_ctx_t ctx, shmemx_pcntr_t *pcntr);

/* Signal extensions */
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_signal_add(uint64_t *sig_addr, uint64_t signal, int pe);
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_ctx_signal_add(shmem_ctx_t ctx, uint64_t *sig_addr, uint64_t signal, int pe);
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_signal_set(uint64_t *sig_addr, uint64_t signal, int pe);
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_ctx_signal_set(shmem_ctx_t ctx, uint64_t *sig_addr, uint64_t signal, int pe);

/* Separate initializers */
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_heap_create(void *base, size_t size, int device_type, int device_index);
SHMEM_FUNCTION_ATTRIBUTES void SHPRE()shmemx_heap_preinit();
Expand Down
54 changes: 54 additions & 0 deletions src/data_c.c4
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ SHMEM_PROF_DEF_CTX_PUT_N_SIGNAL_NBI(`mem')
#define shmemx_ct_wait pshmemx_ct_wait
#pragma weak shmem_signal_fetch = pshmem_signal_fetch
#define shmem_signal_fetch pshmem_signal_fetch
#pragma weak shmemx_signal_add = pshmemx_signal_add
#define shmemx_signal_add pshmemx_signal_add
#pragma weak shmemx_signal_set = pshmemx_signal_set
#define shmemx_signal_set pshmemx_signal_set
#pragma weak shmemx_ctx_signal_add = pshmemx_ctx_signal_add
#define shmemx_ctx_signal_add pshmemx_ctx_signal_add
#pragma weak shmemx_ctx_signal_set = pshmemx_ctx_signal_set
#define shmemx_ctx_signal_set pshmemx_ctx_signal_set

#endif /* ENABLE_PROFILING */

Expand Down Expand Up @@ -700,6 +708,52 @@ shmem_signal_fetch(const uint64_t* sig_addr)
return val;
}

void SHMEM_FUNCTION_ATTRIBUTES
shmemx_signal_add(uint64_t *sig_addr, uint64_t signal, int pe)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should sig_addr be const? I know in the PR where this was added in the spec the change was suggested to remove the const modifier from sig_addr, but it looks like in the main branch of the OpenSHMEM spec repo it is still a const parameter

{
SHMEM_ERR_CHECK_INITIALIZED();
SHMEM_ERR_CHECK_PE(pe);
SHMEM_ERR_CHECK_SYMMETRIC(sig_addr, sizeof(uint64_t));

shmem_internal_atomic(SHMEM_CTX_DEFAULT, sig_addr, &signal, sizeof(uint64_t),
pe, SHM_INTERNAL_SUM, SHM_INTERNAL_UINT64);
}

void SHMEM_FUNCTION_ATTRIBUTES
shmemx_ctx_signal_add(shmem_ctx_t ctx, uint64_t *sig_addr, uint64_t signal, int pe)
{
SHMEM_ERR_CHECK_INITIALIZED();
SHMEM_ERR_CHECK_PE(pe);
SHMEM_ERR_CHECK_CTX(ctx);
SHMEM_ERR_CHECK_SYMMETRIC(sig_addr, sizeof(uint64_t));

shmem_internal_atomic(ctx, sig_addr, &signal, sizeof(uint64_t),
pe, SHM_INTERNAL_SUM, SHM_INTERNAL_UINT64);
}

void SHMEM_FUNCTION_ATTRIBUTES
shmemx_signal_set(uint64_t *sig_addr, uint64_t signal, int pe)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question about const-ness of sig_addr

{
SHMEM_ERR_CHECK_INITIALIZED();
SHMEM_ERR_CHECK_PE(pe);
SHMEM_ERR_CHECK_SYMMETRIC(sig_addr, sizeof(uint64_t));

shmem_internal_atomic_set(SHMEM_CTX_DEFAULT, (void *) sig_addr, &signal,
sizeof(uint64_t), pe, SHM_INTERNAL_UINT64);
}

void SHMEM_FUNCTION_ATTRIBUTES
shmemx_ctx_signal_set(shmem_ctx_t ctx, uint64_t *sig_addr, uint64_t signal, int pe)
{
SHMEM_ERR_CHECK_INITIALIZED();
SHMEM_ERR_CHECK_PE(pe);
SHMEM_ERR_CHECK_CTX(ctx);
SHMEM_ERR_CHECK_SYMMETRIC(sig_addr, sizeof(uint64_t));

shmem_internal_atomic_set(ctx, (void *) sig_addr, &signal,
sizeof(uint64_t), pe, SHM_INTERNAL_UINT64);
}

void SHMEM_FUNCTION_ATTRIBUTES
shmemx_getmem_ct(shmemx_ct_t ct, void *target, const void *source, size_t nelems, int pe)
{
Expand Down
2 changes: 2 additions & 0 deletions test/shmemx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ if SHMEMX_TESTS
check_PROGRAMS += \
perf_counter \
shmemx_team_node \
signal_add \
signal_set \
shmem_malloc_with_hints

if HAVE_PTHREADS
Expand Down
83 changes: 83 additions & 0 deletions test/shmemx/signal_add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2024 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/*
* Validate signal_add operation
*/

#include <stdio.h>
#include <shmem.h>
#include <shmemx.h>
#include <string.h>

#define MSG_SZ 10

int main(int argc, char *argv[])
{
long source[MSG_SZ];
long *target;
int me, npes, i;
int errors = 0;

static uint64_t sig_addr = 0;

shmem_init();

me = shmem_my_pe();
npes = shmem_n_pes();

for (i = 0; i < MSG_SZ; i++)
source[i] = i;

target = (long *) shmem_calloc(MSG_SZ, sizeof(long));
if (!target) {
fprintf(stderr, "Failed to allocate target pointer\n");
shmem_global_exit(1);
}

shmem_barrier_all();
for (i = 0; i < npes; i++) {
shmem_long_put(target, source, MSG_SZ, i);
shmem_fence();
shmemx_signal_add(&sig_addr, me, i);
}

shmem_signal_wait_until(&sig_addr, SHMEM_CMP_EQ, (uint64_t) ((npes * (npes - 1)) / 2));

for (i = 0; i < MSG_SZ; i++) {
if (target[i] != source[i]) {
fprintf(stderr, "%10d: target[%d] = %ld not matching %ld with SHMEM_SIGNAL_ADD\n",
me, i, target[i], source[i]);
errors++;
}
}

shmem_free(target);
shmem_finalize();

return errors;
}
87 changes: 87 additions & 0 deletions test/shmemx/signal_set.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2024 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/*
* Validate signal_set operation
*/

#include <stdio.h>
#include <shmem.h>
#include <shmemx.h>
#include <string.h>

#define MSG_SZ 10

int main(int argc, char *argv[])
{
long source[MSG_SZ];
long *target;
int me, npes, i, dest_pe;
int errors = 0;

static uint64_t sig_addr = 0;

shmem_init();

me = shmem_my_pe();
npes = shmem_n_pes();
dest_pe = (me + 1) % npes;

for (i = 0; i < MSG_SZ; i++)
source[i] = me + i;

target = (long *) shmem_calloc(MSG_SZ, sizeof(long));
if (!target) {
fprintf(stderr, "Failed to allocate target pointer\n");
shmem_global_exit(1);
}

shmem_barrier_all();
if (me == 0) {
shmem_long_put_nbi(target, source, MSG_SZ, dest_pe);
shmemx_signal_set(SHMEM_CTX_DEFAULT, &sig_addr, me + 1, dest_pe);
shmem_signal_wait_until(&sig_addr, SHMEM_CMP_EQ, npes);
} else {
shmem_signal_wait_until(&sig_addr, SHMEM_CMP_EQ, me);
shmem_long_put_nbi(target, source, MSG_SZ, dest_pe);
shmemx_signal_set(SHMEM_CTX_DEFAULT, &sig_addr, me + 1, dest_pe);
}
shmem_barrier_all();

for (i = 0; i < MSG_SZ; i++) {
if (target[i] != (long)(((me + npes - 1) % npes) + i)) {
fprintf(stderr, "%10d: target[%d] = %ld not matching %ld with SHMEM_SIGNAL_SET\n",
me, i, target[i], (long)(((me + npes - 1) % npes) + i));
errors++;
}
}

shmem_free(target);
shmem_finalize();

return errors;
}
Loading