KULeuven-MICAS/zigzag

Omitting spatial/temporal mapping gives error

b0g2 opened this issue · 4 comments

b0g2 commented

When omitting the spatial/temporal mapping in layer 1 in the example:

workload = {
    0: {'equation': 'O[k][b]+=W[k][c]*I[c][b]',  # O should be the name of the output operand
        'loop_dim_size': {'K': 4, 'B': 4, 'C': 4},
        'operand_precision': {'O': 16, 'O_final': 8, 'W': 8, 'I': 8},  # O = partial sum precision
        'core_allocation': 1,
        'spatial_mapping': {'D1': ('K', 4)},  # Must match with the dimensions of core 1
        'temporal_ordering': [('B', 4), ('C', 4)],
        'memory_operand_links': {'O': 'O', 'W': 'I1', 'I': 'I2'}
        },
     1: {'equation': 'O[ox][k]+=W[fx][c][k]*I[ix][c]',
         'dimension_relations': ['ix=1*ox+1*fx'],
         'loop_dim_size': {'OX': 4, 'K': 8, 'C': 3, 'FX': 3},
         'operand_precision': {'O': 16, 'O_final': 8, 'W': 8, 'I': 8},
         'core_allocation': 1,
         #'spatial_mapping': {'D1': ('K', 4)},
         #'temporal_ordering': [('B', 4), ('C', 4)],
         'memory_operand_links': {'O': 'O', 'W': 'I1', 'I': 'I2'},
         'operand_source': {'W': [], 'I': [0]}
         }
}

for the following stages:

mainstage = MainStage([
    WorkloadAndAcceleratorParserStage,
    CompleteSaveStage,
    WorkloadStage,
    SpatialMappingConversionStage,
    TemporalOrderingConversionStage,
    CostModelStage
],
    accelerator_path=args.accelerator,
    workload_path=args.workload,
    dump_filename_pattern="outputs_workshop/{datetime}.json",
    plot_filename_pattern="outputs_workshop/temporal_mappings.png"
)

I have the error (in Python 3.8, windows):

2022-06-21 20:24:45,519 - classes.stages.SpatialMappingConversionStage.check_layer +45 - CRITICAL - Layer LayerNode_1 has no user-defined spatial mapping.

When playing a bit around, like uncommenting the above #'spatial_mapping' and #'temporal_mapping'` lines also various errors are given. I am not sure how the framework intends to handle mixtures of layers with spatial/without spatial mapping, but this may also be useful to check. It might also be useful to give hints like "Layer X has no user-defined spatial mapping: please provide a spatial mapping ('spatial_mapping' in the workload definition) or make sure stage Y is included".

I have also tried adding the following stages:

SpatialMappingGeneratorStage
TemporalOrderingConversionStage

but it didn't solve the issue (at first sight).

b0g2 commented

As a suggestion, it might be useful to define the stages and workload in the same input file (unless the stages are intended to work with most workloads). Then it would be useful to have examples with spatial/temporal mapping present and absent.

asyms commented

Hi,

Thanks for raising this issue.

I have pushed the workload and main file (with the second layer uncommented), which works fine for me. If you run it as it is now in the code, does it still crash for you?

I have also updated the error messaging for the spatial mapping if it is needed but not provided.

The stages are defined in the main file because the flow of ZigZag can remain identical for different workload/accelerator inputs.

Please let me know if it works!

KR

b0g2 commented

It seems fine now, thanks! Also when omitting spatial_mapping and temporal_mapping, and adding SpatialMappingGeneratorStage, LomaStage, I get a result now. Hopefully these are the correct stages to add in this case.
If I would forget to add these stages, the error is:

TypeError: __init__() missing 2 required keyword-only arguments: 'spatial_mapping' and 'temporal_mapping'

Perhaps this error message could also be improved, e.g., to either add the keywords in layer 1 (in my case) or to add the corresponding stages in the main file. Just for user-friendliness;-)

asyms commented

Yes, they are the correct stages!

The error you shared is a standard Python error, I'm afraid I can't override that one. But we tried to make the naming of the variables as such that you can check in the init.py file in the stages classes.stages folder which Stages supply these parameters.