Skip to content
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

Linking to oneDPL adds -fsycl compile flag to all files in the target #1424

Open
al42and opened this issue Feb 27, 2024 · 0 comments
Open

Linking to oneDPL adds -fsycl compile flag to all files in the target #1424

al42and opened this issue Feb 27, 2024 · 0 comments

Comments

@al42and
Copy link

al42and commented Feb 27, 2024

With a typical CMake project, we use target_link_libraries(${PROJECT_NAME} PRIVATE oneDPL) to properly link the oneDPL. However, it adds -fsycl to the compiler flags for all source files in ${PROJECT_NAME}. This is problematic, since not all files might need to be compiled with SYCL support, and might contain unsupported features.

Example project

  • main.cpp:
#include <iostream>

__vectorcall inline void do_simd() {
    //...
}
void do_onedpl();

int main() {
    do_simd();
    do_onedpl();
}
  • onedpl.cpp:
#include <iostream>
#include <vector>
#include <oneapi/dpl/algorithm>
#include <oneapi/dpl/execution>

void do_onedpl() {
    std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    auto policy = oneapi::dpl::execution::dpcpp_default;
    
    int sum = oneapi::dpl::reduce(policy, vec.begin(), vec.end(), 0);

    std::cout << "Sum: " << sum << std::endl;
}
  • CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(MyOneDPLProject)

set(CMAKE_CXX_STANDARD 17)

find_package(oneDPL REQUIRED)

add_executable(${PROJECT_NAME} main.cpp onedpl.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE oneDPL)

With the project above, we are getting warning about an attribute incompatible with SPIR-V targets, even though main.cpp has nothing to do with device code:

$ rm -rf build/ && cmake -DCMAKE_CXX_COMPILER=icpx -S. -Bbuild/ -DoneDPL_DIR=/opt/intel/oneapi/dpl/latest/lib/cmake/oneDPL/ && cmake --build build/
[...]
[ 33%] Building CXX object CMakeFiles/MyOneDPLProject.dir/main.cpp.o
/home/aland/sycl_tests/onedpl_cmake/main.cpp:3:1: warning: '__vectorcall' calling convention is not supported for this target [-Wignored-attributes]
    3 | __vectorcall inline void do_simd() {
      | ^
1 warning generated.

Possible workaround

Client code can manually remove the flag from oneDPL interface and add it manually to the desired targets:

get_target_property(_onedpl_compile_options oneDPL INTERFACE_COMPILE_OPTIONS)
list(REMOVE_ITEM _onedpl_compile_options "-fsycl")
set_target_properties(oneDPL PROPERTIES INTERFACE_COMPILE_OPTIONS "${_onedpl_compile_options}")
set_property(SOURCE onedpl.cpp APPEND PROPERTY COMPILE_OPTIONS -fsycl)

Or do the opposite and manually remove the flag from some of the files. This approach, though, is quite ugly and fragile.

Another option is to move all oneDPL-related files to a separate OBJECT target, but this will require significant changes to the application's build system.

Proposed solution

While the current behavior is reasonable for most cases, sometimes application developers might want to have better control over compilation options and want to only compile certain files with SYCL enabled, given the extra limitations. It would be convenient to have a way to control whether -fsycl flag is added to oneDPL's INTERFACE, given how much this flag affects the overall compiler behavior (compared to, e.g., just another build directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant