示例#1
0
def configuration(parent_package="", top_path=None):
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils.system_info import get_info
    import numpy as np
    import dpctl

    config = Configuration("", parent_package, top_path)

    oneapi_root = environ.get("ONEAPI_ROOT", None)
    if not oneapi_root:
        raise ValueError("ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi")

    mkl_info = {
        "include_dirs": [join(oneapi_root, "mkl", "include")],
        "library_dirs": [
            join(oneapi_root, "mkl", "lib"),
            join(oneapi_root, "mkl", "lib", "intel64"),
        ],
        "libraries": [
            "mkl_sycl",
            "mkl_intel_ilp64",
            "mkl_tbb_thread",
            "mkl_core",
            "tbb",
            "iomp5",
        ],
    }

    mkl_include_dirs = mkl_info.get("include_dirs")
    mkl_library_dirs = mkl_info.get("library_dirs")
    mkl_libraries = mkl_info.get("libraries")

    pdir = dirname(__file__)
    wdir = join(pdir)

    eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]

    config.add_extension(
        name="blackscholes_usm",
        sources=[
            join(pdir, "blackscholes.pyx"),
            join(wdir, "sycl_blackscholes.cpp"),
            join(wdir, "sycl_blackscholes.hpp"),
        ],
        include_dirs=[wdir, np.get_include(), dpctl.get_include()] + mkl_include_dirs,
        libraries=["sycl"] + mkl_libraries,
        runtime_library_dirs=mkl_library_dirs,
        extra_compile_args=eca,  # + ['-O0', '-g', '-ggdb'],
        extra_link_args=["-fPIC"],
        language="c++",
    )

    config.ext_modules = cythonize(config.ext_modules, include_path=[pdir, wdir])
    return config
示例#2
0
def get_ext_modules():
    ext_modules = []

    dpnp_present = False
    try:
        import dpnp
    except:
        pass
    else:
        dpnp_present = True

    import dpctl
    import numba

    dpctl_runtime_library_dirs = []

    if IS_LIN:
        dpctl_runtime_library_dirs.append(os.path.dirname(dpctl.__file__))

    ext_dppy = Extension(
        name="numba_dppy._usm_shared_allocator_ext",
        sources=["numba_dppy/dpctl_iface/usm_shared_allocator_ext.c"],
        include_dirs=[
            numba.core.extending.include_path(),
            dpctl.get_include()
        ],
        libraries=["DPCTLSyclInterface"],
        library_dirs=[os.path.dirname(dpctl.__file__)],
        runtime_library_dirs=dpctl_runtime_library_dirs,
    )
    ext_modules += [ext_dppy]

    if dpnp_present:
        dpnp_lib_path = []
        dpnp_lib_path += [os.path.dirname(dpnp.__file__)]
        ext_dpnp_glue = Extension(
            name="numba_dppy.dpnp_glue.dpnp_fptr_interface",
            sources=["numba_dppy/dpnp_glue/dpnp_fptr_interface.pyx"],
            include_dirs=[dpnp.get_include()],
            libraries=["dpnp_backend_c"],
            library_dirs=dpnp_lib_path,
            runtime_library_dirs=dpnp_lib_path,
            language="c++",
        )
        ext_modules += [ext_dpnp_glue]

    if dpnp_present:
        return cythonize(ext_modules)
    else:
        return ext_modules
示例#3
0
def get_ext_modules():
    ext_modules = []

    try:
        import dpnp

        dpnp_present = True
    except ImportError:
        if int(os.environ.get("NUMBA_DPPY_BUILD_SKIP_NO_DPNP", 0)):
            dpnp_present = False
        else:
            raise ImportError("DPNP is not available")

    import dpctl
    import numba

    dpctl_runtime_library_dirs = []

    if IS_LIN:
        dpctl_runtime_library_dirs.append(os.path.dirname(dpctl.__file__))

    ext_dppy = Extension(
        name="numba_dppy._usm_shared_allocator_ext",
        sources=["numba_dppy/dpctl_iface/usm_shared_allocator_ext.c"],
        include_dirs=[numba.core.extending.include_path(), dpctl.get_include()],
        libraries=["DPCTLSyclInterface"],
        library_dirs=[os.path.dirname(dpctl.__file__)],
        runtime_library_dirs=dpctl_runtime_library_dirs,
    )
    ext_modules += [ext_dppy]

    if dpnp_present:
        dpnp_lib_path = []
        dpnp_lib_path += [os.path.dirname(dpnp.__file__)]
        ext_dpnp_iface = Extension(
            name="numba_dppy.dpnp_iface.dpnp_fptr_interface",
            sources=["numba_dppy/dpnp_iface/dpnp_fptr_interface.pyx"],
            include_dirs=[dpnp.get_include()],
            libraries=["dpnp_backend_c"],
            library_dirs=dpnp_lib_path,
            runtime_library_dirs=dpnp_lib_path,
            language="c++",
        )
        ext_modules += [ext_dpnp_iface]

    if dpnp_present:
        return cythonize(ext_modules)
    else:
        return ext_modules
示例#4
0
def test_get_dpcppversion():
    incl_dir = dpctl.get_include()
    libs = glob.glob(os.path.join(incl_dir, "..", "*DPCTLSyclInterface*"))
    libs = sorted(libs)
    assert len(libs) > 0
    lib = ctypes.cdll.LoadLibrary(libs[0])
    fn = lib.DPCTLService_GetDPCPPVersion
    fn.restype = ctypes.c_char_p
    fn.argtypes = []
    dpcpp_ver = fn()
    assert len(dpcpp_ver) > 0
    dpcpp_ver = dpcpp_ver.decode("utf-8")
    mkl_ver = _get_mkl_version_if_present()
    if mkl_ver is not None:
        assert mkl_ver >= dpcpp_ver
示例#5
0
# TODO remove when it will be fixed on TBB side. Details:
# In GCC versions 9 and 10 the application that uses Parallel STL algorithms may fail to compile due to incompatible
# interface changes between earlier versions of Intel TBB and oneTBB. Disable support for Parallel STL algorithms
# by defining PSTL_USE_PARALLEL_POLICIES (in GCC 9), _GLIBCXX_USE_TBB_PAR_BACKEND (in GCC 10) macro to zero
# before inclusion of the first standard header file in each translation unit.
_project_cmplr_macro += [("PSTL_USE_PARALLEL_POLICIES", "0"),
                         ("_GLIBCXX_USE_TBB_PAR_BACKEND", "0")]

try:
    """
    Detect external SYCL queue handling library
    """
    import dpctl

    _dpctrl_include += [dpctl.get_include()]
    # _dpctrl_libpath = for package build + for local build
    _dpctrl_libpath = ["$ORIGIN/../dpctl"
                       ] + [os.path.join(dpctl.get_include(), '..')]
    _dpctrl_lib = ["DPCTLSyclInterface"]
except ImportError:
    """
    Set local SYCL queue handler
    """
    _project_cmplr_macro += _project_sycl_queue_control_macro

# other OS specific
if IS_WIN:
    _project_compiler = "dpcpp"
    _project_linker = "lld-link"
    _project_cmplr_flag_sycl = []
示例#6
0
import setuptools

import dpctl

ext = setuptools.Extension(
    "_cython_api",
    ["_cython_api.pyx"],
    include_dirs=[dpctl.get_include()],
    language="c++",
)

setuptools.setup(name="_cython_api", version="0.0.0", ext_modules=[ext])
示例#7
0
    Example of using SYCL to work on usm allocations.

    See README.md for more details.
    """,
    license="Apache 2.0",
    author="Intel Corporation",
    url="https://github.com/IntelPython/dpctl",
    ext_modules=[
        Extension(
            name="blackscholes_usm",
            sources=[
                "blackscholes.pyx",
                "sycl_blackscholes.cpp",
            ],
            include_dirs=[".", np.get_include(),
                          dpctl.get_include()],
            libraries=["sycl"] + [
                "mkl_sycl",
                "mkl_intel_ilp64",
                "mkl_tbb_thread",
                "mkl_core",
                "tbb",
                "iomp5",
            ],
            runtime_library_dirs=[],
            extra_compile_args=[
                "-Wall",
                "-Wextra",
                "-fsycl",
                "-fsycl-unnamed-lambda",
            ],
else:
    raise EnvironmentError("DPNP cmake builder: " + sys.platform +
                           " not supported")
"""
Detect external SYCL queue manager
"""
_dpctrl_include_dir = "No_sycl_queue_mgr_include_dir"
_dpctrl_library_dir = "No_sycl_queue_mgr_library_dir"
_dpctrl_exists = "OFF"
try:
    """
    Detect external SYCL queue handling library
    """
    import dpctl

    _dpctrl_include_dir = str(os.path.abspath(dpctl.get_include()))
    _dpctrl_library_dir = str(
        os.path.abspath(os.path.join(dpctl.get_include(), "..")))
    _dpctrl_exists = "ON"
except ImportError:
    """
    Set local SYCL queue handler set by default in CmakeList.txt
    """
    pass
"""
Detect enabling DPNP backend tests
"""
_dpnp_backend_tests_enable = os.environ.get('DPNP_BACKEND_TESTS_ENABLE', None)
"""
CmakeList.txt based build_clib
"""
示例#9
0
def test_get_include():
    incl = dpctl.get_include()
    assert type(incl) is str
    assert incl != ""
    assert os.path.isdir(incl)
示例#10
0
from distutils.sysconfig import get_python_inc, get_config_var

IS_WIN = False
IS_MAC = False
IS_LIN = False

if 'linux' in sys.platform:
    IS_LIN = True
elif sys.platform == 'darwin':
    IS_MAC = True
elif sys.platform in ['win32', 'cygwin']:
    IS_WIN = True

try:
    import dpctl
    _dpctrl_include_dir = str(os.path.abspath(dpctl.get_include()))
    _dpctrl_library_dir = str(os.path.abspath(jp(dpctl.get_include(), "..")))
    _dpctrl_exists = "ON"
except ImportError:
    _dpctrl_include_dir = ""
    _dpctrl_library_dir = ""
    _dpctrl_exists = "OFF"


def custom_build_cmake_clib():
    root_dir = os.path.normpath(jp(os.path.dirname(__file__), ".."))
    log.info(f"Project directory is: {root_dir}")

    builder_directory = jp(root_dir, "scripts")
    abs_build_temp_path = jp(root_dir, "build", "backend")
    install_directory = jp(root_dir, "onedal")
示例#11
0
_sdl_ldflags = ["-Wl,-z,noexecstack,-z,relro,-z,now"]

# TODO remove when it will be fixed on TBB side. Details:
# In GCC versions 9 and 10 the application that uses Parallel STL algorithms may fail to compile due to incompatible
# interface changes between earlier versions of Intel TBB and oneTBB. Disable support for Parallel STL algorithms
# by defining PSTL_USE_PARALLEL_POLICIES (in GCC 9), _GLIBCXX_USE_TBB_PAR_BACKEND (in GCC 10) macro to zero
# before inclusion of the first standard header file in each translation unit.
_project_cmplr_macro += [("PSTL_USE_PARALLEL_POLICIES", "0"), ("_GLIBCXX_USE_TBB_PAR_BACKEND", "0")]

try:
    """
    Detect external SYCL queue handling library
    """
    import dpctl

    _dpctrl_include += [dpctl.get_include()]
    # _dpctrl_libpath = for package build + for local build
    _dpctrl_libpath = ["$ORIGIN/../dpctl"] + [os.path.join(dpctl.get_include(), '..')]
    _dpctrl_lib = ["DPCTLSyclInterface"]
except ImportError:
    """
    Set local SYCL queue handler
    """
    _project_cmplr_macro += _project_sycl_queue_control_macro

# other OS specific
if IS_WIN:
    _project_compiler = "dpcpp"
    _project_linker = "lld-link"
    _project_cmplr_flag_sycl = []
    _project_cmplr_flag_compatibility = []