Skip to content
Snippets Groups Projects
Select Git revision
  • 5eedf7cc3d07a53d64c507dfaab7896326733469
  • master default protected
  • v2.0-dev protected
  • zikeliml/Task-96-dotExporterForAST
  • zikeliml/124-rework-tutorials
  • fma
  • fhennig/v2.0-deprecations
  • holzer-master-patch-46757
  • 66-absolute-access-is-probably-not-copied-correctly-after-_eval_subs
  • gpu_bufferfield_fix
  • hyteg
  • vectorization_sqrt_fix
  • target_dh_refactoring
  • const_fix
  • improved_comm
  • gpu_liveness_opts
  • release/1.3.7 protected
  • release/1.3.6 protected
  • release/2.0.dev0 protected
  • release/1.3.5 protected
  • release/1.3.4 protected
  • release/1.3.3 protected
  • release/1.3.2 protected
  • release/1.3.1 protected
  • release/1.3 protected
  • release/1.2 protected
  • release/1.1.1 protected
  • release/1.1 protected
  • release/1.0.1 protected
  • release/1.0 protected
  • release/0.4.4 protected
  • last/Kerncraft
  • last/OpenCL
  • last/LLVM
  • release/0.4.3 protected
  • release/0.4.2 protected
36 results

test_interpolation.py

Blame
  • test_half_precision.py 1.32 KiB
    import pytest
    import platform
    
    import numpy as np
    import pystencils as ps
    
    
    @pytest.mark.parametrize('target', (ps.Target.CPU, ps.Target.GPU))
    def test_half_precison(target):
        if target == ps.Target.CPU:
            if not platform.machine() in ['arm64', 'aarch64']:
                pytest.xfail("skipping half precision test on non arm platform")
    
            if 'clang' not in ps.cpu.cpujit.get_compiler_config()['command']:
                pytest.xfail("skipping half precision because clang compiler is not used")
    
        if target == ps.Target.GPU:
            pytest.importorskip("cupy")
    
        dh = ps.create_data_handling(domain_size=(10, 10), default_target=target)
    
        f1 = dh.add_array("f1", values_per_cell=1, dtype=np.float16)
        dh.fill("f1", 1.0, ghost_layers=True)
        f2 = dh.add_array("f2", values_per_cell=1, dtype=np.float16)
        dh.fill("f2", 2.0, ghost_layers=True)
    
        f3 = dh.add_array("f3", values_per_cell=1, dtype=np.float16)
        dh.fill("f3", 0.0, ghost_layers=True)
    
        up = ps.Assignment(f3.center, f1.center + 2.1 * f2.center)
    
        config = ps.CreateKernelConfig(target=dh.default_target, default_dtype=np.float32)
        ast = ps.create_kernel(up, config=config)
    
        kernel = ast.compile()
    
        dh.run_kernel(kernel)
        dh.all_to_cpu()
    
        assert np.all(dh.cpu_arrays[f3.name] == 5.2)
        assert dh.cpu_arrays[f3.name].dtype == np.float16