Skip to content

Commit 396ac28

Browse files
author
Luke Robison
committed
WIP: writing coll/tuned dynamic file reader in json format
1 parent 0f8a496 commit 396ac28

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

ompi/mca/coll/tuned/coll_tuned_dynamic_file.c

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "ompi/mca/mca.h"
2929
#include "coll_tuned.h"
3030
#include "ompi/mca/coll/base/coll_base_functions.h"
31+
#include "opal/util/json/opal_json.h"
32+
3133

3234
/* need to include our own topo prototypes so we can malloc data on the comm correctly */
3335
#include "ompi/mca/coll/base/coll_base_topo.h"
@@ -46,6 +48,88 @@ static int fileline=0; /* used for verbose error messages */
4648
#define getnext(fptr, pval) ompi_coll_base_file_getnext_long(fptr, &fileline, pval)
4749
#define isnext_digit(fptr) ompi_coll_base_file_peek_next_char_isdigit(fptr)
4850

51+
static int ompi_coll_tuned_name_to_coll_id( const char *coll_name, int *coll_id ) {
52+
// TODO: implement me.
53+
*coll_id = 1;
54+
return 0;
55+
}
56+
57+
58+
static int ompi_coll_tuned_read_rules_json (const opal_json_t *json_root, ompi_coll_alg_rule_t** rules) {
59+
60+
int rc = OPAL_ERROR;
61+
62+
/* complete table of rules */
63+
ompi_coll_alg_rule_t *alg_rules = (ompi_coll_alg_rule_t*) NULL;
64+
65+
/* individual pointers to sections of rules */
66+
ompi_coll_alg_rule_t *alg_p = (ompi_coll_alg_rule_t*) NULL;
67+
ompi_coll_com_rule_t *com_p = (ompi_coll_com_rule_t*) NULL;
68+
ompi_coll_msg_rule_t *msg_p = (ompi_coll_msg_rule_t*) NULL;
69+
70+
71+
alg_rules = ompi_coll_tuned_mk_alg_rules(COLLCOUNT);
72+
73+
const opal_json_t *collectives_obj;
74+
size_t num_collectives = 0;
75+
size_t num_comm_rules;
76+
rc = opal_json_get_key(json_root, "collectives", &collectives_obj);
77+
// TODO err
78+
79+
rc = opal_json_get_container_size(collectives_obj, &num_collectives);
80+
// TODO err
81+
82+
for( size_t jcol = 0; jcol < num_collectives; jcol++ ) {
83+
const opal_json_t *comm_rule_array;
84+
const char* coll_name;
85+
int coll_id;
86+
rc = opal_json_get_key_by_index( collectives_obj, jcol, &coll_name, &comm_rule_array);
87+
// TODO: err
88+
rc = ompi_coll_tuned_name_to_coll_id( coll_name, &coll_id );
89+
// TODO: err
90+
91+
alg_p = &alg_rules[coll_id];
92+
alg_p->alg_rule_id = coll_id;
93+
rc = opal_json_get_container_size(comm_rule_array, &num_comm_rules);
94+
// TODO: err
95+
alg_p->n_com_sizes = (int)num_comm_rules;
96+
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (num_comm_rules, coll_id);
97+
98+
for (size_t jcomm_rule=0; jcomm_rule < num_comm_rules; jcomm_rule++) {
99+
const opal_json_t *comm_rule;
100+
const opal_json_t *msg_size_array;
101+
size_t num_msg_rules;
102+
int64_t comm_size;
103+
rc = opal_json_get_index(comm_rule_array, jcomm_rule, &comm_rule);
104+
com_p = &(alg_p->com_rules[jcomm_rule]);
105+
rc = opal_json_read_integer("comm_size", &comm_size);
106+
rc = opal_json_get_key( comm_rule, "rules", &msg_size_array);
107+
rc = opal_json_get_container_size(msg_size_array, &num_msg_rules);
108+
109+
for (size_t jmsg_rule=0; jmsg_rule < num_msg_rules; jmsg_rule++) {
110+
/* { "bytes" : 0, "alg" : 0, "reqs" : 20 } */
111+
const opal_json_t *msg_rule;
112+
rc = opal_json_get_index(msg_size_array, jmsg_rule, &msg_rule);
113+
msg_p = &(com_p->msg_rules[jmsg_rule]);
114+
int64_t msg_size, faninout;
115+
opal_json_read_integer(msg_rule, &msg_size);
116+
/* allow arg by string? */
117+
msg_p->msg_size = (size_t)msg_size;
118+
119+
opal_json_free(&msg_rule);
120+
}
121+
122+
opal_json_free(&msg_size_array);
123+
opal_json_free(&comm_rule);
124+
}
125+
126+
opal_json_free(&comm_rule_array);
127+
}
128+
129+
// TODO free collectives_obj
130+
return rc;
131+
}
132+
49133
/*
50134
* Reads a rule file called fname
51135
* The rule file defines a set of sets of rules. The outer set is keyed on
@@ -68,7 +152,7 @@ static int fileline=0; /* used for verbose error messages */
68152
*
69153
*/
70154

71-
int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t** rules)
155+
static int ompi_coll_tuned_read_rules_config_file_classic (char *fname, ompi_coll_alg_rule_t** rules)
72156
{
73157
long NCOL = 0, /* number of collectives for which rules are provided */
74158
COLID = 0, /* identifies the collective type to associate the rules with */
@@ -301,3 +385,29 @@ int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t**
301385
return (-1);
302386
}
303387

388+
int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t** rules) {
389+
if (!fname) {
390+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Gave NULL as rule table configuration file for tuned collectives... ignoring!\n"));
391+
return (-1);
392+
}
393+
394+
if (!rules) {
395+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Gave NULL as rule table result ptr!... ignoring!\n"));
396+
return (-2);
397+
}
398+
399+
const opal_json_t *json;
400+
int ret = opal_json_load_file(fname, &json);
401+
if (ret == OPAL_SUCCESS) {
402+
ret = ompi_coll_tuned_read_rules_json(json, rules);
403+
opal_json_free(&json);
404+
return ret;
405+
} else {
406+
opal_output_verbose(20, ompi_coll_tuned_stream, "Failed to parse %s as valid json. Assuming classic format.\n",fname);
407+
ret = ompi_coll_tuned_read_rules_config_file_classic(fname, rules);
408+
if (ret != OPAL_SUCCESS) {
409+
opal_output_verbose(1, ompi_coll_tuned_stream, "Failed to load %s in either json or classic readers. Check format.\n",fname);
410+
}
411+
return ret;
412+
}
413+
}

0 commit comments

Comments
 (0)