diff --git a/tests/test_compile_math.py b/tests/test_compile_math.py index f27fa94..e8ff755 100644 --- a/tests/test_compile_math.py +++ b/tests/test_compile_math.py @@ -15,7 +15,7 @@ def run_command(command: list[str]) -> str: @pytest.mark.runner -def test_compile(): +def test_compile_sqrt(): test_vals = [0.0, 0.0001, 0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.28318530718, 100.0, 1000.0, 100000.0] test_vals = [100000.0] @@ -50,6 +50,79 @@ def test_compile(): #assert 'END_COM' in result +@pytest.mark.runner +def test_compile_log(): + test_vals = [0.0, 0.0001, 0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.28318530718, 100.0, 1000.0, 100000.0] + + test_vals = [100000.0] + + ret = [r for v in test_vals for r in (cp.log(variable(v)),)] + + + out = [Write(r) for r in ret] + + il, variables = compile_to_dag(out, copapy.generic_sdb) + + # run program command + il.write_com(_binwrite.Command.RUN_PROG) + + for net in ret: + assert isinstance(net, copapy.backend.Net) + add_read_command(il, variables, net) + + il.write_com(_binwrite.Command.END_COM) + + print('* Data to runner:') + il.print() + + il.to_file('bin/test.copapy') + + result = run_command(['bin/coparun', 'bin/test.copapy']) + print('* Output from runner:\n--') + print(result) + print('--') + + assert 'Return value: 1' in result + #assert 'END_COM' in result + + +@pytest.mark.runner +def test_compile_sin(): + test_vals = [0.0, 0.0001, 0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.28318530718, 100.0, 1000.0, 100000.0] + + test_vals = [100000.0] + + ret = [r for v in test_vals for r in (cp.sin(variable(v)),)] + + + out = [Write(r) for r in ret] + + il, variables = compile_to_dag(out, copapy.generic_sdb) + + # run program command + il.write_com(_binwrite.Command.RUN_PROG) + + for net in ret: + assert isinstance(net, copapy.backend.Net) + add_read_command(il, variables, net) + + il.write_com(_binwrite.Command.END_COM) + + print('* Data to runner:') + il.print() + + il.to_file('bin/test.copapy') + + result = run_command(['bin/coparun', 'bin/test.copapy']) + print('* Output from runner:\n--') + print(result) + print('--') + + assert 'Return value: 1' in result + #assert 'END_COM' in result + + if __name__ == "__main__": - #test_example() - test_compile() + #test_compile_sqrt() + #test_compile_log() + test_compile_sin() diff --git a/tools/build_stencils.bat b/tools/build_stencils.bat new file mode 100644 index 0000000..94951dc --- /dev/null +++ b/tools/build_stencils.bat @@ -0,0 +1,15 @@ +python stencils/generate_stencils.py bin/stencils.c + +echo -------------x86_64 - 64 bit----------------- + +echo - Build stencils for 64 bit... +wsl mkdir -p build/stencil_objs +wsl gcc -fno-pic -c bin/stencils.c -O3 -o build/stencil_objs/stencils.lo + +cd build\stencil_objs +wsl ar x /usr/lib/x86_64-linux-musl/libc.a sinf.lo cosf.lo tanf.lo sqrtf.lo logf.lo expf.lo logf_data.lo __tandf.lo __cosdf.lo __sindf.lo __rem_pio2f.lo __math_invalidf.lo __stack_chk_fail.lo __math_divzerof.lo __math_oflowf.lo __rem_pio2_large.lo scalbn.lo floor.lo +wsl ld -r *.lo -o ../../src/copapy/obj/stencils_x86_64_O3.o + +cd .. +cd .. +wsl objdump -d -x src/copapy/obj/stencils_x86_64_O3.o > bin/stencils_x86_64_O3.asm \ No newline at end of file