Skip to content

Commit

Permalink
Multilevel (#3)
Browse files Browse the repository at this point in the history
* Multilevel kernels from spatter
  • Loading branch information
JDTruj2018 committed Jan 4, 2023
1 parent 41ffbbc commit bb220c4
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 34 deletions.
8 changes: 2 additions & 6 deletions include/shared/parse-args.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Administration. The Government is granted for itself and others acting on its
behalf a nonexclusive, paid-up, irrevocable worldwide license in this material
to reproduce, prepare derivative works, distribute copies to the public, perform
publicly and display publicly, and to permit others to do so.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -20,21 +19,16 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------
Copyright (c) 2018, HPCGarage research group at Georgia Tech
All rights reserved.
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 notices (both
LANL and GT), 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.
* Neither the name of spatter nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
Expand Down Expand Up @@ -73,6 +67,8 @@ enum sg_kernel {
SCATTER,
GATHER,
GS,
MULTISCATTER,
MULTIGATHER
};

enum sg_op { OP_COPY, OP_ACCUM, INVALID_OP };
Expand Down
2 changes: 1 addition & 1 deletion src/client/client_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void cleanup_queues(struct client *client) {

void cleanup_shared_mem(struct client *client) {
scoria_sm_unmap(client->shared_location, sizeof(struct memory_location),
"client:unmap");
"client:unmap");

close(client->fd_location);
close(client->fd_requests);
Expand Down
47 changes: 32 additions & 15 deletions tests/parse-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Administration. The Government is granted for itself and others acting on its
behalf a nonexclusive, paid-up, irrevocable worldwide license in this material
to reproduce, prepare derivative works, distribute copies to the public, perform
publicly and display publicly, and to permit others to do so.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -20,21 +19,16 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------
Copyright (c) 2018, HPCGarage research group at Georgia Tech
All rights reserved.
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 notices (both
LANL and GT), 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.
* Neither the name of spatter nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
Expand Down Expand Up @@ -141,17 +135,18 @@ void initialize_argtable() {
"(i.e. 1,2,3,4), or a path to a json file with a run-configuration.");
malloc_argtable[8] = pattern_gather =
arg_strn("g", "pattern-gather", "<pattern>", 0, 1,
"Valid wtih [kernel-name: GS]. Specify either a built-in "
"pattern (i.e. UNIFORM), a custom pattern (i.e. 1,2,3,4), or a "
"path to a json file with a run-configuration.");
"Valid wtih [kernel-name: GS, MultiGather]. Specify either a "
"built-in pattern (i.e. UNIFORM), a custom pattern (i.e. "
"1,2,3,4), or a path to a json file with a run-configuration.");
malloc_argtable[9] = pattern_scatter =
arg_strn("h", "pattern-scatter", "<pattern>", 0, 1,
"Valid with [kernel-name: GS]. Specify either a built-in "
"pattern (i.e. UNIFORM), a custom pattern (i.e. 1,2,3,4), or a "
"path to a json file with a run-configuration.");
"Valid with [kernel-name: GS, MultiScatter]. Specify either a "
"built-in pattern (i.e. UNIFORM), a custom pattern (i.e. "
"1,2,3,4), or a path to a json file with a run-configuration.");
malloc_argtable[10] = kernelName =
arg_strn("k", "kernel-name", "<kernel>", 0, 1,
"Specify the kernel you want to run. [Default: Gather]");
"Specify the kernel you want to run. [Default: Gather, Options: "
"Gather, Scatter, GS, MultiGather, MultiScatter]");
malloc_argtable[11] = op = arg_strn("o", "op", "<s>", 0, 1, "TODO");
malloc_argtable[12] = delta =
arg_strn("d", "delta", "<delta[,delta,...]>", 0, 1,
Expand Down Expand Up @@ -245,7 +240,9 @@ int get_num_configs(json_value *value) {
void parse_json_kernel(json_object_entry cur, char **argv, int i) {
if (!strcasecmp(cur.value->u.string.ptr, "SCATTER") ||
!strcasecmp(cur.value->u.string.ptr, "GATHER") ||
!strcasecmp(cur.value->u.string.ptr, "GS")) {
!strcasecmp(cur.value->u.string.ptr, "GS") ||
!strcasecmp(cur.value->u.string.ptr, "MULTISCATTER") ||
!strcasecmp(cur.value->u.string.ptr, "MULTIGATHER")) {
error("Ambiguous Kernel Type: Assuming kernel-name option.", WARN);
snprintf(argv[i + 1], STRING_SIZE, "--kernel-name=%s",
cur.value->u.string.ptr);
Expand Down Expand Up @@ -458,7 +455,11 @@ struct run_config *parse_runs(int argc, char **argv) {

if (kernelName->count > 0) {
copy_str_ignore_leading_space(kernel_name, kernelName->sval[0]);
if (!strcasecmp("GS", kernel_name))
if (!strcasecmp("MULTISCATTER", kernel_name))
rc->kernel = MULTISCATTER;
else if (!strcasecmp("MULTIGATHER", kernel_name))
rc->kernel = MULTIGATHER;
else if (!strcasecmp("GS", kernel_name))
rc->kernel = GS;
else if (!strcasecmp("SCATTER", kernel_name))
rc->kernel = SCATTER;
Expand Down Expand Up @@ -697,6 +698,18 @@ struct run_config *parse_runs(int argc, char **argv) {
if (rc->kernel != GS && !pattern_found)
error("Please specify a pattern", ERROR);

if ((rc->kernel == MULTISCATTER && !pattern_scatter_found) ||
(rc->kernel == MULTISCATTER && !pattern_found))
error("Please specify an inner scatter pattern (scatter pattern -h) and an "
"outer scatter pattern (pattern -p",
ERROR);

if ((rc->kernel == MULTIGATHER && !pattern_gather_found) ||
(rc->kernel == MULTIGATHER && !pattern_found))
error("Please specify an inner gather pattern (gather pattern -g) and an "
"outer gather pattern (pattern -p",
ERROR);

if ((rc->kernel == GS && !pattern_scatter_found) ||
(rc->kernel == GS && !pattern_gather_found))
error("Please specify a gather pattern and a scatter pattern for an GS "
Expand Down Expand Up @@ -741,6 +754,10 @@ struct run_config *parse_runs(int argc, char **argv) {
sprintf(kernel_name, "%s%zu", "gather", rc->vector_len);
else if (rc->kernel == GS)
sprintf(kernel_name, "%s%zu", "sg", rc->vector_len);
else if (rc->kernel == MULTISCATTER)
sprintf(kernel_name, "%s%zu", "multiscatter", rc->vector_len);
else if (rc->kernel == MULTIGATHER)
sprintf(kernel_name, "%s%zu", "multigather", rc->vector_len);

if (pattern_found) {
if (rc->delta <= -1) {
Expand Down
87 changes: 75 additions & 12 deletions tests/test_spatter.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,41 @@ int main(int argc, char **argv) {
return 1;
}

if (rc[0].kernel != GATHER && rc[0].kernel != SCATTER && rc[0].kernel != GS) {
if (rc[0].kernel != GATHER && rc[0].kernel != SCATTER &&
rc[0].kernel != MULTIGATHER && rc[0].kernel != MULTISCATTER) {
printf("Error: Unsupported kernel\n");
exit(1);
}

size_t max_pattern_val = 0;

for (int i = 0; i < nrc; i++)
max_pattern_val = remap_pattern(nrc, rc[i].pattern, rc[i].pattern_len);
for (int i = 0; i < nrc; i++) {
if (rc[i].kernel == MULTISCATTER) {
size_t max_pattern_val_outer =
remap_pattern(nrc, rc[i].pattern, rc[i].pattern_len);
size_t max_pattern_val_inner =
remap_pattern(nrc, rc[i].pattern_scatter, rc[i].pattern_scatter_len);

assert(rc[i].pattern_len > max_pattern_val_inner);

max_pattern_val = max_pattern_val_outer >= max_pattern_val_inner
? max_pattern_val_outer
: max_pattern_val_inner;
} else if (rc[i].kernel == MULTIGATHER) {
size_t max_pattern_val_outer =
remap_pattern(nrc, rc[i].pattern, rc[i].pattern_len);
size_t max_pattern_val_inner =
remap_pattern(nrc, rc[i].pattern_gather, rc[i].pattern_gather_len);

assert(rc[i].pattern_len > max_pattern_val_inner);

max_pattern_val = max_pattern_val_outer >= max_pattern_val_inner
? max_pattern_val_outer
: max_pattern_val_inner;
} else {
max_pattern_val = remap_pattern(nrc, rc[i].pattern, rc[i].pattern_len);
}
}

printf("max pattern val: %d\n", max_pattern_val);

Expand All @@ -58,27 +84,64 @@ int main(int argc, char **argv) {
for (size_t k = 0; k < N; k++)
pattern[k] = (size_t)rc[i].pattern[k];

struct request req;

switch (rc[i].kernel) {
case SCATTER:
case MULTISCATTER: {
size_t M = rc[i].pattern_scatter_len;

printf("MultiScatter with Outer Length: %d and Inner Length: %d\n", N,
M);

size_t *pattern_scatter = shm_malloc(M * sizeof(size_t));
for (size_t k = 0; k < M; k++)
pattern_scatter[k] = (size_t)rc[i].pattern_scatter[k];

scoria_write(&client, res, M, input, pattern, pattern_scatter, 0, 0,
&req);
wait_request(&client, &req);

shm_free(pattern_scatter);
break;
}
case MULTIGATHER: {
size_t M = rc[i].pattern_gather_len;

printf("MultiGahter with Outer Length: %d and Inner Length: %d\n", N,
M);

size_t *pattern_gather = shm_malloc(M * sizeof(size_t));
for (size_t k = 0; k < M; k++)
pattern_gather[k] = (size_t)rc[i].pattern_gather[k];

scoria_read(&client, res, M, input, pattern, pattern_gather, 0, 0,
&req);
wait_request(&client, &req);

shm_free(pattern_gather);
break;
}
case SCATTER: {
printf("Scatter with Length: %d\n", N);

struct request write_req;
scoria_write(&client, res, N, input, pattern, NULL, 0, 0, &write_req);
wait_request(&client, &write_req);
scoria_write(&client, res, N, input, pattern, NULL, 0, 0, &req);
wait_request(&client, &req);

break;
case GATHER:
}
case GATHER: {
printf("Gather with Length: %d\n", N);

struct request read_req;
scoria_read(&client, input, N, res, pattern, NULL, 0, 0, &read_req);
wait_request(&client, &read_req);
scoria_read(&client, input, N, res, pattern, NULL, 0, 0, &req);
wait_request(&client, &req);

break;
default:
}
default: {
printf("Error: Unable to determine kernel\n");
break;
}
}

shm_free(res);
shm_free(input);
Expand Down

0 comments on commit bb220c4

Please sign in to comment.