From bb220c4a9b6b24f758b823a3c17495f9ec971445 Mon Sep 17 00:00:00 2001 From: Jered Dominguez-Trujillo Date: Tue, 3 Jan 2023 17:29:40 -0700 Subject: [PATCH] Multilevel (#3) * Multilevel kernels from spatter --- include/shared/parse-args.h | 8 +--- src/client/client_cleanup.c | 2 +- tests/parse-args.c | 47 +++++++++++++------- tests/test_spatter.c | 87 ++++++++++++++++++++++++++++++++----- 4 files changed, 110 insertions(+), 34 deletions(-) diff --git a/include/shared/parse-args.h b/include/shared/parse-args.h index 3eb6864..4eacd80 100644 --- a/include/shared/parse-args.h +++ b/include/shared/parse-args.h @@ -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 @@ -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. @@ -73,6 +67,8 @@ enum sg_kernel { SCATTER, GATHER, GS, + MULTISCATTER, + MULTIGATHER }; enum sg_op { OP_COPY, OP_ACCUM, INVALID_OP }; diff --git a/src/client/client_cleanup.c b/src/client/client_cleanup.c index 5bd8f85..2bfbd69 100644 --- a/src/client/client_cleanup.c +++ b/src/client/client_cleanup.c @@ -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); diff --git a/tests/parse-args.c b/tests/parse-args.c index 539ef88..f419298 100644 --- a/tests/parse-args.c +++ b/tests/parse-args.c @@ -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 @@ -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. @@ -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", "", 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", "", 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", "", 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", "", 0, 1, "TODO"); malloc_argtable[12] = delta = arg_strn("d", "delta", "", 0, 1, @@ -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); @@ -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; @@ -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 " @@ -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) { diff --git a/tests/test_spatter.c b/tests/test_spatter.c index a8cd1f3..4a21a5d 100644 --- a/tests/test_spatter.c +++ b/tests/test_spatter.c @@ -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); @@ -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);