Skip to content

Add TOSA Operation Characteristics for Cost Functions#2

Open
erdalmutlu wants to merge 2 commits intopnnl:mainfrom
erdalmutlu:main
Open

Add TOSA Operation Characteristics for Cost Functions#2
erdalmutlu wants to merge 2 commits intopnnl:mainfrom
erdalmutlu:main

Conversation

@erdalmutlu
Copy link
Copy Markdown

Add TOSA Operation Characteristics for Cost Functions

Summary

This PR introduces a new pass for analyzing TOSA operations and adds TOSA operation characteristics that can be used in cost functions. The pass annotates TOSA operations with performance metrics and memory characteristics, enabling cost-based analysis and optimization. It also includes comprehensive tests to ensure the new features work correctly.

New Features

1. TOSA Operation Analysis Pass (sodap-annotate-tosa-ops)

  • Analyzes TOSA operations by lowering them to linalg.generic and collecting performance metrics
  • Annotates TOSA operations with the following attributes:
    • numArithmeticOpsEstimative: Estimated total arithmetic operations
    • numMemoryOpsEstimative: Estimated total memory operations
    • numArithmeticOpsInKernel: Arithmetic operations in the kernel body
    • numMemoryOpsInKernel: Memory operations in the kernel body

2. TOSA Operation Characteristics for Cost Functions (soda-view-op-graph)

  • Adds memory size-based characteristics to TOSA operations for use in cost functions
  • Memory characteristics are computed from the memory footprint of tensor values flowing between TOSA operations
  • Provides raw byte counts (e.g., 64 bytes for tensor<4x4xf32>, 24 bytes for tensor<2x3xf32>) that can be used in cost calculations

Refactoring

  • Extracted LinalgOpInfo struct and analysis utilities from GenerateLinalgSummary.cpp into AnalysisPasses.h for reuse across multiple passes
  • Refactored GenerateLinalgSummary.cpp to use shared analysis utilities

Testing

Added comprehensive tests for the new features:

  • annotate-tosa-ops.mlir: Tests for sodap-annotate-tosa-ops pass

    • Verifies TOSA operations are annotated with performance metrics
    • Tests both tosa.add and tosa.matmul operations
  • view-op-graph-tosa.mlir: Tests for soda-view-op-graph pass with TOSA characteristics

    • Verifies that memory size-based characteristics are added for TOSA operations
    • Checks that memory characteristics are correctly computed and available for cost functions

Documentation

  • Updated README.md with documentation for the new sodap-annotate-tosa-ops pass
  • Added examples of running multiple passes in sequence
  • Reorganized README with clearer sections for available passes

Build System Updates

  • Added AnnotateTosaOps.cpp to CMakeLists.txt
  • Updated SODAPPasses.td with new pass definition
  • Updated SODAPPasses.h with new pass registration

Backward Compatibility

All changes maintain backward compatibility with existing functionality.

This commit adds a new pass for analyzing TOSA operations and enhances
the graph visualization with edge weights based on memory sizes.

New Features:
- Add sodap-annotate-tosa-ops pass: Analyzes TOSA operations by lowering
  them to linalg.generic and collecting performance metrics. The metrics
  are annotated as attributes on the original TOSA operations:
  * numArithmeticOpsEstimative: Estimated total arithmetic operations
  * numMemoryOpsEstimative: Estimated total memory operations
  * numArithmeticOpsInKernel: Arithmetic operations in the kernel body
  * numMemoryOpsInKernel: Memory operations in the kernel body

- Enhance soda-view-op-graph pass: Add memory size-based edge weights
  to the graphviz output for TOSA operations. Weights are computed from
  the memory footprint of tensor values flowing between TOSA operations
  and displayed as raw byte counts.

Refactoring:
- Extract LinalgOpInfo struct and analysis utilities from
  GenerateLinalgSummary.cpp into AnalysisPasses.h for reuse across
  multiple passes
- Refactor GenerateLinalgSummary.cpp to use shared analysis utilities

Documentation:
- Update README.md with documentation for the new sodap-annotate-tosa-ops
  pass and examples of running multiple passes in sequence
- Reorganize README with clearer sections for available passes

Build System:
- Add AnnotateTosaOps.cpp to CMakeLists.txt
- Update SODAPPasses.td with new pass definition
- Update SODAPPasses.h with new pass registration
Add comprehensive tests for the new TOSA-related features:

- annotate-tosa-ops.mlir: Test for sodap-annotate-tosa-ops pass
  * Verifies that TOSA operations are annotated with performance metrics
  * Checks for numArithmeticOpsEstimative, numMemoryOpsEstimative,
    numArithmeticOpsInKernel, and numMemoryOpsInKernel attributes
  * Tests both tosa.add and tosa.matmul operations

- view-op-graph-tosa.mlir: Test for enhanced soda-view-op-graph pass
  * Verifies that edge weights are added to Graphviz output for TOSA ops
  * Checks that memory size-based weights (in bytes) are correctly
    computed and displayed for edges between TOSA operations
  * Tests with tensor<4x4xf32> (64 bytes) and tensor<2x3xf32> (24 bytes)

These tests ensure the new features work correctly and maintain
backward compatibility with existing functionality.
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.

1 participant