diff --git a/src/pystencils/config.py b/src/pystencils/config.py index fafc34178f38849c3ef1f71705314fc65e70989a..dec9df8bab0216347e1d42d929abfa695c0e50db 100644 --- a/src/pystencils/config.py +++ b/src/pystencils/config.py @@ -135,14 +135,9 @@ class CreateKernelConfig: """ skip_independence_check: bool = False """ - Don't check that loop iterations are independent. This is needed e.g. for - periodicity kernel, that access the field outside the iteration bounds. Use with care! - """ - check_thread_safety: bool = True - """ - Assignments are considered thread safe if read and writes only target the same locations. If this is not the case, - multithreaded optimisations will fail. The thread safety check can be deactivated to use e.g. GPUs anyway. - Use with care! + By default the assignment list is checked for read/write independence. This means fields are only written at + locations where they are read. Doing so guarantees thread safety. In some cases e.g. for + periodicity kernel, this can not be assured and does the check needs to be deactivated. Use with care! """ class DataTypeFactory: diff --git a/src/pystencils/kernel_contrains_check.py b/src/pystencils/kernel_contrains_check.py index b72e084a32df8e7f96859c61cb9c56265dcc90e7..f33434a0ece48375dc5139804285cd37801846e0 100644 --- a/src/pystencils/kernel_contrains_check.py +++ b/src/pystencils/kernel_contrains_check.py @@ -43,7 +43,6 @@ class KernelConstraintsCheck: self.fields_read = set() self.check_independence_condition = check_independence_condition self.check_double_write_condition = check_double_write_condition - self.thread_safe = True def visit(self, obj): if isinstance(obj, (AssignmentCollection, NodeCollection)): @@ -117,7 +116,9 @@ class KernelConstraintsCheck: if fai in self.field_reads: reads = tuple(self.field_reads[fai]) if len(reads) > 1 or lhs.offsets != reads[0]: - self.thread_safe = False + if self.check_independence_condition: + raise ValueError(f"Field {lhs.field.name} is written at different location than it was read. " + f"This means the resulting kernel would not be thread safe") elif isinstance(lhs, sp.Symbol): if self.scopes.is_defined_locally(lhs): raise ValueError(f"Assignments not in SSA form, multiple assignments to {lhs.name}") diff --git a/src/pystencils/kernelcreation.py b/src/pystencils/kernelcreation.py index 8dd7b90fc25431ba78c4c698bab7de4dd8b38b85..59986e8d849261d37ea4581ff6f69cbc6dfaf0a4 100644 --- a/src/pystencils/kernelcreation.py +++ b/src/pystencils/kernelcreation.py @@ -130,12 +130,6 @@ def create_domain_kernel(assignments: NodeCollection, *, config: CreateKernelCon check_double_write_condition=not config.allow_double_writes) check.visit(assignments) - if not check.thread_safe and config.check_thread_safety: - base = "Assignments are not thread safe because data is read and written on different locations." - if config.cpu_openmp: - raise ValueError(f"{base} OpenMP optimisation is not permitted in this scenario.") - if config.target == Target.GPU: - raise ValueError(f"{base} GPU target is not permitted in this case, only CPU target with single thread") assignments.bound_fields = check.fields_written assignments.rhs_fields = check.fields_read