1"""Generate a mock model for LLVM tests for Register Allocation.
2The generated model is not a neural net - it is just a tf.function with the
3correct input and output parameters. By construction, the mock model will always
4output the first liverange that can be evicted.
10POLICY_DECISION_LABEL =
"index_to_evict"
11POLICY_OUTPUT_SPEC =
"""
14 "logging_name":
"index_to_evict",
16 "name":
"StatefulPartitionedCall",
26PER_REGISTER_FEATURE_LIST = ["mask"]
30def get_input_signature():
31 """Returns (time_step_spec, action_spec) for LLVM register allocation."""
33 (key, tf.TensorSpec(dtype=tf.int64, shape=(NUM_REGISTERS), name=key))
34 for key
in PER_REGISTER_FEATURE_LIST
40 return os.path.join(path,
"output_spec.json")
44 """Build and save the mock model with the given signature."""
48 module.var = tf.Variable(0, dtype=tf.int64)
52 tf.math.argmax(tf.cast(inputs[0][
"mask"], tf.int32), axis=-1) + module.var
54 return {POLICY_DECISION_LABEL: result}
56 module.action = tf.function()(action)
58 tf.saved_model.save(module, path, signatures=action)
60 with open(output_spec_path,
"w")
as f:
61 print(f
"Writing output spec to {output_spec_path}.")
62 f.write(POLICY_OUTPUT_SPEC)
71if __name__ ==
"__main__":
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
def get_output_spec_path(path)
def get_input_signature()
def build_mock_model(path)