Skip to content

Commit

Permalink
refactor[next]: workflowify PAST -> ITIR toolchain step (#1479)
Browse files Browse the repository at this point in the history
## New:
- "next.ffront":
  - ".past_to_itir": workflow step PAST -> ITIR
- ".transform_utils": some utility functions moved from
"next.ffront.decorator"
 
## Changed:
 - "Backend":
   - is not a "ProgramProcessor" anymore
   - still passes "is_program_backend" test
- new attribute ".transformer", a workflow which prepares for the
".executor"
- currently starts at "stages.PastClosure" (PAST node + args, kwargs)
but will evolve into starting from function definition + args, kwargs
 
 - "ModularExecutor":
   - is now a "ProgramExecutor" (passes "is_processor_kind" test)

 - "program_processor_interface":
- "is_program_backend" test now checks for existence of an ".executor"
attribute, which must pass the executor test
   
 - "ffront.decorator":
   - several utilities and methods refactored out into the new modules

- tests: test utils / fixtures refactored to deal with backends which
are not executors

---------

Co-authored-by: nfarabullini <nicoletta.farabullini@c2sm.ethz.ch>
Co-authored-by: Rico Häuselmann <ricoh@cscs.ch>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent d5b83a8 commit 7a980f9
Show file tree
Hide file tree
Showing 28 changed files with 507 additions and 293 deletions.
20 changes: 12 additions & 8 deletions src/gt4py/next/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,34 @@
from __future__ import annotations

import dataclasses
from typing import Any, Generic
from typing import Generic

from gt4py._core import definitions as core_defs
from gt4py.next import allocators as next_allocators
from gt4py.next.iterator import ir as itir
from gt4py.next.ffront import past_process_args, past_to_itir
from gt4py.next.otf import stages, workflow
from gt4py.next.program_processors import processor_interface as ppi


DEFAULT_TRANSFORMS: workflow.Workflow[stages.PastClosure, stages.ProgramCall] = (
past_process_args.past_process_args.chain(past_to_itir.PastToItirFactory())
)


@dataclasses.dataclass(frozen=True)
class Backend(Generic[core_defs.DeviceTypeT]):
executor: ppi.ProgramExecutor
allocator: next_allocators.FieldBufferAllocatorProtocol[core_defs.DeviceTypeT]
transformer: workflow.Workflow[stages.PastClosure, stages.ProgramCall] = DEFAULT_TRANSFORMS

def __call__(self, program: itir.FencilDefinition, *args, **kwargs: Any) -> None:
self.executor.__call__(program, *args, **kwargs)
def __call__(self, program: stages.PastClosure) -> None:
program_call = self.transformer(program)
self.executor(program_call.program, *program_call.args, **program_call.kwargs)

@property
def __name__(self) -> str:
return getattr(self.executor, "__name__", None) or repr(self)

@property
def kind(self) -> type[ppi.ProgramExecutor]:
return self.executor.kind

@property
def __gt_allocator__(
self,
Expand Down
Loading

0 comments on commit 7a980f9

Please sign in to comment.