Skip to content
Snippets Groups Projects
Commit 9c97cccb authored by Frederik Hennig's avatar Frederik Hennig
Browse files

some minor code + docs cleanup

parent 3e1cf7b0
1 merge request!442Refactor Configuration API
Pipeline #72446 passed with stages
in 6 minutes and 24 seconds
Code Generation
===============
# Code Generation
.. module:: pystencils.codegen
## Invocation
Invocation
----------
```{eval-rst}
.. module:: pystencils.codegen
.. autosummary::
:toctree: generated
:nosignatures:
create_kernel
```
Configuration
-------------
## Configuration
```{eval-rst}
.. module:: pystencils.codegen.config
```
The code generation driver (`create_kernel`, but also `DefaultKernelCreationDriver`) can be configured by
passing it a `CreateKernelConfig` object.
This object can be constructed incrementally:
```Python
cfg = ps.CreateKernelConfig()
cfg.default_dtype = "float32"
cfg.target = ps.Target.X86_AVX
cfg.cpu.openmp.enable = True
cfg.cpu.vectorize.enable = True
cfg.cpu.vectorize.assume_inner_stride_one = True
```
### Options and Option Categories
The following options and option categories are exposed by the configuration object:
#### Target Specification
```{eval-rst}
.. current
.. autosummary::
~CreateKernelConfig.target
```
#### Data Types
```{eval-rst}
.. autosummary::
~CreateKernelConfig.default_dtype
~CreateKernelConfig.index_dtype
```
#### Iteration Space
```{eval-rst}
.. autosummary::
~CreateKernelConfig.ghost_layers
~CreateKernelConfig.iteration_slice
~CreateKernelConfig.index_field
```
#### Kernel Constraint Checks
```{eval-rst}
.. autosummary::
~CreateKernelConfig.allow_double_writes
~CreateKernelConfig.skip_independence_check
```
#### Target-Specific Options
The following categories with target-specific options are exposed:
| | |
|---------------------------|--------------------------|
| {any}`cpu <CpuOptions>` | Options for CPU kernels |
| {any}`gpu <GpuOptions>` | Options for GPU kernels |
| {any}`sycl <SyclOptions>` | Options for SYCL kernels |
#### Kernel Object and Just-In-Time Compilation
```{eval-rst}
.. autosummary::
~CreateKernelConfig.function_name
~CreateKernelConfig.jit
```
### Configuration System Classes
```{eval-rst}
.. autosummary::
:toctree: generated
......@@ -35,7 +115,7 @@ Configuration
AUTO
.. dropdown:: Configuration System Implementation Details
.. dropdown:: Implementation Details
.. autosummary::
:toctree: generated
......@@ -47,9 +127,11 @@ Configuration
Category
ConfigBase
```
Target Specification
--------------------
## Target Specification
```{eval-rst}
.. module:: pystencils.codegen.target
......@@ -60,9 +142,11 @@ Target Specification
Target
Code Generation Drivers
-----------------------
```
## Code Generation Drivers
```{eval-rst}
.. module:: pystencils.codegen.driver
.. autosummary::
......@@ -77,10 +161,11 @@ Code Generation Drivers
:nosignatures:
get_driver
```
Output Code Objects
-------------------
## Output Code Objects
```{eval-rst}
.. currentmodule:: pystencils.codegen
.. autosummary::
......@@ -92,3 +177,4 @@ Output Code Objects
GpuKernel
Parameter
GpuThreadsRange
```
......@@ -48,12 +48,14 @@ cfg.ghost_layers = 2
for all index calculations and loop counters.
- *CPU Optimization Options:* Should now be set via the {any}`cpu <CpuOptions>` option category and its subcategories.
.. dropdown:: Deprecated options of `CreateKernelConfig`
:::{dropdown} Deprecated options of `CreateKernelConfig`
- ``data_type``: Use ``default_dtype`` instead
- ``cpu_openmp``: Set OpenMP-Options in the `cpu.openmp <OpenMpOptions>` category instead.
- ``cpu_vectorize_info``: Set vectorization options in the `cpu.vectorize <VectorizationOptions>` category instead
- ``gpu_indexing_params``: Set GPU indexing options in the `gpu <GpuOptions>` category instead
- ``data_type``: Use ``default_dtype`` instead
- ``cpu_openmp``: Set OpenMP-Options in the `cpu.openmp <OpenMpOptions>` category instead.
- ``cpu_vectorize_info``: Set vectorization options in the `cpu.vectorize <VectorizationOptions>` category instead
- ``gpu_indexing_params``: Set GPU indexing options in the `gpu <GpuOptions>` category instead
:::
### Type Checking
......
......@@ -453,11 +453,7 @@ def create_full_iteration_space(
assert not ctx.fields.index_fields
if not (
(ghost_layers is not None)
or (iteration_slice is not None)
or infer_ghost_layers
):
if (ghost_layers is None) and (iteration_slice is None) and not infer_ghost_layers:
raise ValueError(
"One argument of `ghost_layers`, `iteration_slice`, and `infer_ghost_layers` must be set."
)
......
......@@ -82,17 +82,17 @@ class Option(Generic[Option_T, Arg_T]):
def is_set(self, obj) -> bool:
return getattr(obj, self._lookup, None) is not None
def __set_name__(self, owner, name: str):
def __set_name__(self, owner: ConfigBase, name: str):
self._name = name
self._lookup = f"_{name}"
def __get__(self, obj, objtype=None) -> Option_T | None:
def __get__(self, obj: ConfigBase, objtype: type[ConfigBase] | None = None) -> Option_T | None:
if obj is None:
return None
return getattr(obj, self._lookup, None)
def __set__(self, obj, arg: Arg_T | None):
def __set__(self, obj: ConfigBase, arg: Arg_T | None):
if arg is not None and self._validator is not None:
value = self._validator(obj, arg)
else:
......@@ -190,17 +190,17 @@ class Category(Generic[Category_T]):
def __init__(self, default: Category_T):
self._default = default
def __set_name__(self, owner, name: str):
def __set_name__(self, owner: ConfigBase, name: str):
self._name = name
self._lookup = f"_{name}"
def __get__(self, obj, objtype=None) -> Category_T:
def __get__(self, obj: ConfigBase, objtype: type[ConfigBase] | None = None) -> Category_T:
if obj is None:
return self._default
return cast(Category_T, getattr(obj, self._lookup, None))
def __set__(self, obj, cat: Category_T):
def __set__(self, obj: ConfigBase, cat: Category_T):
setattr(obj, self._lookup, cat.copy())
......@@ -208,12 +208,7 @@ class _AUTO_TYPE: ... # noqa: E701
AUTO = _AUTO_TYPE()
"""Special value that can be passed to some options for invoking automatic behaviour.
Currently, these options permit `AUTO`:
- `ghost_layers <CreateKernelConfig.ghost_layers>`
"""
"""Special value that can be passed to some options for invoking automatic behaviour."""
@dataclass
......
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment