pystencils merge requestshttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests2019-10-01T15:12:52+02:00https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/69Small fixes2019-10-01T15:12:52+02:00Stephan SeitzSmall fixeshttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/68Declare LoopCounterSymbols nonnegative2019-10-01T15:12:29+02:00Stephan SeitzDeclare LoopCounterSymbols nonnegativeThis removed some checks like `ctr1 <= 0` from my kernelsThis removed some checks like `ctr1 <= 0` from my kernelshttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/66Set assumptions for TypedSymbol/cast_func/IntegerFunctionTwoArgsMixIn the SymPy way2019-09-30T14:11:05+02:00Stephan SeitzSet assumptions for TypedSymbol/cast_func/IntegerFunctionTwoArgsMixIn the SymPy wayAfter having a nearly week long discussion on assumptions in my SymPy PR, I got some idea of how the assumptions in SymPy are working.
It's interesting that you can use `Function.__new__(cls, integer=True)` for `UndefinedFunction`s li...After having a nearly week long discussion on assumptions in my SymPy PR, I got some idea of how the assumptions in SymPy are working.
It's interesting that you can use `Function.__new__(cls, integer=True)` for `UndefinedFunction`s like `Function('f', interger=True)` but not for subclassese of `Function`.
Now things like `(2*f.shape[0]).is_integer` are working.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/63Bugfix: this bracket should not be here (collate_types returns single type)2019-09-30T14:10:58+02:00Stephan SeitzBugfix: this bracket should not be here (collate_types returns single type)https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/65Bugfix: Align calculation of number of ghost layers on GPU with CPU version2019-09-30T14:10:47+02:00Stephan SeitzBugfix: Align calculation of number of ghost layers on GPU with CPU versionFor the calculation of the number of ghostlayers only relative accesses
should be considered like on the CPU versionFor the calculation of the number of ghostlayers only relative accesses
should be considered like on the CPU versionhttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/62Bugfix fields accessed for interpolator access2019-09-30T14:10:31+02:00Stephan SeitzBugfix fields accessed for interpolator accesshttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/64Bugfix avoid east and west const2019-09-30T14:10:05+02:00Stephan SeitzBugfix avoid east and west constHere's the printing logic for SympyAsssignment:
```python
if node.is_declaration:
if node.is_const # <<< and 'const' not in self._print(node.lhs.dtype):
prefix = 'const '
else:
...Here's the printing logic for SympyAsssignment:
```python
if node.is_declaration:
if node.is_const # <<< and 'const' not in self._print(node.lhs.dtype):
prefix = 'const '
else:
prefix = ''
data_type = prefix + self._print(node.lhs.dtype) + " "
return "%s%s = %s;" % (data_type, self.sympy_printer.doprint(node.lhs),
self.sympy_printer.doprint(node.rhs))
else:
lhs_type = get_type_of_expression(node.lhs)
if type(lhs_type) is VectorType and isinstance(node.lhs, cast_func):
```
It will always prefix const on a declaration. This will not work if dtype is also const since:
```python
def __str__(self):
result = BasicType.numpy_name_to_c(str(self._dtype))
if self.const:
result += " const"
return result
```
So we get something like `const int64_t const`.
I deleted the postfix const to have everything nicely aligned.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/61Kernel wrapper2019-09-26T17:14:29+02:00Stephan SeitzKernel wrapper`KernelWrapper` is cool. Let's also use it for the `gpucuda` backend.
Also:
- make `show_code(kernel_wrapper)` possible
- fix `DeprecationWarning` for import of `Hashable``KernelWrapper` is cool. Let's also use it for the `gpucuda` backend.
Also:
- make `show_code(kernel_wrapper)` possible
- fix `DeprecationWarning` for import of `Hashable`https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/60Eliminate usages of old name 'equation collection' for `AssignmentCollection`2019-09-26T17:12:44+02:00Stephan SeitzEliminate usages of old name 'equation collection' for `AssignmentCollection`We should avoid the old name equation collection.We should avoid the old name equation collection.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/59Document backends.json2019-09-26T12:49:19+02:00Stephan SeitzDocument backends.jsonhttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/57Add AssignmentCollection.{free_fields,bound_fields}2019-09-25T15:41:44+02:00Stephan SeitzAdd AssignmentCollection.{free_fields,bound_fields}Wasn't this merged already?Wasn't this merged already?https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/56Interpolation 24.0.92019-09-25T15:41:24+02:00Stephan SeitzInterpolation 24.0.9This is another rebased PR for integrating interpolated accesses.
Iterpolation accesses work like `absolute_access` except they can be savely applied on all fields (i.e. with boundary checks).
More info here: !20
This PR contains som...This is another rebased PR for integrating interpolated accesses.
Iterpolation accesses work like `absolute_access` except they can be savely applied on all fields (i.e. with boundary checks).
More info here: !20
This PR contains some dead code that uses https://github.com/theHamsta/CubicInterpolationCUDA . I have not included it as a submodule in pystencils in this PR.
This PR break the hash of those two test:
```
[gw11] [ 14%] FAILED lbmpy_tests/test_code_hashequivalence.py::test_hash_equivalence_llvm
lbmpy_tests/test_conserved_quantity_relaxation_invariance.py::test_srt
[gw8] [ 15%] FAILED lbmpy_tests/test_code_hashequivalence.py::test_hash_equivalence
```https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/58Extra asserts sympy issue2019-09-25T15:38:17+02:00Stephan SeitzExtra asserts sympy issueAdd extra assertions to be super sure.Add extra assertions to be super sure.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/43Use get_type_of_expression in typing_form_sympy_inspection to infer types2019-09-23T16:16:50+02:00Stephan SeitzUse get_type_of_expression in typing_form_sympy_inspection to infer typesDANGER ZONE: this changes something in the core behavior of pystencils. Be careful before merging!
In summary, when `typing_form_sympy_inspection` reaches the point where it would just use `default_type`, we try to use `get_type_of_ex...DANGER ZONE: this changes something in the core behavior of pystencils. Be careful before merging!
In summary, when `typing_form_sympy_inspection` reaches the point where it would just use `default_type`, we try to use `get_type_of_expression` to infer the actual type.
We use information of previously defined variables in current scope.
Another approach would be to just type all the intermediate variable with `auto`.
```python
x = pystencils.fields('x: float32[3d]')
assignments = pystencils.AssignmentCollection({
a: cast_func(10, create_type('float64')),
b: cast_func(10, create_type('uint16')),
e: 11,
c: b,
f: c + b,
d: c + b + x.center + e,
x.center: c + b + x.center
})
```
Before:
```cpp
FUNC_PREFIX void kernel(float * RESTRICT _data_x, int64_t const _size_x_0, int64_t const _size_x_1,
int64_t const _size_x_2, int64_t const _stride_x_0, int64_t const _stride_x_1, int64_t const _stri
de_x_2)
{
const double a = 10.0;
const double b = 10;
const double e = 11.0;
const double c = b;
const double f = b + c;
for (int ctr_0 = 0; ctr_0 < _size_x_0; ctr_0 += 1)
{
float * RESTRICT _data_x_00 = _data_x + _stride_x_0*ctr_0;
for (int ctr_1 = 0; ctr_1 < _size_x_1; ctr_1 += 1)
{
float * RESTRICT _data_x_00_10 = _stride_x_1*ctr_1 + _data_x_00;
for (int ctr_2 = 0; ctr_2 < _size_x_2; ctr_2 += 1)
{
const double d = b + c + e + _data_x_00_10[_stride_x_2*ctr_2];
_data_x_00_10[_stride_x_2*ctr_2] = b + c + _data_x_00_10[_stride_x_2*ctr_2];
}
}
}
}
```
After:
```cpp
FUNC_PREFIX void kernel(float * RESTRICT _data_x, int64_t const _size_x_0, int64_t const _size_x_1,
int64_t const _size_x_2, int64_t const _stride_x_0, int64_t const _stride_x_1, int64_t const _stri
de_x_2)
{
const double a = 10.0;
const uint16_t b = 10;
const int64_t e = 11.0;
const uint16_t c = b;
const uint16_t f = b + c;
for (int ctr_0 = 0; ctr_0 < _size_x_0; ctr_0 += 1)
{
float * RESTRICT _data_x_00 = _data_x + _stride_x_0*ctr_0;
for (int ctr_1 = 0; ctr_1 < _size_x_1; ctr_1 += 1)
{
float * RESTRICT _data_x_00_10 = _stride_x_1*ctr_1 + _data_x_00;
for (int ctr_2 = 0; ctr_2 < _size_x_2; ctr_2 += 1)
{
const float d = b + c + e + _data_x_00_10[_stride_x_2*ctr_2];
_data_x_00_10[_stride_x_2*ctr_2] = b + c + _data_x_00_10[_stride_x_2*ctr_2];
}
}
}
}
```https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/53Compile CUDA using the LLVM backend2019-09-23T12:49:30+02:00Stephan SeitzCompile CUDA using the LLVM backendWe can compile CUDA to PTX using the LLVM backend :wink:
`llc` produces PTX files without complaining.We can compile CUDA to PTX using the LLVM backend :wink:
`llc` produces PTX files without complaining.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/52Sort headers/global definitions to enable reproducible code generation2019-09-23T11:03:53+02:00Stephan SeitzSort headers/global definitions to enable reproducible code generationheaders and global_declarations are generated by methods that return
sets. So even with the same inputs it is not guaranteed that the same
source code is generated since sets do not guarantee a specific order
when iterating over them.
I...headers and global_declarations are generated by methods that return
sets. So even with the same inputs it is not guaranteed that the same
source code is generated since sets do not guarantee a specific order
when iterating over them.
I was supprised that my generated code could often not be reused from the cache. The problem was that the included headers appeared in random order.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/34Address #13: Use sympy.codegen.rewriting.optimize2019-09-23T10:55:13+02:00Stephan SeitzAddress #13: Use sympy.codegen.rewriting.optimizeIt's really comfortable to write optimizations in terms of `sympy.codegen.rewrite.RewriteOptim`:
```python
# Evaluates all constant terms
evaluate_constant_terms = ReplaceOptim(
lambda e: hasattr(e, 'is_constant') a...It's really comfortable to write optimizations in terms of `sympy.codegen.rewrite.RewriteOptim`:
```python
# Evaluates all constant terms
evaluate_constant_terms = ReplaceOptim(
lambda e: hasattr(e, 'is_constant') and e.is_constant,
lambda p: p.evalf()
)
```
This PR adds a parameter `sympy_optimizations` to the `create_*_kernel` functions that applies the list of optimizations to the assignments before creating the AST.
`sympy.codegen.rewrite` already has some optimizations. Some similar to the optimizations of pystencils.
For example `create_expand_pow_optimization(limit)` is really similar to the logic in `CustomSympyPrinter._print_Pow`.
See #13
Problem: old versions of sympy (e.g. from ubuntu CI) don't have `sympy.codegen.rewrite`. The optimizations are skipped in that case. `test_and_coverage` applies all optimizations.
We could also try to implement a fma-optimization (fused-multipy add) with that and `sympy.Wild`.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/46AES-NI vectorization improvements2019-09-17T09:08:05+02:00Michael Kuronmkuron@icp.uni-stuttgart.deAES-NI vectorization improvements!30 didn't implement an SSE-vectorized `_mm_cvtepu64_pd` equivalent because the [stackoverflow](https://stackoverflow.com/a/41148578) solution didn't work. That turned out to be due to a bad optimization in GCC 5+ in fast-math mode. None...!30 didn't implement an SSE-vectorized `_mm_cvtepu64_pd` equivalent because the [stackoverflow](https://stackoverflow.com/a/41148578) solution didn't work. That turned out to be due to a bad optimization in GCC 5+ in fast-math mode. None of the other compilers (Clang, Intel, MSVC) have that issue, so we just disable fast-math for that function.
Also, we now use fused multiply-add if available.Martin BauerMartin Bauerhttps://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/50CI: Add minimal-sympy-master2019-09-17T09:06:54+02:00Stephan SeitzCI: Add minimal-sympy-masterTest for #11
This could warn us when SymPy introduces breaking changes.
The test with SymPy master is allowed to fail.Test for #11
This could warn us when SymPy introduces breaking changes.
The test with SymPy master is allowed to fail.https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/51Close pystencils' config file after writing2019-09-17T09:06:15+02:00Stephan SeitzClose pystencils' config file after writingI got a warning that this file remains unclosed.I got a warning that this file remains unclosed.