Commit 1a37be50 authored by Martin Bauer's avatar Martin Bauer
Browse files

Extended scaling tutorial & more documentation cleanup

parent 4651c191
...@@ -310,7 +310,7 @@ class BoundaryHandling: ...@@ -310,7 +310,7 @@ class BoundaryHandling:
gpu_version = gpu_version.boundary_object_to_index_list gpu_version = gpu_version.boundary_object_to_index_list
cpu_version = cpu_version.boundary_object_to_index_list cpu_version = cpu_version.boundary_object_to_index_list
for obj, cpu_arr in cpu_version.items(): for obj, cpu_arr in cpu_version.items():
if obj not in gpu_version: if obj not in gpu_version or gpu_version[obj].shape != cpu_arr.shape:
gpu_version[obj] = gpuarray.to_gpu(cpu_arr) gpu_version[obj] = gpuarray.to_gpu(cpu_arr)
else: else:
gpu_version[obj].set(cpu_arr) gpu_version[obj].set(cpu_arr)
......
...@@ -63,7 +63,7 @@ compiled into the shared library. Then, the same script can be run from the comp ...@@ -63,7 +63,7 @@ compiled into the shared library. Then, the same script can be run from the comp
- **'read_from_shared_library'**: if true kernels are not compiled but assumed to be in the shared library - **'read_from_shared_library'**: if true kernels are not compiled but assumed to be in the shared library
- **'object_cache'**: path to a folder where intermediate files are stored - **'object_cache'**: path to a folder where intermediate files are stored
- **'clear_cache_on_start'**: when true the cache is cleared on each start of a *pystencils* script - **'clear_cache_on_start'**: when true the cache is cleared on each start of a *pystencils* script
- **'shared_library'**: path to a shared library file, which is created if `read_from_shared_library=false` - **'shared_library'**: path to a shared library file, which is created if 'read_from_shared_library=false'
""" """
from __future__ import print_function from __future__ import print_function
import os import os
......
...@@ -108,14 +108,15 @@ class Diff(sp.Expr): ...@@ -108,14 +108,15 @@ class Diff(sp.Expr):
class DiffOperator(sp.Expr): class DiffOperator(sp.Expr):
""" """Un-applied differential, i.e. differential operator
Un-applied differential, i.e. differential operator
Its args are: Args:
- target: the differential is w.r.t to this variable. target: the differential is w.r.t to this variable.
This target is mainly for display purposes (its the subscript) and to distinguish DiffOperators This target is mainly for display purposes (its the subscript) and to distinguish DiffOperators
If the target is '-1' no subscript is displayed If the target is '-1' no subscript is displayed
- superscript: optional marker displayed as superscript superscript: optional marker displayed as superscript
is not displayed if set to '-1' is not displayed if set to '-1'
The DiffOperator behaves much like a variable with special name. Its main use is to be applied later, using the The DiffOperator behaves much like a variable with special name. Its main use is to be applied later, using the
DiffOperator.apply(expr, arg) which transforms 'DiffOperator's to applied 'Diff's DiffOperator.apply(expr, arg) which transforms 'DiffOperator's to applied 'Diff's
""" """
...@@ -178,7 +179,7 @@ class DiffOperator(sp.Expr): ...@@ -178,7 +179,7 @@ class DiffOperator(sp.Expr):
def diff_terms(expr): def diff_terms(expr):
"""Returns set of all derivatives in an expression. """Returns set of all derivatives in an expression.
This function yields different results than `expr.atoms(Diff)` when nested derivatives are in the expression, This function yields different results than 'expr.atoms(Diff)' when nested derivatives are in the expression,
since this function only returns the outer derivatives since this function only returns the outer derivatives
""" """
result = set() result = set()
......
...@@ -112,7 +112,7 @@ class Field: ...@@ -112,7 +112,7 @@ class Field:
Creating Fields: Creating Fields:
The preferred method to create fields is the `fields` function. The preferred method to create fields is the `fields` function.
Alternatively one can use one of the static functions `Field.create_generic`, `Field.create_from_numpy_array` Alternatively one can use one of the static functions `Field.create_generic`, `Field.create_from_numpy_array`
and `Field.create_fixed_size`. Don't instantiate the Field directly! and `Field.create_fixed_size`. Don't instantiate the Field directly!
Fields can be created with known or unknown shapes: Fields can be created with known or unknown shapes:
1. If you want to create a kernel with fixed loop sizes i.e. the shape of the array is already known. 1. If you want to create a kernel with fixed loop sizes i.e. the shape of the array is already known.
......
...@@ -35,21 +35,27 @@ class AbstractIndexing(abc.ABC): ...@@ -35,21 +35,27 @@ class AbstractIndexing(abc.ABC):
@abc.abstractmethod @abc.abstractmethod
def call_parameters(self, arr_shape): def call_parameters(self, arr_shape):
""" """Determine grid and block size for kernel call.
Determine grid and block size for kernel call
:param arr_shape: the numeric (not symbolic) shape of the array Args:
:return: dict with keys 'blocks' and 'threads' with tuple values for number of (x,y,z) threads and blocks arr_shape: the numeric (not symbolic) shape of the array
the kernel should be started with Returns:
dict with keys 'blocks' and 'threads' with tuple values for number of (x,y,z) threads and blocks
the kernel should be started with
""" """
@abc.abstractmethod @abc.abstractmethod
def guard(self, kernel_content, arr_shape): def guard(self, kernel_content, arr_shape):
""" """In some indexing schemes not all threads of a block execute the kernel content.
In some indexing schemes not all threads of a block execute the kernel content.
This function can return a Conditional ast node, defining this execution guard. This function can return a Conditional ast node, defining this execution guard.
:param kernel_content: the actual kernel contents which can e.g. be put into the Conditional node as true block
:param arr_shape: the numeric or symbolic shape of the field Args:
:return: ast node, which is put inside the kernel function kernel_content: the actual kernel contents which can e.g. be put into the Conditional node as true block
arr_shape: the numeric or symbolic shape of the field
Returns:
ast node, which is put inside the kernel function
""" """
...@@ -116,12 +122,14 @@ class BlockIndexing(AbstractIndexing): ...@@ -116,12 +122,14 @@ class BlockIndexing(AbstractIndexing):
@staticmethod @staticmethod
def limit_block_size_to_device_maximum(block_size): def limit_block_size_to_device_maximum(block_size):
""" """Changes block size according to match device limits.
Changes block size according to match device limits according to the following rules:
1) if the total amount of threads is too big for the current device, the biggest coordinate is divided by 2. * if the total amount of threads is too big for the current device, the biggest coordinate is divided by 2.
2) next, if one component is still too big, the component which is too big is divided by 2 and the smallest * next, if one component is still too big, the component which is too big is divided by 2 and the smallest
component is multiplied by 2, such that the total amount of threads stays the same component is multiplied by 2, such that the total amount of threads stays the same
Returns the altered block_size
Returns:
the altered block_size
""" """
# Get device limits # Get device limits
import pycuda.driver as cuda import pycuda.driver as cuda
......
...@@ -33,7 +33,7 @@ def create_kernel(assignments, target='cpu', data_type="double", iteration_slice ...@@ -33,7 +33,7 @@ def create_kernel(assignments, target='cpu', data_type="double", iteration_slice
Returns: Returns:
abstract syntax tree (AST) object, that can either be printed as source code with `show_code` or abstract syntax tree (AST) object, that can either be printed as source code with `show_code` or
can be compiled with through its `compile()` member can be compiled with through its 'compile()' member
Example: Example:
>>> import pystencils as ps >>> import pystencils as ps
......
...@@ -61,9 +61,9 @@ def subexpression_substitution_in_main_assignments(ac: AC) -> AC: ...@@ -61,9 +61,9 @@ def subexpression_substitution_in_main_assignments(ac: AC) -> AC:
def add_subexpressions_for_divisions(ac: AC) -> AC: def add_subexpressions_for_divisions(ac: AC) -> AC:
"""Introduces subexpressions for all divisions which have no constant in the denominator. r"""Introduces subexpressions for all divisions which have no constant in the denominator.
For example :math:`\frac{1}{x}` is replaced, :math:`\frac{1}{3}` is not replaced. For example :math:`\frac{1}{x}` is replaced while :math:`\frac{1}{3}` is not replaced.
""" """
divisors = set() divisors = set()
......
Markdown is supported
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