Skip to content

Commit f795ca9

Browse files
committed
Add XPU support in Tensorpipe.
- added xpu_basic channel support. - added helper functions in common for xpu. - added test for xpu_basic channel Signed-off-by: Jeeja KP <[email protected]>
1 parent 2b4cd91 commit f795ca9

21 files changed

+1806
-1
lines changed

cmake/Options.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ endmacro()
3131

3232
# TODO: Default to ON if CUDA available.
3333
option(TP_USE_CUDA "Enable support for CUDA tensors" OFF)
34+
option(TP_USE_XPU "Enable support for XPU tensors" OFF)
3435

3536
# Optional features
3637
option(TP_BUILD_BENCHMARK "Build benchmarks" OFF)

tensorpipe/CMakeLists.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,65 @@ if(TP_USE_CUDA)
321321

322322
endif()
323323

324+
## XPU
325+
326+
if(TP_USE_XPU)
327+
# TP_SRCS is the list of source files that we need to build libtensorpipe.
328+
set(TP_XPU_SRCS)
329+
330+
# TP_PUBLIC_HDRS is the list of public header files that we need to install.
331+
set(TP_XPU_PUBLIC_HDRS)
332+
333+
# TP_LINK_LIBRARIES is list of dependent libraries to be linked
334+
set(TP_XPU_LINK_LIBRARIES)
335+
336+
# TP_INCLUDE_DIRS is list of include path to be used
337+
set(TP_XPU_INCLUDE_DIRS)
338+
339+
find_package(IntelSYCL REQUIRED)
340+
list(APPEND TP_XPU_LINK_LIBRARIES ${SYCL_LIBRARY})
341+
list(APPEND TP_XPU_INCLUDE_DIRS ${SYCL_INCLUDE_DIR})
342+
list(APPEND TP_XPU_SRCS
343+
common/xpu_buffer.cc)
344+
list(APPEND TP_XPU_PUBLIC_HDRS
345+
tensorpipe_xpu.h
346+
common/xpu_buffer.h)
347+
348+
### xpu_basic
349+
350+
list(APPEND TP_XPU_SRCS
351+
channel/xpu_basic/channel_impl.cc
352+
channel/xpu_basic/context_impl.cc
353+
channel/xpu_basic/factory.cc
354+
common/xpu_loop.cc)
355+
list(APPEND TP_XPU_PUBLIC_HDRS
356+
channel/xpu_basic/factory.h)
357+
358+
add_library(tensorpipe_xpu ${TP_STATIC_OR_SHARED} ${TP_XPU_SRCS})
359+
360+
if(BUILD_SHARED_LIBS)
361+
set_target_properties(tensorpipe_xpu PROPERTIES POSITION_INDEPENDENT_CODE 1)
362+
endif()
363+
364+
target_link_libraries(tensorpipe_xpu PUBLIC tensorpipe)
365+
target_link_libraries(tensorpipe_xpu PRIVATE ${TP_XPU_LINK_LIBRARIES})
366+
target_include_directories(tensorpipe_xpu PUBLIC ${TP_XPU_INCLUDE_DIRS})
367+
368+
install(TARGETS tensorpipe_xpu
369+
EXPORT TensorpipeTargets
370+
LIBRARY DESTINATION ${TP_INSTALL_LIBDIR}
371+
ARCHIVE DESTINATION ${TP_INSTALL_LIBDIR})
372+
373+
foreach(_header_file ${TP_XPU_PUBLIC_HDRS})
374+
get_filename_component(_TP_HEADER_SUBDIR "${_header_file}" DIRECTORY)
375+
install(FILES ${_header_file}
376+
DESTINATION ${TP_INSTALL_INCLUDEDIR}/tensorpipe/${_TP_HEADER_SUBDIR})
377+
endforeach()
378+
379+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
380+
DESTINATION ${TP_INSTALL_INCLUDEDIR}/tensorpipe)
381+
382+
endif()
324383

325384
## Python bindings
326385

tensorpipe/benchmark/channel_registry.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <tensorpipe/tensorpipe.h>
1212
#include <tensorpipe/tensorpipe_cuda.h>
13+
#include <tensorpipe/tensorpipe_xpu.h>
1314

1415
TP_DEFINE_SHARED_REGISTRY(
1516
TensorpipeChannelRegistry,
@@ -89,6 +90,18 @@ std::shared_ptr<tensorpipe::channel::Context> makeCudaGdrChannel() {
8990
TP_REGISTER_CREATOR(TensorpipeChannelRegistry, cuda_gdr, makeCudaGdrChannel);
9091
#endif // TENSORPIPE_HAS_CUDA_GDR_CHANNEL
9192

93+
// XPU BASIC
94+
95+
std::shared_ptr<tensorpipe::channel::Context> makeXpuBasicChannel() {
96+
return tensorpipe::channel::xpu_basic::create(
97+
tensorpipe::channel::basic::create());
98+
}
99+
100+
TP_REGISTER_CREATOR(
101+
TensorpipeChannelRegistry,
102+
xpu_basic,
103+
makeXpuBasicChannel);
104+
92105
void validateChannelContext(
93106
std::shared_ptr<tensorpipe::channel::Context> context) {
94107
if (!context) {

0 commit comments

Comments
 (0)