cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
40 stars 17 forks source link

[Exception] Exception Package for Warning and Error Handling #120

Closed zzzDavid closed 1 year ago

zzzDavid commented 2 years ago

Description

This thread is about adding an exception package for HeteroCL. This package provides a systematic way to define and issue warnings and errors. The package hierarchy follows Python's documentation: having an exception base class, with errors and warnings as subclasses. This package inherits all the errors defined in Halide-based HeteroCL here, and adds warning support.

Features

Class Hierarchy

HCLException
    |
    |--HCLWarning
    |     |--DTypeWarning
    |     |__HCLDeprecationWarning
    |
    |__HCLError
        |--DTypeError
        |--APIError
        |--DSLError
        |--TensorError
        |--DeviceError
        |--AssertError
        |--NotImplementedError
        |--MLIRLimitationError
        |__HCLValueError

Developers can subclass HCLError and HCLWarning to add new types of warning and errors.

Usage

def test_deprecate_stage(): with warnings.catch_warnings(record=True) as w: hcl.init(hcl.Int(32)) A = hcl.placeholder((10,))

    def kernel(A):
        with hcl.Stage("B"):
            with hcl.for_(0, 10) as i:
                A[i] = A[i] + 1
        return
    s = hcl.create_schedule([A], kernel)
    assert len(w) == 1
    assert issubclass(w[-1].category, DeprecationWarning)
    assert "deprecated" in str(w[-1].message)

- Suppress and filter warnings, `HCLDeprecationWarning` as an example
```python
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
zzzDavid commented 2 years ago

I've finished rewriting all errors and warnings in build_ir.py with this new package. The errors and warnings in the front end will be rewritten in the future. This package should act as a central place to handle exceptions.

zzzDavid commented 1 year ago

The revamped frontend uses this exception package for warnings and errors. I will move the descriptions to documentation once the website is up, closing this thread.