Skip to content

[SYCL][PI] Move files to libpi folder #3679

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 13 additions & 2 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,31 @@ option(SYCL_BUILD_PI_CUDA
# Configure SYCL version macro
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(sycl_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/source)
set(sycl_plugin_dir ${CMAKE_CURRENT_SOURCE_DIR}/plugins)
set(sycl_plugin_dir ${CMAKE_CURRENT_SOURCE_DIR}/libpi/plugins)
string(TIMESTAMP __SYCL_COMPILER_VERSION "%Y%m%d")
set(version_header "${sycl_inc_dir}/CL/sycl/version.hpp")
configure_file("${version_header}.in" "${version_header}")

# Location of PI files
set(pi_include_dir ${CMAKE_CURRENT_SOURCE_DIR}/libpi/include)
set(pi_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/libpi/src)

# Copy SYCL headers from sources to build directory
add_custom_target(pi-headers ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${pi_include_dir} ${SYCL_INCLUDE_BUILD_DIR}
COMMENT "Copying PI headers ...")

# Copy SYCL headers from sources to build directory
add_custom_target(sycl-headers ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${sycl_inc_dir}/sycl ${SYCL_INCLUDE_BUILD_DIR}/sycl
COMMAND ${CMAKE_COMMAND} -E copy_directory ${sycl_inc_dir}/CL ${SYCL_INCLUDE_BUILD_DIR}/sycl/CL
COMMENT "Copying SYCL headers ...")
add_dependencies(sycl-headers pi-headers)

# Copy SYCL headers from sources to install directory
install(DIRECTORY "${sycl_inc_dir}/sycl" DESTINATION ${SYCL_INCLUDE_DEPLOY_DIR} COMPONENT sycl-headers)
install(DIRECTORY "${sycl_inc_dir}/CL" DESTINATION ${SYCL_INCLUDE_DEPLOY_DIR}/sycl COMPONENT sycl-headers)
install(DIRECTORY "${pi_include_dir}/." DESTINATION ${SYCL_INCLUDE_DEPLOY_DIR} COMPONENT sycl-headers)

set(SYCL_RT_LIBS sycl)
if (MSVC)
Expand Down Expand Up @@ -213,7 +224,7 @@ option(SYCL_INCLUDE_TESTS
${LLVM_INCLUDE_TESTS})

# Plugin Library
add_subdirectory( plugins )
include(libpi.cmake)

add_subdirectory(tools)

Expand Down
5 changes: 4 additions & 1 deletion sycl/cmake/modules/AddSYCLUnitTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ macro(add_sycl_unittest test_dirname link_variant)
target_include_directories(${test_dirname}
PRIVATE SYSTEM
${sycl_inc_dir}
${pi_include_dir}
${SYCL_SOURCE_DIR}/source/
${SYCL_SOURCE_DIR}/unittests/
)
Expand Down Expand Up @@ -92,8 +93,10 @@ macro(add_sycl_unittest_with_device test_dirname link_variant)
endif()

if ("${link_variant}" MATCHES "OBJECT")
# TODO PI integration should be fixed
# once add_sycl_executable supports target_link_libraries
add_sycl_executable(${test_dirname}
OPTIONS -nolibsycl ${COMMON_OPTS} ${LLVM_PTHREAD_LIB} ${TERMINFO_LIB}
OPTIONS -nolibsycl ${COMMON_OPTS} ${LLVM_PTHREAD_LIB} ${TERMINFO_LIB} -I "${pi_include_dir}"
SOURCES ${ARGN} $<TARGET_OBJECTS:${sycl_obj_target}>
LIBRARIES gtest_main gtest LLVMSupport LLVMTestingSupport OpenCL ${EXTRA_LIBS}
DEPENDANTS SYCLUnitTests)
Expand Down
6 changes: 3 additions & 3 deletions sycl/doc/PluginInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ SYCL_PI_TRACE=-1 lists all PI Traces above and more debug messages.

#### Plugin binary interface
Plugins should implement all the Interface APIs required for the PI Version
it supports. There is [pi.def](../include/CL/sycl/detail/pi.def)/
[pi.h](../include/CL/sycl/detail/pi.h) file listing all PI API names that can be
it supports. There is [pi.def](../libpi/include/pi/pi.def)/
[pi.h](../libpi/include/pi/pi.h) file listing all PI API names that can be
called by the specific version of Plugin Interface.
It exports a function - "piPluginInit" that returns the plugin details and
function pointer table containing the list of pointers to implemented Interface
Expand Down Expand Up @@ -149,7 +149,7 @@ into
- **Interoperability API** which allows interoperability with underlying
runtimes such as OpenCL.

See [pi.h](../include/CL/sycl/detail/pi.h) header for the full list and
See [pi.h](../include/pi/pi.h) header for the full list and
descriptions of PI APIs.

### The Core OpenCL-based PI APIs
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <CL/sycl/detail/backend_traits.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/pi.h>
#include <CL/sycl/detail/pi.hpp>
#include <pi/pi.h>
#include <CL/sycl/detail/pi_sycl.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/event.hpp>
#include <CL/sycl/exception.hpp>
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/backend/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <CL/sycl/backend_types.hpp>
#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/detail/pi_sycl.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/event.hpp>
#include <CL/sycl/queue.hpp>
Expand Down Expand Up @@ -58,4 +59,4 @@ struct interop<backend::cuda, accessor<DataT, Dimensions, AccessMode,
};

} // namespace sycl
} // namespace cl
} // __SYCL_INLINE_NAMESPACE(cl)
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/detail/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#pragma once
#include <CL/sycl/detail/type_traits.hpp>
#include <CL/sycl/exception.hpp>
#include <pi/pi.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pity that we had to include pi.h here to use PI_INVALID_VALUE in the function that has no dependency on plug-in interface.

  __SYCL_ALWAYS_INLINE void check_dimension(int dimension) const {
#ifndef __SYCL_DEVICE_ONLY__
    if (dimension >= dimensions || dimension < 0) {
      throw cl::sycl::invalid_parameter_error("Index out of range",
                                              PI_INVALID_VALUE);
    }
#endif
    (void)dimension;
  }

@romanovvlad, @smaslov-intel, I think there should be PI-independent error codes to report errors for cases like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such error codes getting introduced in SYCL2020


#include <functional>
#include <stdexcept>

Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/device_binary_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once

#include <CL/sycl/detail/os_util.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/detail/pi_sycl.hpp>

#include <memory>

Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <CL/sycl/access/access.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/detail/pi_sycl.hpp>
#include <CL/sycl/detail/type_traits.hpp>

#include <memory>
Expand Down
12 changes: 12 additions & 0 deletions sycl/include/CL/sycl/detail/pi_sycl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//==---------------- pi_sycl.hpp - SYCL wrapper for PI ---------*- C++ -*---==//
//
// 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
//
// ===--------------------------------------------------------------------=== //

#pragma once

#include <CL/sycl/detail/defines.hpp>
#include <pi/pi.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the motivation to have this wrapper.
Do we have a dependency on defines.hpp from pi.hpp? If so, I think we should remove such tight coupling between plug-in interface and the rest of the sycl runtime library.

1 change: 1 addition & 0 deletions sycl/include/CL/sycl/detail/property_list_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/property_helper.hpp>
#include <CL/sycl/detail/stl_type_traits.hpp>
#include <pi/pi.h>

#include <bitset>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/sycl_mem_obj_i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/detail/pi_sycl.hpp>
#include <CL/sycl/stl.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/pi.h>
#include <CL/sycl/stl.hpp>
#include <pi/pi.h>

#include <exception>

Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/info/info_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma once

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/detail/pi_sycl.hpp>
#include <CL/sycl/id.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/interop_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <CL/sycl/detail/accessor_impl.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/detail/pi_sycl.hpp>

#include <memory>

Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/pi.h>
#include <pi/pi.h>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/stl.hpp>

Expand Down
4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/kernel_bundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/kernel_desc.hpp>
#include <CL/sycl/detail/pi.h>
#include <CL/sycl/detail/pi.hpp>
#include <pi/pi.h>
#include <CL/sycl/detail/pi_sycl.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/kernel.hpp>

Expand Down
1 change: 1 addition & 0 deletions sycl/libpi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(libpi/plugins)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ struct _pi_plugin {
char *Targets;
struct FunctionPointers {
#define _PI_API(api) decltype(::api) *api;
#include <CL/sycl/detail/pi.def>
#include <pi/pi.def>
} PiFunctionTable;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/os_util.hpp>
#include <CL/sycl/detail/pi.h>
#include <pi/pi.h>

#include <cassert>
#include <cstdint>
Expand All @@ -41,7 +41,7 @@ namespace detail {

enum class PiApiKind {
#define _PI_API(api) api,
#include <CL/sycl/detail/pi.def>
#include <pi/pi.def>
};
class plugin;
namespace pi {
Expand Down Expand Up @@ -162,7 +162,7 @@ template <PiApiKind PiApiOffset> struct PiFuncInfo {};
return MPlugin.PiFunctionTable.api; \
} \
};
#include <CL/sycl/detail/pi.def>
#include <pi/pi.def>

/// Emits an XPTI trace before a PI API call is made
/// \param FName The name of the PI API call
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//==------------ cuda_definitions.hpp - SYCL CUDA backend ------------------==//
//==------------ pi_cuda.h - PI CUDA backend ------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#pragma once
#include <CL/sycl/backend_types.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/stl.hpp>
#include <detail/plugin_printers.hpp>
#include <pi/pi.hpp>
#include <memory>
#include <mutex>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ set_target_properties(
)

add_library(pi_cuda SHARED
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
"${sycl_inc_dir}/CL/sycl/detail/pi.hpp"
"${pi_include_dir}/pi/pi.h"
"${pi_include_dir}/pi/pi.hpp"
"pi_cuda.hpp"
"pi_cuda.cpp"
)
Expand All @@ -29,6 +29,7 @@ set_target_properties(pi_cuda PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(pi_cuda
PRIVATE
${sycl_inc_dir}
${pi_include_dir}
)

target_link_libraries(pi_cuda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
///
/// \ingroup sycl_pi_cuda

#include <CL/sycl/detail/cuda_definitions.hpp>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <pi/pi.hpp>
#include <pi/pi_cuda.h>
#include <pi_cuda.hpp>

#include <algorithm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,30 @@
#ifndef PI_CUDA_HPP
#define PI_CUDA_HPP

#include "CL/sycl/detail/pi.h"
#include <pi/pi.h>

#include <array>
#include <atomic>
#include <cassert>
#include <cstring>
#include <cuda.h>
#include <functional>
#include <limits>
#include <mutex>
#include <numeric>
#include <stdint.h>
#include <string>
#include <vector>
#include <functional>
#include <mutex>

extern "C" {

/// \cond INGORE_BLOCK_IN_DOXYGEN
pi_result cuda_piContextRetain(pi_context );
pi_result cuda_piContextRelease(pi_context );
pi_result cuda_piDeviceRelease(pi_device );
pi_result cuda_piDeviceRetain(pi_device );
pi_result cuda_piProgramRetain(pi_program );
pi_result cuda_piProgramRelease(pi_program );
pi_result cuda_piContextRetain(pi_context);
pi_result cuda_piContextRelease(pi_context);
pi_result cuda_piDeviceRelease(pi_device);
pi_result cuda_piDeviceRetain(pi_device);
pi_result cuda_piProgramRetain(pi_program);
pi_result cuda_piProgramRelease(pi_program);
pi_result cuda_piQueueRelease(pi_queue);
pi_result cuda_piQueueRetain(pi_queue);
pi_result cuda_piMemRetain(pi_mem);
Expand Down Expand Up @@ -511,7 +512,7 @@ struct _pi_program {

pi_result set_binary(const char *binary, size_t binarySizeInBytes);

pi_result build_program(const char* build_options);
pi_result build_program(const char *build_options);

pi_context get_context() const { return context_; };

Expand Down Expand Up @@ -632,8 +633,7 @@ struct _pi_kernel {
pi_context ctxt)
: _pi_kernel{func, nullptr, name, program, ctxt} {}

~_pi_kernel()
{
~_pi_kernel() {
cuda_piProgramRelease(program_);
cuda_piContextRelease(context_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ target_include_directories(LevelZeroLoader-Headers


include_directories("${sycl_inc_dir}")
include_directories("${pi_include_dir}")
Comment on lines 99 to +100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include_directories("${sycl_inc_dir}")
include_directories("${pi_include_dir}")
include_directories("${sycl_inc_dir}" "${pi_include_dir}")


add_library(pi_level_zero SHARED
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
"${pi_include_dir}/pi/pi.h"
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level_zero.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level_zero.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6051,7 +6051,7 @@ pi_result piPluginInit(pi_plugin *PluginInit) {

#define _PI_API(api) \
(PluginInit->PiFunctionTable).api = (decltype(&::api))(&api);
#include <CL/sycl/detail/pi.def>
#include <pi/pi.def>

return PI_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#ifndef PI_LEVEL_ZERO_HPP
#define PI_LEVEL_ZERO_HPP

#include <CL/sycl/detail/pi.h>
#include <pi/pi.h>

#include <atomic>
#include <cassert>
#include <cstring>
Expand Down
Loading