-
Notifications
You must be signed in to change notification settings - Fork 789
[SYCL][COMPAT] SYCLcompat dim and defs headers #9976
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d80109e
[SYCL][COMPAT] Dim3 and macro definitions added.
Alcpz 3bfd299
[SYCL][COMPAT] Fix wrong name for defs.hpp in syclcompat.hpp
Alcpz 9dbe877
[SYCL][COMPAT] Improved some comments and file headers
Alcpz 6c0c092
[SYCL][COMPAT] Refactored outside of sycl include path
Alcpz ea4902f
[SYCL][COMPAT] Improved defs test suite name
Alcpz f36ff23
[SYCL][COMPAT] Added dependency to SYCLUnitTests target
Alcpz ac97108
[SYCL][COMPAT] Improved Windows library unittests
Alcpz a053235
[SYCL][COMPAT] Fixed missing libraries when linking unittests
Alcpz 2376acc
[SYCL][COMPAT] Formatting
joeatodd 3310dad
Merge remote-tracking branch 'intel/sycl' into Alcpz/impl-SYCLcompat
Alcpz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# add_sycl_library_unittest(test_suite_name sycl_extra_flags | ||
# file1.cpp file2.cpp ...) | ||
# | ||
# sycl_extra_flags: Clang extra compiler flags, e.g. | ||
# "-fsycl-unnamed-lambdas;-fsycl-device-code-split" | ||
# | ||
# Will compile the list of files together using clang. | ||
# Produces a single binary using all the .cpp files | ||
# named 'test_suite_name' at ${CMAKE_CURRENT_BINARY_DIR}. | ||
macro(add_sycl_library_unittest test_suite_name) | ||
cmake_parse_arguments(ARG | ||
"" | ||
"" | ||
"SYCL_EXTRA_FLAGS;SOURCES" | ||
${ARGN}) | ||
|
||
set(CXX_COMPILER clang++) | ||
if(MSVC) | ||
set(CXX_COMPILER clang-cl.exe) | ||
endif() | ||
|
||
set(DEVICE_COMPILER_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/${CXX_COMPILER}) | ||
set(_OUTPUT_BIN ${CMAKE_CURRENT_BINARY_DIR}/${test_suite_name}Tests) | ||
set(_TESTS_TARGET ${test_suite_name}Tests) | ||
set(_BIN_TARGET ${_TESTS_TARGET}_bin) | ||
set(_LLVM_TARGET_DEPENDENCIES | ||
"llvm_gtest_main;llvm_gtest;LLVMTestingSupport;LLVMSupport;LLVMDemangle") | ||
|
||
foreach(_lib ${_LLVM_TARGET_DEPENDENCIES}) | ||
list(APPEND _LIBRARIES $<TARGET_LINKER_FILE:${_lib}>) | ||
endforeach() | ||
|
||
# Enable exception handling on Windows | ||
# Appends extra libraries not available in LIBPATH | ||
if(WIN32) | ||
set(_INTERNAL_LINKER_FLAGS /link /SUBSYSTEM:CONSOLE) | ||
list(APPEND _INTERNAL_EXTRA_FLAGS "/EHs") | ||
list(APPEND _LIBRARIES $<TARGET_LINKER_FILE:sycl>) | ||
list(APPEND _LIBRARIES ${LLVM_LIBRARY_OUTPUT_INTDIR}/sycl-devicelib-host.lib) | ||
endif() | ||
|
||
if(UNIX) | ||
foreach(_lib "pthread" "dl" "ncurses") | ||
list(APPEND _LIBRARIES "-l${_lib}") | ||
endforeach() | ||
endif() | ||
|
||
get_target_property(GTEST_INCLUDES llvm_gtest INCLUDE_DIRECTORIES) | ||
foreach(_dir ${GTEST_INCLUDES}) | ||
# Avoid -I when _dir contains an empty generator expression. | ||
list(APPEND INCLUDE_COMPILER_STRING "$<$<BOOL:${_dir}>:-I${_dir}>") | ||
endforeach() | ||
|
||
add_custom_target(${_BIN_TARGET} | ||
COMMAND ${DEVICE_COMPILER_EXECUTABLE} -fsycl ${ARG_SOURCES} | ||
-o ${_OUTPUT_BIN} | ||
${ARG_SYCL_EXTRA_FLAGS} | ||
${_INTERNAL_EXTRA_FLAGS} | ||
${INCLUDE_COMPILER_STRING} | ||
${_LIBRARIES} | ||
${_INTERNAL_LINKER_FLAGS} | ||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${_TESTS_TARGET} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMAND_EXPAND_LISTS) | ||
|
||
add_dependencies(${_BIN_TARGET} sycl) | ||
foreach(_lib ${ARG_LIBRARIES}) | ||
add_dependencies(${_BIN_TARGET} ${_TARGET_DEPENDENCIES}) | ||
endforeach() | ||
|
||
add_dependencies(SYCLUnitTests ${_BIN_TARGET}) | ||
|
||
add_executable(${_TESTS_TARGET} IMPORTED GLOBAL) | ||
set_target_properties(${_TESTS_TARGET} PROPERTIES | ||
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
# Check target for Linux | ||
if (UNIX) | ||
add_custom_target(check-${test_suite_name} | ||
${CMAKE_COMMAND} -E | ||
env LD_LIBRARY_PATH="${CMAKE_BINARY_DIR}/lib" | ||
env SYCL_CONFIG_FILE_NAME=null.cfg | ||
env SYCL_DEVICELIB_NO_FALLBACK=1 | ||
env SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache" | ||
${CMAKE_CURRENT_BINARY_DIR}/${_TESTS_TARGET} | ||
) | ||
add_dependencies(check-${test_suite_name} ${_BIN_TARGET}) | ||
add_dependencies(check-sycl-unittests-libs check-${test_suite_name}) | ||
endif() | ||
|
||
endmacro() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*************************************************************************** | ||
* | ||
* Copyright (C) Codeplay Software Ltd. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SYCLcompat | ||
* | ||
* syclcompat.hpp | ||
* | ||
* Description: | ||
* Main include header for SYCLcompat | ||
**************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <syclcompat/syclcompat.hpp> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*************************************************************************** | ||
* | ||
* Copyright (C) Codeplay Software Ltd. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SYCLcompat | ||
* | ||
* defs.hpp | ||
* | ||
* Description: | ||
* helper aliases and definitions for SYCLcompat | ||
* | ||
**************************************************************************/ | ||
|
||
// The original source was under the license below: | ||
//==---- dpct.hpp ---------------------------------*- C++ -*----------------==// | ||
// | ||
// Copyright (C) Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
template <class... Args> class sycl_compat_kernel_name; | ||
template <int Arg> class sycl_compat_kernel_scalar; | ||
|
||
#define __sycl_compat_align__(n) alignas(n) | ||
#define __sycl_compat_inline__ __inline__ __attribute__((always_inline)) | ||
|
||
#define __sycl_compat_noinline__ __attribute__((noinline)) | ||
|
||
#define SYCL_COMPAT_COMPATIBILITY_TEMP (600) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*************************************************************************** | ||
* | ||
* Copyright (C) Codeplay Software Ltd. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SYCLcompat | ||
* | ||
* dims.hpp | ||
* | ||
* Description: | ||
* dim3 functionality for SYCLcompat | ||
**************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <tuple> | ||
|
||
#include <sycl/range.hpp> | ||
|
||
namespace syclcompat { | ||
|
||
class dim3 { | ||
public: | ||
const size_t x, y, z; | ||
|
||
dim3(const sycl::range<3> &r) : x(r[2]), y(r[1]), z(r[0]) {} | ||
|
||
dim3(const sycl::range<2> &r) : x(r[1]), y(r[0]), z(1) {} | ||
|
||
dim3(const sycl::range<1> &r) : x(r[0]), y(1), z(1) {} | ||
|
||
constexpr dim3(size_t x, size_t y = 1, size_t z = 1) : x(x), y(y), z(z) {} | ||
|
||
constexpr size_t size() const { return x * y * z; } | ||
|
||
operator sycl::range<3>() const { return sycl::range<3>(z, y, x); } | ||
operator sycl::range<2>() const { | ||
if (z != 1) | ||
throw std::invalid_argument( | ||
"Attempting to convert a 3D dim3 into sycl::range<2>"); | ||
return sycl::range<2>(y, x); | ||
} | ||
operator sycl::range<1>() const { | ||
if (z != 1 || y != 1) | ||
throw std::invalid_argument( | ||
"Attempting to convert a 2D or 3D dim3 into sycl::range<1>"); | ||
return sycl::range<1>(x); | ||
} | ||
}; // namespace dim3 | ||
|
||
inline dim3 operator*(const dim3 &a, const dim3 &b) { | ||
return dim3{a.x * b.x, a.y * b.y, a.z * b.z}; | ||
} | ||
|
||
inline dim3 operator+(const dim3 &a, const dim3 &b) { | ||
return dim3{a.x + b.x, a.y + b.y, a.z + b.z}; | ||
} | ||
|
||
inline dim3 operator-(const dim3 &a, const dim3 &b) { | ||
return dim3{a.x - b.x, a.y - b.y, a.z - b.z}; | ||
} | ||
|
||
} // namespace syclcompat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*************************************************************************** | ||
* | ||
* Copyright (C) Codeplay Software Ltd. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SYCLcompat | ||
* | ||
* syclcompat.hpp | ||
* | ||
* Description: | ||
* Main include internal header for SYCLcompat | ||
**************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <syclcompat/defs.hpp> | ||
#include <syclcompat/dims.hpp> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright (C) Codeplay Software Ltd. | ||
# | ||
# 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 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
# | ||
# SYCLcompat | ||
# | ||
|
||
set(SYCL_EXTRA_FLAGS "-fsycl-unnamed-lambda;-fsycl-device-code-split=per_kernel") | ||
|
||
if (UNIX) | ||
add_custom_target(check-syclcompat) | ||
add_dependencies(check-sycl-unittests check-syclcompat) | ||
endif() | ||
|
||
add_sycl_library_unittest(syclcompat-base | ||
SYCL_EXTRA_FLAGS | ||
${SYCL_EXTRA_FLAGS} | ||
SOURCES | ||
Dim.cpp | ||
Defs.cpp) | ||
|
||
if (UNIX) | ||
add_dependencies(check-syclcompat check-syclcompat-base) | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.