Exemple #1
0
def test_complies_fortran_function_with_module():
    kernel_string = """
    module my_fancy_module
    use iso_c_binding

    contains

    function my_test_function() result(time)
        use iso_c_binding
        real (c_float) :: time

        time = 42.0
    end function my_test_function

    end module my_fancy_module
    """
    kernel_name = "my_test_function"
    kernel_sources = KernelSource(kernel_string, "C")
    kernel_instance = KernelInstance(kernel_name, kernel_sources, kernel_string, [], None, None, dict(), [])

    cfunc = CFunctions(compiler="gfortran")
    func = cfunc.compile(kernel_instance)

    result = cfunc.run_kernel(func, [], (), ())

    assert np.isclose(result, 42.0)
Exemple #2
0
def test_compile(npct, subprocess):

    kernel_string = "this is a fake C program"
    kernel_name = "blabla"
    kernel_sources = KernelSource(kernel_string, "C")
    kernel_instance = KernelInstance(kernel_name, kernel_sources, kernel_string, [], None, None, dict(), [])

    cfunc = CFunctions()

    f = cfunc.compile(kernel_instance)

    print(subprocess.mock_calls)
    print(npct.mock_calls)
    print(f)

    assert len(subprocess.mock_calls) == 6
    assert npct.load_library.called == 1

    args, _ = npct.load_library.call_args_list[0]
    filename = args[0]
    print('filename=' + filename)

    # check if temporary files are cleaned up correctly
    import os.path
    assert not os.path.isfile(filename + ".cu")
    assert not os.path.isfile(filename + ".o")
    assert not os.path.isfile(filename + ".so")
Exemple #3
0
def test_compile_detects_device_code(npct, subprocess):

    kernel_string = "this code clearly contains device code __global__ kernel(float* arg){ return; }"
    kernel_name = "blabla"
    kernel_sources = KernelSource(kernel_string, "C")
    kernel_instance = KernelInstance(kernel_name, kernel_sources, kernel_string, [], None, None, dict(), [])

    cfunc = CFunctions()

    cfunc.compile(kernel_instance)

    print(subprocess.check_call.call_args_list)

    # assert the filename suffix used for source compilation is .cu
    dot_cu_used = False
    for call in subprocess.check_call.call_args_list:
        args, kwargs = call
        args = args[0]
        print(args)
        if args[0] == 'nvcc' and args[1] == '-c':
            assert args[2][-3:] == '.cu'
            dot_cu_used = True

    assert dot_cu_used
def test_compile(npct, subprocess):

    kernel_string = "this is a fake C program"
    kernel_name = "blabla"

    cfunc = CFunctions()
    f = cfunc.compile(kernel_name, kernel_string)

    print(subprocess.mock_calls)
    print(npct.mock_calls)
    print(f)

    assert len(subprocess.mock_calls) == 6
    assert npct.load_library.called == 1

    args, _ = npct.load_library.call_args_list[0]
    filename = args[0]
    print('filename=' + filename)

    #check if temporary files are cleaned up correctly
    import os.path
    assert not os.path.isfile(filename + ".cu")
    assert not os.path.isfile(filename + ".o")
    assert not os.path.isfile(filename + ".so")