Skip to content

Commit

Permalink
osc/sm: do not require 64-bit atomic math
Browse files Browse the repository at this point in the history
This commit fixes a compile issue on 32-bit systems that do not
support 64-bit atomic math. The active target path was using 64-bit
atomics exclusively to support PSCW. This commit updates the code to
use either 32 or 64-bit atomic math depending on what is available.

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
  • Loading branch information
hjelmn committed Sep 12, 2017
1 parent 29a53b0 commit 7cdda24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
17 changes: 16 additions & 1 deletion ompi/mca/osc/sm/osc_sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@

#include "opal/mca/shmem/base/base.h"

#if OPAL_HAVE_ATOMIC_MATH_64

typedef uint64_t osc_sm_post_type_t;
#define OSC_SM_POST_BITS 6
#define OSC_SM_POST_MASK 0x3f

#else

typedef uint32_t osc_sm_post_type_t;
#define OSC_SM_POST_BITS 5
#define OSC_SM_POST_MASK 0x1f

#endif

/* data shared across all peers */
struct ompi_osc_sm_global_state_t {
int use_barrier_for_fence;
Expand Down Expand Up @@ -81,7 +95,8 @@ struct ompi_osc_sm_module_t {
ompi_osc_sm_global_state_t *global_state;
ompi_osc_sm_node_state_t *my_node_state;
ompi_osc_sm_node_state_t *node_states;
uint64_t **posts;

osc_sm_post_type_t ** volatile posts;

opal_mutex_t lock;
};
Expand Down
8 changes: 4 additions & 4 deletions ompi/mca/osc/sm/osc_sm_active_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ ompi_osc_sm_start(struct ompi_group_t *group,
size = ompi_group_size(module->start_group);

for (int i = 0 ; i < size ; ++i) {
int rank_byte = ranks[i] >> 6;
uint64_t old, rank_bit = ((uint64_t) 1) << (ranks[i] & 0x3f);
int rank_byte = ranks[i] >> OSC_SM_POST_BITS;
osc_sm_post_type_t old, rank_bit = ((osc_sm_post_type_t) 1) << (ranks[i] & 0x3f);

/* wait for rank to post */
while (!(module->posts[my_rank][rank_byte] & rank_bit)) {
Expand All @@ -162,7 +162,7 @@ ompi_osc_sm_start(struct ompi_group_t *group,

do {
old = module->posts[my_rank][rank_byte];
} while (!opal_atomic_cmpset_64 ((int64_t *) module->posts[my_rank] + rank_byte, old, old ^ rank_bit));
} while (!opal_atomic_cmpset ((volatile osc_sm_post_type_t *) module->posts[my_rank] + rank_byte, old, old ^ rank_bit));
}

free (ranks);
Expand Down Expand Up @@ -244,7 +244,7 @@ ompi_osc_sm_post(struct ompi_group_t *group,

gsize = ompi_group_size(module->post_group);
for (int i = 0 ; i < gsize ; ++i) {
(void) opal_atomic_add_64 ((int64_t *) module->posts[ranks[i]] + my_byte, my_bit);
(void) opal_atomic_add ((volatile osc_sm_post_type_t *) module->posts[ranks[i]] + my_byte, my_bit);
}

opal_atomic_wmb ();
Expand Down
8 changes: 4 additions & 4 deletions ompi/mca/osc/sm/osc_sm_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
if (NULL == module->global_state) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
module->node_states = malloc(sizeof(ompi_osc_sm_node_state_t));
if (NULL == module->node_states) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
module->posts = calloc (1, sizeof(module->posts[0]) + sizeof (uint64_t));
module->posts = calloc (1, sizeof(module->posts[0]) + sizeof (module->posts[0][0]));
if (NULL == module->posts) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
module->posts[0] = (uint64_t *) (module->posts + 1);
module->posts[0] = (osc_sm_post_type_t *) (module->posts + 1);
} else {
unsigned long total, *rbuf;
int i, flag;
Expand Down Expand Up @@ -258,7 +258,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
/* user opal/shmem directly to create a shared memory segment */
state_size = sizeof(ompi_osc_sm_global_state_t) + sizeof(ompi_osc_sm_node_state_t) * comm_size;
state_size += OPAL_ALIGN_PAD_AMOUNT(state_size, 64);
posts_size = comm_size * post_size * sizeof (uint64_t);
posts_size = comm_size * post_size * sizeof (module->posts[0][0]);
posts_size += OPAL_ALIGN_PAD_AMOUNT(posts_size, 64);
if (0 == ompi_comm_rank (module->comm)) {
char *data_file;
Expand Down Expand Up @@ -295,7 +295,7 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
if (NULL == module->posts) return OMPI_ERR_TEMP_OUT_OF_RESOURCE;

/* set module->posts[0] first to ensure 64-bit alignment */
module->posts[0] = (uint64_t *) (module->segment_base);
module->posts[0] = (osc_sm_post_type_t *) (module->segment_base);
module->global_state = (ompi_osc_sm_global_state_t *) (module->posts[0] + comm_size * post_size);
module->node_states = (ompi_osc_sm_node_state_t *) (module->global_state + 1);

Expand Down

0 comments on commit 7cdda24

Please sign in to comment.