Skip to content

Move SPIR devicelib to toplevel. #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def do_configure(args):
sycl_dir = os.path.join(args.src_dir, "sycl")
spirv_dir = os.path.join(args.src_dir, "llvm-spirv")
xpti_dir = os.path.join(args.src_dir, "xpti")
libdevice_dir = os.path.join(args.src_dir, "libdevice")
ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers")
icd_loader_lib = os.path.join(args.obj_dir, "OpenCL-ICD-Loader", "build")
llvm_targets_to_build = 'X86'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;libdevice'
libclc_targets_to_build = ''
sycl_build_pi_cuda = 'OFF'
llvm_enable_assertions = 'ON'
Expand Down Expand Up @@ -49,10 +50,11 @@ def do_configure(args):
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti",
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;libdevice",
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
"-DSYCL_BUILD_PI_CUDA={}".format(sycl_build_pi_cuda),
Expand Down
10 changes: 10 additions & 0 deletions libdevice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Utility project providing various functionalities for SPIR-V devices
# without native support of these functionalities.

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
)

# Build libdevice for SYCL.
include(SYCLLibdevice)
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
# Place device libraries near the libsycl.so library in a build
# directory
if (WIN32)
set(binary_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(binary_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
else()
set(binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
set(binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
endif()

set(clang $<TARGET_FILE:clang>)

set(compile_opts
# suppress an error about SYCL_EXTERNAL
-Wno-sycl-strict
# for CL/__spirv/spirv_vars.hpp
-I${sycl_inc_dir})
# suppress an error about SYCL_EXTERNAL being used for
# a function with a raw pointer parameter.
-Wno-sycl-strict
# Disable warnings for the host compilation, where
# we declare all functions as 'static'.
-Wno-undefined-internal
# Force definition of CL_SYCL_LANGUAGE_VERSION, as long as
# SYCL specific code is guarded by it.
-sycl-std=2017
)

if (WIN32)
set(devicelib-obj-file ${binary_dir}/libsycl-msvc.o)
add_custom_command(OUTPUT ${devicelib-obj-file}
COMMAND ${clang} -fsycl -c
${compile_opts}
${CMAKE_CURRENT_SOURCE_DIR}/msvc_wrapper.cpp
-o ${devicelib-obj-file}
MAIN_DEPENDENCY msvc_wrapper.cpp
DEPENDS wrapper.h clang
VERBATIM)
set(devicelib-obj-file ${binary_dir}/libsycl-msvc.o)
add_custom_command(OUTPUT ${devicelib-obj-file}
COMMAND ${clang} -fsycl -c
${compile_opts}
${CMAKE_CURRENT_SOURCE_DIR}/msvc_wrapper.cpp
-o ${devicelib-obj-file}
MAIN_DEPENDENCY msvc_wrapper.cpp
DEPENDS wrapper.h device.h clang
VERBATIM)
else()
set(devicelib-obj-file ${binary_dir}/libsycl-glibc.o)
add_custom_command(OUTPUT ${devicelib-obj-file}
COMMAND ${clang} -fsycl -c
${compile_opts}
${CMAKE_CURRENT_SOURCE_DIR}/glibc_wrapper.cpp
-o ${devicelib-obj-file}
MAIN_DEPENDENCY glibc_wrapper.cpp
DEPENDS wrapper.h clang
VERBATIM)
set(devicelib-obj-file ${binary_dir}/libsycl-glibc.o)
add_custom_command(OUTPUT ${devicelib-obj-file}
COMMAND ${clang} -fsycl -c
${compile_opts}
${CMAKE_CURRENT_SOURCE_DIR}/glibc_wrapper.cpp
-o ${devicelib-obj-file}
MAIN_DEPENDENCY glibc_wrapper.cpp
DEPENDS wrapper.h device.h clang
VERBATIM)
endif()


set(devicelib-obj-complex ${binary_dir}/libsycl-complex.o)
add_custom_command(OUTPUT ${devicelib-obj-complex}
COMMAND ${clang} -fsycl -c
${compile_opts}
${CMAKE_CURRENT_SOURCE_DIR}/complex_wrapper.cpp
-o ${devicelib-obj-complex}
MAIN_DEPENDENCY complex_wrapper.cpp
DEPENDS device_complex.h clang
DEPENDS device_complex.h device.h clang
VERBATIM)

set(devicelib-obj-complex-fp64 ${binary_dir}/libsycl-complex-fp64.o)
Expand All @@ -54,7 +57,7 @@ add_custom_command(OUTPUT ${devicelib-obj-complex-fp64}
${CMAKE_CURRENT_SOURCE_DIR}/complex_wrapper_fp64.cpp
-o ${devicelib-obj-complex-fp64}
MAIN_DEPENDENCY complex_wrapper_fp64.cpp
DEPENDS device_complex.h clang
DEPENDS device_complex.h device.h clang
VERBATIM)

set(devicelib-obj-cmath ${binary_dir}/libsycl-cmath.o)
Expand All @@ -64,7 +67,7 @@ add_custom_command(OUTPUT ${devicelib-obj-cmath}
${CMAKE_CURRENT_SOURCE_DIR}/cmath_wrapper.cpp
-o ${devicelib-obj-cmath}
MAIN_DEPENDENCY cmath_wrapper.cpp
DEPENDS device_complex.h clang
DEPENDS device_math.h device.h clang
VERBATIM)

set(devicelib-obj-cmath-fp64 ${binary_dir}/libsycl-cmath-fp64.o)
Expand All @@ -74,7 +77,7 @@ add_custom_command(OUTPUT ${devicelib-obj-cmath-fp64}
${CMAKE_CURRENT_SOURCE_DIR}/cmath_wrapper_fp64.cpp
-o ${devicelib-obj-cmath-fp64}
MAIN_DEPENDENCY cmath_wrapper_fp64.cpp
DEPENDS device_math.h clang
DEPENDS device_math.h device.h clang
VERBATIM)

add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-cassert.spv
Expand All @@ -83,7 +86,7 @@ add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-cassert.spv
${CMAKE_CURRENT_SOURCE_DIR}/fallback-cassert.cpp
-o ${binary_dir}/libsycl-fallback-cassert.spv
MAIN_DEPENDENCY fallback-cassert.cpp
DEPENDS wrapper.h clang llvm-spirv
DEPENDS wrapper.h device.h clang llvm-spirv
VERBATIM)

add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-complex.spv
Expand All @@ -92,7 +95,7 @@ add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-complex.spv
${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex.cpp
-o ${binary_dir}/libsycl-fallback-complex.spv
MAIN_DEPENDENCY fallback-complex.cpp
DEPENDS device_math.h device_complex.h clang llvm-spirv
DEPENDS device_math.h device_complex.h device.h clang llvm-spirv
VERBATIM)

add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-complex-fp64.spv
Expand All @@ -101,7 +104,7 @@ add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-complex-fp64.spv
${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex-fp64.cpp
-o ${binary_dir}/libsycl-fallback-complex-fp64.spv
MAIN_DEPENDENCY fallback-complex-fp64.cpp
DEPENDS device_math.h device_complex.h clang llvm-spirv
DEPENDS device_math.h device_complex.h device.h clang llvm-spirv
VERBATIM)

add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-cmath.spv
Expand All @@ -110,7 +113,7 @@ add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-cmath.spv
${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath.cpp
-o ${binary_dir}/libsycl-fallback-cmath.spv
MAIN_DEPENDENCY fallback-cmath.cpp
DEPENDS device_math.h clang llvm-spirv
DEPENDS device_math.h device.h clang llvm-spirv
VERBATIM)

add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-cmath-fp64.spv
Expand All @@ -119,30 +122,31 @@ add_custom_command(OUTPUT ${binary_dir}/libsycl-fallback-cmath-fp64.spv
${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath-fp64.cpp
-o ${binary_dir}/libsycl-fallback-cmath-fp64.spv
MAIN_DEPENDENCY fallback-cmath-fp64.cpp
DEPENDS device_math.h clang llvm-spirv
DEPENDS device_math.h device.h clang llvm-spirv
VERBATIM)

add_custom_target(devicelib-obj DEPENDS ${devicelib-obj-file}
${devicelib-obj-complex}
${devicelib-obj-complex-fp64}
${devicelib-obj-cmath}
${devicelib-obj-cmath-fp64})
add_custom_target(devicelib-spv DEPENDS ${binary_dir}/libsycl-fallback-cassert.spv
${binary_dir}/libsycl-fallback-complex.spv
${binary_dir}/libsycl-fallback-complex-fp64.spv
${binary_dir}/libsycl-fallback-cmath.spv
${binary_dir}/libsycl-fallback-cmath-fp64.spv)
add_dependencies(sycl devicelib-obj devicelib-spv)
if (MSVC)
add_dependencies(sycld devicelib-obj devicelib-spv)
endif()
add_custom_target(libsycldevice-obj DEPENDS
${devicelib-obj-file}
${devicelib-obj-complex}
${devicelib-obj-complex-fp64}
${devicelib-obj-cmath}
${devicelib-obj-cmath-fp64}
)
add_custom_target(libsycldevice-spv DEPENDS
${binary_dir}/libsycl-fallback-cassert.spv
${binary_dir}/libsycl-fallback-complex.spv
${binary_dir}/libsycl-fallback-complex-fp64.spv
${binary_dir}/libsycl-fallback-cmath.spv
${binary_dir}/libsycl-fallback-cmath-fp64.spv
)
add_custom_target(libsycldevice DEPENDS libsycldevice-obj libsycldevice-spv)

# Place device libraries near the libsycl.so library in an install
# directory as well
if (WIN32)
set(install_dest bin)
set(install_dest bin)
else()
set(install_dest lib${LLVM_LIBDIR_SUFFIX})
set(install_dest lib${LLVM_LIBDIR_SUFFIX})
endif()

install(FILES ${devicelib-obj-file}
Expand All @@ -156,4 +160,4 @@ install(FILES ${devicelib-obj-file}
${devicelib-obj-cmath-fp64}
${binary_dir}/libsycl-fallback-cmath-fp64.spv
DESTINATION ${install_dest}
COMPONENT sycl)
COMPONENT libsycldevice)
130 changes: 130 additions & 0 deletions libdevice/cmath_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//==--- cmath_wrapper.cpp - wrappers for C math library functions ----------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "device.h"
#include "device_math.h"

DEVICE_EXTERN_C
float scalbnf(float x, int n) { return __devicelib_scalbnf(x, n); }

DEVICE_EXTERN_C
float logf(float x) { return __devicelib_logf(x); }

DEVICE_EXTERN_C
float expf(float x) { return __devicelib_expf(x); }

DEVICE_EXTERN_C
float frexpf(float x, int *exp) { return __devicelib_frexpf(x, exp); }

DEVICE_EXTERN_C
float ldexpf(float x, int exp) { return __devicelib_ldexpf(x, exp); }

DEVICE_EXTERN_C
float log10f(float x) { return __devicelib_log10f(x); }

DEVICE_EXTERN_C
float modff(float x, float *intpart) { return __devicelib_modff(x, intpart); }

DEVICE_EXTERN_C
float exp2f(float x) { return __devicelib_exp2f(x); }

DEVICE_EXTERN_C
float expm1f(float x) { return __devicelib_expm1f(x); }

DEVICE_EXTERN_C
int ilogbf(float x) { return __devicelib_ilogbf(x); }

DEVICE_EXTERN_C
float log1pf(float x) { return __devicelib_log1pf(x); }

DEVICE_EXTERN_C
float log2f(float x) { return __devicelib_log2f(x); }

DEVICE_EXTERN_C
float logbf(float x) { return __devicelib_logbf(x); }

DEVICE_EXTERN_C
float sqrtf(float x) { return __devicelib_sqrtf(x); }

DEVICE_EXTERN_C
float cbrtf(float x) { return __devicelib_cbrtf(x); }

DEVICE_EXTERN_C
float hypotf(float x, float y) { return __devicelib_hypotf(x, y); }

DEVICE_EXTERN_C
float erff(float x) { return __devicelib_erff(x); }

DEVICE_EXTERN_C
float erfcf(float x) { return __devicelib_erfcf(x); }

DEVICE_EXTERN_C
float tgammaf(float x) { return __devicelib_tgammaf(x); }

DEVICE_EXTERN_C
float lgammaf(float x) { return __devicelib_lgammaf(x); }

DEVICE_EXTERN_C
float fmodf(float x, float y) { return __devicelib_fmodf(x, y); }

DEVICE_EXTERN_C
float remainderf(float x, float y) { return __devicelib_remainderf(x, y); }

DEVICE_EXTERN_C
float remquof(float x, float y, int *q) { return __devicelib_remquof(x, y, q); }

DEVICE_EXTERN_C
float nextafterf(float x, float y) { return __devicelib_nextafterf(x, y); }

DEVICE_EXTERN_C
float fdimf(float x, float y) { return __devicelib_fdimf(x, y); }

DEVICE_EXTERN_C
float fmaf(float x, float y, float z) { return __devicelib_fmaf(x, y, z); }

DEVICE_EXTERN_C
float sinf(float x) { return __devicelib_sinf(x); }

DEVICE_EXTERN_C
float cosf(float x) { return __devicelib_cosf(x); }

DEVICE_EXTERN_C
float tanf(float x) { return __devicelib_tanf(x); }

DEVICE_EXTERN_C
float powf(float x, float y) { return __devicelib_powf(x, y); }

DEVICE_EXTERN_C
float acosf(float x) { return __devicelib_acosf(x); }

DEVICE_EXTERN_C
float asinf(float x) { return __devicelib_asinf(x); }

DEVICE_EXTERN_C
float atanf(float x) { return __devicelib_atanf(x); }

DEVICE_EXTERN_C
float atan2f(float x, float y) { return __devicelib_atan2f(x, y); }

DEVICE_EXTERN_C
float coshf(float x) { return __devicelib_coshf(x); }

DEVICE_EXTERN_C
float sinhf(float x) { return __devicelib_sinhf(x); }

DEVICE_EXTERN_C
float tanhf(float x) { return __devicelib_tanhf(x); }

DEVICE_EXTERN_C
float acoshf(float x) { return __devicelib_acoshf(x); }

DEVICE_EXTERN_C
float asinhf(float x) { return __devicelib_asinhf(x); }

DEVICE_EXTERN_C
float atanhf(float x) { return __devicelib_atanhf(x); }
Loading