Skip to content
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

New feature: Allows the output data of a layer to remain in the low-level memory for later use when possible #25

Merged
merged 8 commits into from
Oct 23, 2023

Conversation

JiacongSun
Copy link
Collaborator

New feature:

  • This feature allows the output data of a layer to remain in the low-level memory when possible. This enables direct use of the output data by the next layer, eliminating the need for data to travel to/from the top memory level.

Note:

  1. This feature applies only to layers on the same branch.
  2. By default, it is assumed that the initial input and final output of the entire network can be generated from the low-level memory. If your case requires them to travel to/from the top memory level, you can change this assumption by setting the workload_data_always_from_top_mem parameter to True in the run() function within the SearchNoUseMemStage.py file.

New stages:

  • SearchNoUseMemStage: This stage searches for unnecessary top memory levels for each layer and generates a pointer indicating which level the output data of each layer should travel up to.
  • RemoveNoUseMemStage: This stage removes memory instances with a level higher than the pointer.

How to use:

  • Place the SearchNoUseMemStage before the WorkloadStage, and place the RemoveNoUseMemStage after the WorkloadStage.

Example:

An example function, get_hardware_performance_zigzag_unused_mem_removing is provided in api.py for reference.

@JiacongSun JiacongSun requested a review from asyms October 5, 2023 13:15
Copy link
Contributor

@asyms asyms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the comments, and format your code using black

## do not add the current mem into the modified architecture
#####################################################

class RemoveNoUseMemStage(Stage):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is not the most informative. Maybe something like "RemoveUnusedMemoryStage"?

for cme, extra_info in sub_stage.run():
yield cme, extra_info

def generate_accelerator_removing_nouse_mem(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly rename this function.

memory_hierarchy = core.memory_hierarchy

if len(self.layer.constant_operands) == 1:
act_operand = self.layer.memory_operand_links[[operand for operand in self.layer.input_operands if operand not in self.layer.constant_operands][0]] # act representation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename all operand variables to reflect if they're "layer operands" or "memory operands" either in the name or in comments

## mem_update_weight = current_mem_level
#####################################################

class SearchNoUseMemStage(Stage):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this class and documentation to "SearchUnusedMemoryStage" or something similar.

const_operand = self.layer.memory_operand_links[weight_operand] # weight representation

# Find target_act/const/output_mem_level
for pos, ele in enumerate(self.mem_update_list[f"{curr_id}"]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is curr_id not already a string? If not, you should convert a variable to a string using str(...)

# Find target_act/const/output_mem_level
for pos, ele in enumerate(self.mem_update_list[f"{curr_id}"]):
if list(ele.keys())[0] == f"{act_operand}":
target_act_mem_level = self.mem_update_list[f"{curr_id}"][pos][f"{act_operand}"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure act_operand is already a string?

dataflows = core.dataflows
if dataflows is not None:
raise NotImplementedError(
"Scale your core-defined dataflows accordingly here."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the dataflows have to be scaled?

Update mem_update_list and mem_update_weight according to the algorithm description at the file beginning.
"""
"""
param const_operand: constant operand name (e.g. "W")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You specify three parameters but the function has no parameters?

@JiacongSun
Copy link
Collaborator Author

New fixes:

  1. SearchNoUseMemStage is renamed as SearchUnusedMemoryStage, RemoveNoUseMemStage is renamed as RemoveUnusedMemoryStage.
  2. Coding style in stages above are reformated using black.
  3. Add more comments in the new stages, including explicitly label whether a operand is of the layer representation or the mem representation.
  4. pytest cases are added under /tests/main/test_without_unused_memory/. Original pytest cases are moved to /tests/main/test_origin/.

Extra note:

  • Only when user-defined workload (.py) is used and there are Adder layers within the workload, the estimation of SearchUnusedMemoryStage for these Adder layers is more pessimistic, which means the topest memory level for output of these Adder layers possibly is higher than expected. (For details, please refer to the comments in SearchUnusedMemoryStage).
  • For other cases (.onnx workload or non-Adder layers), there is no problem.

Copy link
Contributor

@asyms asyms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@asyms asyms merged commit 2b2e076 into KULeuven-MICAS:master Oct 23, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants