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 1 commit
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
Next Next commit
Move SYCL devicelib to toplevel.
Signed-off-by: Vyacheslav Zakharin <vyacheslav.p.zakharin@intel.com>
  • Loading branch information
Vyacheslav Zakharin committed Mar 18, 2020
commit aa0ec6bce448bee677911ce616fd71ca8916f964
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
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# Place device libraries near the libsycl.so library in a build
# directory
# Utility project providing various functionalities for SPIR-V devices
# without native support of these functionalities.

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
)

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 +54,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 +64,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 +74,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 +83,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 +92,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 +101,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 +110,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,22 +119,26 @@ 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)
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_dependencies(sycl libsycldevice-obj libsycldevice-spv)
if (MSVC)
add_dependencies(sycld devicelib-obj devicelib-spv)
add_dependencies(sycld libsycldevice-obj libsycldevice-spv)
endif()

# Place device libraries near the libsycl.so library in an install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifdef __SYCL_DEVICE_ONLY__
#include "device_math.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
SYCL_EXTERNAL
float __attribute__((weak)) scalbnf(float x, int n) {
return __devicelib_scalbnf(x, n);
Expand Down Expand Up @@ -207,5 +211,8 @@ SYCL_EXTERNAL
float __attribute__((weak)) atanhf(float x) {
return __devicelib_atanhf(x);
}
}
#endif

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __SYCL_DEVICE_ONLY__
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifdef __SYCL_DEVICE_ONLY__
#include "device_math.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
// All exported functions in math and complex device libraries are weak
// reference. If users provide their own math or complex functions(with
// the prototype), functions in device libraries will be ignored and
Expand Down Expand Up @@ -206,5 +210,8 @@ SYCL_EXTERNAL
double __attribute__((weak)) atanh(double x) {
return __devicelib_atanh(x);
}
}
#endif

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __SYCL_DEVICE_ONLY__
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifdef __SYCL_DEVICE_ONLY__
#include "device_complex.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
SYCL_EXTERNAL
float __attribute__((weak)) cimagf(float __complex__ z) {
return __devicelib_cimagf(z);
Expand Down Expand Up @@ -134,5 +138,8 @@ float __complex__ __attribute__((weak)) __divsc3(float __a, float __b,
float __c, float __d) {
return __devicelib___divsc3(__a, __b, __c, __d);
}
}
#endif

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __SYCL_DEVICE_ONLY__
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifdef __SYCL_DEVICE_ONLY__
#include "device_complex.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
SYCL_EXTERNAL
double __attribute__((weak)) cimag(double __complex__ z) {
return __devicelib_cimag(z);
Expand Down Expand Up @@ -135,5 +139,7 @@ double __complex__ __attribute__((weak)) __divdc3(double __a, double __b,
return __devicelib___divdc3(__a, __b, __c, __d);
}

}
#endif
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __SYCL_DEVICE_ONLY__
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//==------------------------------------------------------------------------==//
#ifndef __SYCL_COMPLEX_WRAPPER_H_
#define __SYCL_COMPLEX_WRAPPER_H_
#ifndef __LIBDEVICE_DEVICE_COMPLEX_H_
#define __LIBDEVICE_DEVICE_COMPLEX_H_

// TODO: This needs to be more robust.
// clang doesn't recognize the c11 CMPLX macro, but it does have
// its own syntax extension for initializing a complex as a struct.
#ifndef CMPLX
#define CMPLX(r, i) ((double __complex__){ (double)r, (double)i })
#define CMPLX(r, i) ((double __complex__){ (double)(r), (double)(i) })
#endif
#ifndef CMPLXF
#define CMPLXF(r, i) ((float __complex__){ (float)r, (float)i })
#define CMPLXF(r, i) ((float __complex__){ (float)(r), (float)(i) })
#endif

SYCL_EXTERNAL
Expand Down Expand Up @@ -167,4 +167,4 @@ extern "C" double __complex__ __devicelib___divdc3(double a, double b,
SYCL_EXTERNAL
extern "C" float __complex__ __devicelib___divsc3(float a, float b,
float c, float d);
#endif
#endif // __LIBDEVICE_DEVICE_COMPLEX_H_
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//==------------------------------------------------------------------------==//

#ifndef __SYCL_CMATH_WRAPPER_H__
#define __SYCL_CMATH_WRAPPER_H__
#ifndef __LIBDEVICE_DEVICE_CMATH_H__
#define __LIBDEVICE_DEVICE_CMATH_H__

SYCL_EXTERNAL double __spirv_ocl_log(double);
SYCL_EXTERNAL double __spirv_ocl_sin(double);
Expand Down Expand Up @@ -353,4 +353,4 @@ extern "C" float __devicelib_logbf(float x);

SYCL_EXTERNAL
extern "C" float __devicelib_scalbnf(float x, int n);
#endif
#endif // __LIBDEVICE_DEVICE_CMATH_H__
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#ifdef __SYCL_DEVICE_ONLY__
#include "device_math.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
SYCL_EXTERNAL
double __devicelib_log(double x) {
return __spirv_ocl_log(x);
Expand Down Expand Up @@ -202,5 +205,7 @@ SYCL_EXTERNAL
double __devicelib_atanh(double x) {
return __spirv_ocl_atanh(x);
}
}
#endif
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __SYCL_DEVICE_ONLY__
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#ifdef __SYCL_DEVICE_ONLY__
#include "device_math.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
SYCL_EXTERNAL
float __devicelib_scalbnf(float x, int n) {
return __spirv_ocl_ldexp(x, n);
Expand Down Expand Up @@ -207,5 +210,7 @@ SYCL_EXTERNAL
float __devicelib_atanhf(float x) {
return __spirv_ocl_atanh(x);
}
}
#endif
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __SYCL_DEVICE_ONLY__
Loading