---
# System prepended metadata

title: DaCe workshop 2023-11-08
tags: [minutes, dace]

---

# DaCe workshop

## Preparation

### Topics GT4Py intro

* GT4Py overview (Hannes)
    * Workflows (frontends, backends) 

* Field View + ITIR => Combined IR (Enrique/Hannes)
    * [Field-view](https://github.com/havogt/intro_to_gt4py)
    * [ICON Python Dycore frontend overview](https://docs.google.com/presentation/d/1v3QO7NItInjbxGkJKk3jGzvRS9WcGXu1EkEWwvLACs8/edit?usp=sharing)([Office 365](https://ethz-my.sharepoint.com/:p:/r/personal/tille_ethz_ch/Documents/ICON%20Python%20dycore%20-%20Frontend%20overview.pptx?d=w0ddde6cba60f4f348534e19d98777818&csf=1&web=1&e=YctQoh))
    * [Formalize Field-View concepts](https://hackmd.io/@gridtools/rJje3XbNn)
    * [Combined IR sketch](https://github.com/havogt/gt4py/blob/combined_ir/src/gt4py/next/lap.py)

* Iterator IR syntax and operators (Hannes/Enrique/Till)
    * [concepts/Iterator-View.md](https://github.com/GridTools/concepts/blob/master/Iterator-View.md)

* Iterator IR passes (e.g. lift inlining, reduction unrolling, temporaries) (Till)

* Eve infrastructure (Enrique)
    - [`gt4py.eve`](https://github.com/GridTools/gt4py/tree/main/src/gt4py/eve)
        - [`eve.datamodels`](https://github.com/GridTools/gt4py/tree/main/src/gt4py/eve/datamodels) = [dataclasses](https://docs.python.org/3/library/dataclasses.html) + [attrs](https://www.attrs.org/en/stable/examples.html) validators & converters) * [pydantic.Datamodels](https://docs.pydantic.dev/latest/#pydantic-examples)
        - [`eve.extended_typing`](https://github.com/GridTools/gt4py/blob/main/src/gt4py/eve/extended_typing.py) = [standard typing](https://docs.python.org/3/library/typing.html) + [typing_extensions](https://typing-extensions.readthedocs.io/en/latest/#module-contents)
        - [`eve.codegen`](https://github.com/GridTools/gt4py/blob/main/src/gt4py/eve/codegen.py) = node_visitors + string templates
    - [`eve_tests`](https://github.com/GridTools/gt4py/tree/main/tests/eve_tests/unit_tests)

* icon4py → gt4py → dace execution flow (Edoardo)

* gt4py.cartesian
    * [Description of the Optimization Intermediate Representation (OIR)](https://hackmd.io/LtuWbpAzSCKNVwtMFBFh9Q)
    * "DaCe orchestration"
    * optimizations 

---
* Glossary: what do we call IR, frontend, backend, etc...

### SDFG Refresher
* Short intro to SDFG focused only on elements likely relevant for workshop (Ben)

### Questions to DaCe future:
- jax 2 DaCe
- dace-mlir
- builtin/intrinsic library nodes

### Discussion points
- can_deref implementation with select memlet
- AOT vs JIT

### Outlook


-------------------

## Minutes

### GT4Py overview (Hannes)

- Hannes presented slides from another internal EXCLAIM gt4py workshop one year ago
- Double roundtrip ITIR backend makes sure the user-written IR gets canonicalized properly to ITIR using the builtin functions:
    ```python!
    def diff(inp):
        return deref(shift(I,1)(inp)) - deref(shift(I,-1)(inp))

    def diff(inp):
        return minus(deref(shift(I,1)(inp)), deref(shift(I,-1)(inp)))

    ```
- Ideal SDFG representations should have:
    - As few states as possibles
    - It doesn't need to have maps, loops are also ok
    - As less boilerplate and concrete implementation details as possible ?

- Action points:
    - Try different flags in the current ITIR - DaCe backend
    - Try some improvements in the  ITIR - DaCe backend (memlets, ... ?)
    - Compare the generated SDFGs from the current ITIR - DaCe backend and the NumPy Dace frontend using the validation Numpy stencils in icon4py


### Scratch

```python!
# def diff(inp):
#     return deref(shift(I,1)(inp)) - deref(shift(I,-1)(inp))

@fundef
def diff(inp: iterator):
    return minus(deref(shift(I,1)(inp)), deref(shift(I,-1)(inp)))


@fencil(buffer_info={"inp": ...})
def diff_program(inp, out2):
    tmp = allocate_tmp()
    closure(diff, domain=..., [inp], tmp)
    closure(diff, domain=..., [tmp], out2)
    

@fundef
def diff_twice(inp):
    return diff(lift(diff)(inp))

@fencil
def diff_twice_program(inp, out):
    closure(diff_twice, domain=..., [inp], out)
    

diff_program(inp, out)
```
