-
Notifications
You must be signed in to change notification settings - Fork 163
Add TPU time linear model #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9c6663
Add TPU time linear model
yutation 88dea7e
Update readme
yutation a857376
Remove results
yutation d5452f1
Minor code cleanup
ritikraj7 059da52
More cleanups
ritikraj7 78937c8
update tpuv5e model
yutation a5b66e0
Merge branch 'validation' of github.com:scalesim-project/SCALE-Sim in…
yutation File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -25,4 +25,5 @@ test_benchmark* | |
| result_parser.py | ||
| test* | ||
| configs_test | ||
| benchmark_results | ||
| benchmark_results | ||
| results/ | ||
This file contains hidden or 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 hidden or 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,18 @@ | ||
| [general] | ||
| run_name = scale_example_TPUv4 | ||
|
|
||
| [architecture_presets] | ||
| ArrayHeight: 128 | ||
| ArrayWidth: 128 | ||
| IfmapSramSzkB: 4096 | ||
| FilterSramSzkB: 4096 | ||
| OfmapSramSzkB: 8192 | ||
| IfmapOffset: 0 | ||
| FilterOffset: 10000000 | ||
| OfmapOffset: 20000000 | ||
| Bandwidth : 1024 | ||
| Dataflow : ws | ||
|
|
||
| [run_presets] | ||
| InterfaceBandwidth: USER | ||
| TimeLinearModel: TPUv4 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,6 @@ | ||
| """ | ||
| Linear model package for converting cycles to time. | ||
| """ | ||
|
|
||
|
|
||
|
|
This file contains hidden or 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,60 @@ | ||
| def tpuv4_linear_model(cycles, s_row=1, s_col=1, t_time=1): | ||
| """ | ||
| TPUv4 linear model for converting cycles to time in microseconds. | ||
|
|
||
| Args: | ||
| cycles: Total compute cycles | ||
| s_row: Spatial dimension rows | ||
| s_col: Spatial dimension columns | ||
| t_time: Temporal dimension | ||
|
|
||
| Returns: | ||
| Time in microseconds | ||
| """ | ||
| if s_row <=128 and s_col <=128 and t_time <=128: | ||
| return 0.002762 * cycles - 0.062665 | ||
| elif s_row <=1024 and s_col <=1024 and t_time <=1024: | ||
| return 0.000388 * cycles + 2.05942 | ||
| else: | ||
| return 0.000202 * cycles + 29.7217 | ||
| def tpuv5e_linear_model(cycles, s_row=1, s_col=1, t_time=1): | ||
| """ | ||
| TPUv5e linear model for converting cycles to time in microseconds. | ||
|
|
||
| Args: | ||
| cycles: Total compute cycles | ||
| s_row: Spatial dimension rows | ||
| s_col: Spatial dimension columns | ||
| t_time: Temporal dimension | ||
|
|
||
| Returns: | ||
| Time in microseconds | ||
| """ | ||
| # TODO: Modify for V5 | ||
| if s_row <=128 and s_col <=128 and t_time <=128: | ||
| return 0.002133 * cycles - 0.168796 | ||
| elif s_row <=1024 and s_col <=1024 and t_time <=1024: | ||
| return 0.000167 * cycles + 1.158923 | ||
| else: | ||
| return 0.000159 * cycles -0.380696 | ||
|
|
||
| def tpuv6e_linear_model(cycles, s_row=1, s_col=1, t_time=1): | ||
| """ | ||
| TPUv6e linear model for converting cycles to time in microseconds. | ||
|
|
||
| Args: | ||
| cycles: Total compute cycles | ||
| s_row: Spatial dimension rows | ||
| s_col: Spatial dimension columns | ||
| t_time: Temporal dimension | ||
|
|
||
| Returns: | ||
| Time in microseconds | ||
| """ | ||
| if s_row <=128 and s_col <=128 and t_time <=128: | ||
| return 0.001389 * cycles + 0.604798 | ||
| elif s_row <=1024 and s_col <=1024 and t_time <=1024: | ||
| return 0.000068 * cycles + 1.546793 | ||
| else: | ||
| return 0.000040 * cycles + 4.384712 | ||
|
|
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| from scalesim.topology_utils import topologies as topo | ||
| from scalesim.layout_utils import layouts as layout | ||
| from scalesim.single_layer_sim import single_layer_sim as layer_sim | ||
| from scalesim.linear_model.tpu import tpuv4_linear_model, tpuv5e_linear_model, tpuv6e_linear_model | ||
|
|
||
|
|
||
| class simulator: | ||
|
|
@@ -174,6 +175,11 @@ def generate_reports(self): | |
| header = ('LayerID, Total Cycles (incl. prefetch), Total Cycles, Stall Cycles, Overall Util %, Mapping Efficiency %,' | ||
| ' Compute Util %,\n') | ||
| compute_report.write(header) | ||
|
|
||
| # Create TIME_REPORT.csv for linear model time conversion | ||
| time_report_name = self.top_path + '/TIME_REPORT.csv' | ||
| time_report = open(time_report_name, 'w') | ||
|
||
| time_report.write('LayerID, Time (us),\n') | ||
|
|
||
| bandwidth_report_name = self.top_path + '/BANDWIDTH_REPORT.csv' | ||
| bandwidth_report = open(bandwidth_report_name, 'w') | ||
|
|
@@ -214,6 +220,29 @@ def generate_reports(self): | |
| log += ', '.join([str(x) for x in compute_report_items_this_layer]) | ||
| log += ',\n' | ||
| compute_report.write(log) | ||
|
|
||
| # Generate TIME_REPORT entry using linear model | ||
| total_cycles = compute_report_items_this_layer[1] # Total Cycles (not including prefetch) | ||
| time_linear_model = self.conf.get_time_linear_model() | ||
|
|
||
| # Get spatiotemporal dimensions for this layer | ||
| dataflow = self.conf.get_dataflow() | ||
| s_row, s_col, t_time = self.topo.get_spatiotemporal_dims(layer_id=lid, df=dataflow) | ||
|
|
||
|
|
||
| # Apply the appropriate linear model based on config | ||
| if time_linear_model == 'TPUv4': | ||
| time_us = tpuv4_linear_model(total_cycles, s_row, s_col, t_time) | ||
| elif time_linear_model == 'TPUv5e': | ||
| time_us = tpuv5e_linear_model(total_cycles, s_row, s_col, t_time) | ||
| elif time_linear_model == 'TPUv6e': | ||
| time_us = tpuv6e_linear_model(total_cycles, s_row, s_col, t_time) | ||
| else: | ||
| # Default: no conversion, just use cycles as time | ||
| time_us = total_cycles | ||
|
|
||
| time_log = str(lid) + ', ' + str(time_us) + ',\n' | ||
| time_report.write(time_log) | ||
|
|
||
| bandwidth_report_items_this_layer = single_layer_obj.get_bandwidth_report_items() | ||
| log = str(lid) + ', ' | ||
|
|
@@ -237,6 +266,7 @@ def generate_reports(self): | |
| compute_report.close() | ||
| bandwidth_report.close() | ||
| detail_report.close() | ||
| time_report.close() | ||
| if self.conf.sparsity_support is True: | ||
| sparse_report.close() | ||
|
|
||
|
|
@@ -254,3 +284,4 @@ def get_total_cycles(self): | |
| total_cycles += cycles_this_layer | ||
|
|
||
| return total_cycles | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value "Default" when valid_conf_flag is False is inconsistent with the actual default value "None" set in init. This should return "None" or self.time_linear_model for consistency.