forked from google/gematria
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
273 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from gematria.basic_block.python import basic_block | ||
from gematria.basic_block.python import basic_block_protos | ||
from gematria.proto import basic_block_pb2 | ||
from gematria.proto import throughput_pb2 | ||
from gematria.proto import canonicalized_instruction_pb2 | ||
from gematria.io.python import tfrecord | ||
|
||
from collections.abc import Sequence | ||
|
||
from absl import app | ||
from absl import flags | ||
from absl import logging | ||
|
||
import numpy as np | ||
_CanonicalizedInstructionProto = ( | ||
canonicalized_instruction_pb2.CanonicalizedInstructionProto | ||
) | ||
|
||
r"""Generates tokens from a Gematria data set. | ||
Usage: | ||
gen_tokens \ | ||
--gematria_input_tfrecord=/tmp/bhive/skl.tfrecord \ | ||
--gematria_output_tokens=/tmp/bhive/skl_tokens.txt \ | ||
""" | ||
|
||
_INPUT_TFRECORD_FILE = flags.DEFINE_string( | ||
'gematria_input_tfrecord', | ||
None, | ||
'The name of the TFRecord file to read the tokens from.', | ||
required=True, | ||
) | ||
|
||
|
||
def main(argv: Sequence[str]) -> None: | ||
if len(argv) > 1: | ||
raise app.UsageError('Too many command-line arguments.') | ||
output_blocks = list( | ||
tfrecord.read_protos((_INPUT_TFRECORD_FILE.value,), throughput_pb2.BasicBlockWithThroughputProto) | ||
) | ||
y_actual = [] | ||
y_predict = [] | ||
for block in output_blocks: | ||
print(block) | ||
assert(len(block.inverse_throughputs) == 2) | ||
y_actual.append(block.inverse_throughputs[0].inverse_throughput_cycles[0]) | ||
y_predict.append(block.inverse_throughputs[1].inverse_throughput_cycles[0]) | ||
|
||
print("y true is:") | ||
print(y_actual) | ||
print("y pred is:") | ||
print(y_predict) | ||
y_actual = np.array(y_actual) | ||
y_predict = np.array(y_predict) | ||
|
||
# Ensure that y_actual and y_predict have the same length | ||
if y_actual.shape != y_predict.shape: | ||
raise ValueError("The shapes of y_actual and y_predict must be the same") | ||
# Find the 10th and 90th percentiles of y_actual | ||
p10 = np.percentile(y_actual, 10) | ||
p90 = np.percentile(y_actual, 90) | ||
# Filter both arrays to ignore the bottom and top 10 percentiles | ||
filtered_indices = (y_actual >= p10) & (y_actual <= p90) | ||
filtered_y_actual = y_actual[filtered_indices] | ||
filtered_y_predict = y_predict[filtered_indices] | ||
# Compute MAE for the filtered data | ||
mae = np.mean(np.abs(filtered_y_actual - filtered_y_predict)) | ||
# Compute MSE for the filtered data | ||
mse = np.mean((filtered_y_actual - filtered_y_predict) ** 2) | ||
print(f"Mean Absolute Error (MAE) for the 10th to 90th percentile range: {mae}") | ||
print(f"Mean Absolute Error (MSE) for the 10th to 90th percentile range: {mse}") | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
app.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
num_graphs = 1 | ||
num_nodes = 13 | ||
num_edges = 15 | ||
num_node_tokens = 12 | ||
num_nodes_per_block = [13] | ||
num_edges_per_block = [15] | ||
register_nodes : | ||
%5 -> 12 | ||
%6 -> 11 | ||
RBP -> 7 | ||
%1 -> 4 | ||
%0 -> 2 | ||
RDI -> 1 | ||
alias_group_nodes : | ||
1 -> 8 | ||
node_types = [NodeType::kInstruction NodeType::kRegister | ||
NodeType::kRegister NodeType::kInstruction NodeType::kRegister | ||
NodeType::kInstruction NodeType::kAddressOperand | ||
NodeType::kRegister NodeType::kMemoryOperand | ||
NodeType::kInstruction NodeType::kAddressOperand | ||
NodeType::kRegister NodeType::kRegister] | ||
edge_senders = [10023376455811109] | ||
edge_receivers = [02334565589910912] | ||
edge_types = [EdgeType::kInputOperands EdgeType::kOutputOperands | ||
EdgeType::kStructuralDependency EdgeType::kInputOperands | ||
EdgeType::kOutputOperands EdgeType::kStructuralDependency | ||
EdgeType::kAddressBaseRegister EdgeType::kInputOperands | ||
EdgeType::kInputOperands EdgeType::kOutputOperands | ||
EdgeType::kStructuralDependency EdgeType::kInputOperands | ||
EdgeType::kAddressBaseRegister EdgeType::kInputOperands | ||
EdgeType::kOutputOperands] | ||
|
||
|
||
==========interference======== | ||
|
||
===================================== | ||
num_graphs = 1 | ||
num_nodes = 14 | ||
num_edges = 22 | ||
num_node_tokens = 12 | ||
num_nodes_per_block = [14,] | ||
num_edges_per_block = [22,] | ||
register_nodes : | ||
RBP -> 10 | ||
%outer -> 6 | ||
%1 -> 5 | ||
%5 -> 4 | ||
%6 -> 3 | ||
%0 -> 2 | ||
RDI -> 1 | ||
alias_group_nodes : | ||
1 -> 11 | ||
interference_groups : | ||
%5 -> [ %0 ] | ||
%6 -> [ %0 ] | ||
%1 -> [ %0 ] | ||
%0 -> [ %outer %1 %5 %6 ] | ||
node_types = [NodeType::kInstruction,NodeType::kRegister,NodeType::kRegister, | ||
NodeType::kRegister,NodeType::kRegister,NodeType::kRegister, | ||
NodeType::kRegister,NodeType::kInstruction,NodeType::kInstruction, | ||
NodeType::kAddressOperand,NodeType::kRegister,NodeType::kMemoryOperand, | ||
NodeType::kInstruction,NodeType::kAddressOperand,] | ||
edge_senders = [1,0,3,4,5,6,0,2,7,2,7,10,9,5,8,8,11,3,2,13,12,2,] | ||
edge_receivers = [0,2,2,2,2,2,7,7,5,5,8,9,8,8,11,12,12,13,3,12,4,4,] | ||
edge_types = [EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kInterference,EdgeType::kInterference, | ||
EdgeType::kInterference,EdgeType::kInterference,EdgeType::kStructuralDependency, | ||
EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kInterference, | ||
EdgeType::kStructuralDependency,EdgeType::kAddressBaseRegister,EdgeType::kInputOperands, | ||
EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kStructuralDependency, | ||
EdgeType::kInputOperands,EdgeType::kAddressBaseRegister,EdgeType::kInterference, | ||
EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kInterference,] | ||
InstructionNodeMask = [1,0,0,0,0,0,0,1,1,0,0,0,1,0,] | ||
DeltaBlockIndex = [0,0,0,0,] | ||
|
||
|
||
|
||
num_graphs = 1 | ||
num_nodes = 14 | ||
num_edges = 23 | ||
num_node_tokens = 12 | ||
num_nodes_per_block = [14,] | ||
num_edges_per_block = [23,] | ||
register_nodes : | ||
RBP -> 10 | ||
%outer -> 6 | ||
%1 -> 5 | ||
%5 -> 4 | ||
%6 -> 3 | ||
%0 -> 2 | ||
RDI -> 1 | ||
alias_group_nodes : | ||
1 -> 11 | ||
interference_groups : | ||
%outer -> [ %0 ] | ||
%1 -> [ %0 ] | ||
%5 -> [ %0 ] | ||
%6 -> [ %0 ] | ||
%0 -> [ %outer %1 %5 %6 ] | ||
node_types = [NodeType::kInstruction,NodeType::kRegister,NodeType::kRegister,NodeType::kRegister,NodeType::kRegister,NodeType::kRegister,NodeType::kRegister,NodeType::kInstruction,NodeType::kInstruction,NodeType::kAddressOperand,NodeType::kRegister,NodeType::kMemoryOperand,NodeType::kInstruction,NodeType::kAddressOperand,] | ||
edge_senders = [1,0,3,2,4,2,5,2,6,2,0,2,7,7,10,9,5,8,8,11,3,13,12,] | ||
edge_receivers = [0,2,2,3,2,4,2,5,2,6,7,7,5,8,9,8,8,11,12,12,13,12,4,] | ||
edge_types = [EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kInterference,EdgeType::kStructuralDependency,EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kStructuralDependency,EdgeType::kAddressBaseRegister,EdgeType::kInputOperands,EdgeType::kInputOperands,EdgeType::kOutputOperands,EdgeType::kStructuralDependency,EdgeType::kInputOperands,EdgeType::kAddressBaseRegister,EdgeType::kInputOperands,EdgeType::kOutputOperands,] | ||
InstructionNodeMask = [1,0,0,0,0,0,0,1,1,0,0,0,1,0,] | ||
DeltaBlockIndex = [0,0,0,0,] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters