Skip to content
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include versioneer.py
recursive-include dpctl/include *.h *.hpp
recursive-include dpctl/include *.h*
include dpctl/*.pxd
include dpctl/*DPPL*Interface.*
include dpctl/tests/input_files/*
Expand Down
78 changes: 24 additions & 54 deletions backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,13 @@ function (check_for_dpcpp)
endif()
endfunction()

function (check_for_numpy_inc)
string(COMPARE EQUAL "${NUMPY_INCLUDE_DIR}" "" no_numpy_inc)
if(${no_dpcpp_root})
message(FATAL_ERROR "Set the NUMPY_INCLUDE_DIR argument providing the \
path to NumPy Headers.")
else()
message(STATUS "NUMPY_INCLUDE_DIR: ${NUMPY_INCLUDE_DIR}")
endif()

string(COMPARE EQUAL "${PYTHON_INCLUDE_DIR}" "" no_python_inc)
if(${no_dpcpp_root})
message(FATAL_ERROR "Set the PYTHON_INCLUDE_DIR argument providing the \
path to Python Headers.")
else()
message(STATUS "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
endif()
endfunction()

# Check for dpcpp in the specified DPCPP_ROOT
check_for_dpcpp()
# Check if the locations of Numpy and Python headers were provided
check_for_numpy_inc()

find_package(Python REQUIRED COMPONENTS Development NumPy)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do these macros search in the conda prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes.

include(CMakePrintHelpers)
cmake_print_variables(Python_INCLUDE_DIRS)
cmake_print_variables(Python_NumPy_INCLUDE_DIRS)

if(WIN32)
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
Expand Down Expand Up @@ -89,9 +74,13 @@ endif()

set(OpenCL_INCLUDE_DIR "${DPCPP_ROOT}/include/sycl")
set(OpenCL_LIBRARY "${DPCPP_ROOT}/lib/libOpenCL.so")
cmake_print_variables(OpenCL_INCLUDE_DIR)
cmake_print_variables(OpenCL_LIBRARY)

add_definitions(-DCL_TARGET_OPENCL_VERSION=220)

message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")

# DPPLSyclInterface

add_library(
DPPLSyclInterface
Expand All @@ -108,40 +97,30 @@ add_library(
source/dppl_utils.cpp
)

# Install DPPLOpenCLInterface
add_library(
DPPLOpenCLInterface
SHARED
source/dppl_opencl_interface.c
)

# Install DPPLSyclInterface
target_include_directories(
DPPLSyclInterface
PRIVATE
${CMAKE_SOURCE_DIR}/include/
${PYTHON_INCLUDE_DIR}
${NUMPY_INCLUDE_DIR}
${Python_INCLUDE_DIRS}
${Python_NumPy_INCLUDE_DIRS}
)

target_include_directories(
DPPLOpenCLInterface
PRIVATE
${CMAKE_SOURCE_DIR}/include/

# DPPLOpenCLInterface

add_library(
DPPLOpenCLInterface
SHARED
source/dppl_opencl_interface.c
)

target_include_directories(
DPPLOpenCLInterface
PUBLIC
${OpenCL_INCLUDE_DIR}
PRIVATE ${CMAKE_SOURCE_DIR}/include/
PUBLIC ${OpenCL_INCLUDE_DIR}
)

if(WIN32)
message(
STATUS
"SYCL_INCLUDE_DIR: "
${DPCPP_ROOT}/include/sycl
)
target_include_directories(
DPPLSyclInterface
PUBLIC
Expand All @@ -159,18 +138,9 @@ if(WIN32)
endif()

install(
TARGETS
DPPLSyclInterface
LIBRARY DESTINATION
"${CMAKE_INSTALL_PREFIX}/lib/"
)

install(
TARGETS
DPPLOpenCLInterface
TARGETS DPPLSyclInterface DPPLOpenCLInterface
LIBRARY
DESTINATION
"${CMAKE_INSTALL_PREFIX}/lib/"
DESTINATION lib
)

# Install all headers
Expand Down
87 changes: 39 additions & 48 deletions backends/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
string(COMPARE EQUAL "${GTEST_INCLUDE_DIR}" "" no_gtest_incl_dir)
string(COMPARE EQUAL "${GTEST_LIB_DIR}" "" no_gtest_lib_dir)

if(${no_gtest_incl_dir} OR ${no_gtest_lib_dir})
message(WARNING
"GTest is needed to test PyDPPL's backend test cases. Pass in \
-DGTEST_INCLUDE_DIR and -DGTEST_LIB_DIR when you configure Cmake if\
you wish to run PyDPPL backend tests."
)
else()
# We need thread support for gtest
find_package(Threads REQUIRED)

set(CMAKE_CTEST_COMMAND ctest -V)

# Emulate autotools like make check target to build tests
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
enable_testing()

include_directories(${GTEST_INCLUDE_DIR})
include_directories(../include)

link_directories(${GTEST_LIB_DIR})

set(PYDPPL_BACKEND_TEST_CASES
test_sycl_kernel_interface
test_sycl_platform_interface
test_sycl_program_interface
test_sycl_queue_interface
test_sycl_queue_manager
find_package(GTest REQUIRED)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same question. I was not sure if the macro is smart enough to look under conda prefix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have tested on Linux. It works fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On my system I have gtest installed in my conda environment and find_package fails to locate Gtest. What do I need to do to fix? I can install gtest through apt, but that is not what we want right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok. So to get it to work, I need cmake to come from conda as well. So it works. Nice!


# We need thread support for gtest
find_package(Threads REQUIRED)

set(CMAKE_CTEST_COMMAND ctest -V)

# Emulate autotools like make check target to build tests
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
enable_testing()

include_directories(${GTEST_INCLUDE_DIR})
include_directories(../include)

link_directories(${GTEST_LIB_DIR})

set(PYDPPL_BACKEND_TEST_CASES
test_sycl_kernel_interface
test_sycl_platform_interface
# test_sycl_program_interface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: commented.

test_sycl_queue_interface
test_sycl_queue_manager
)

# Copy the spir-v input files to test build directory
set(spirv-test-files
multi_kernel.spv
)
foreach(tf ${spirv-test-files})
file(COPY ${tf} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endforeach()

foreach(TEST_CASE ${PYDPPL_BACKEND_TEST_CASES})
add_executable(${TEST_CASE} EXCLUDE_FROM_ALL ${TEST_CASE}.cpp)
target_link_libraries(
${TEST_CASE} ${CMAKE_THREAD_LIBS_INIT} GTest::GTest DPPLSyclInterface
)

# Copy the spir-v input files to test build directory
set(spirv-test-files
multi_kernel.spv
)
foreach(tf ${spirv-test-files})
file(COPY ${tf} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endforeach()

foreach(TEST_CASE ${PYDPPL_BACKEND_TEST_CASES})
add_executable(${TEST_CASE} EXCLUDE_FROM_ALL ${TEST_CASE}.cpp)
target_link_libraries(
${TEST_CASE} ${CMAKE_THREAD_LIBS_INIT} gtest DPPLSyclInterface
)
add_test(NAME ${TEST_CASE} COMMAND ${TEST_CASE})
add_dependencies(check ${TEST_CASE})
endforeach()
endif()
add_test(NAME ${TEST_CASE} COMMAND ${TEST_CASE})
add_dependencies(check ${TEST_CASE})
endforeach()
7 changes: 1 addition & 6 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@ pushd build_cmake
INSTALL_PREFIX=`pwd`/../install
rm -rf ${INSTALL_PREFIX}

PYTHON_INC=`${PYTHON} -c "import distutils.sysconfig; \
print(distutils.sysconfig.get_python_inc())"`
NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"`
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/

cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
-DDPCPP_ROOT=${DPCPP_ROOT} \
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
../backends

make -j 4 && make install
make -j 4 && make check & make install

popd
cp install/lib/*.so dpctl/
Expand Down
1 change: 1 addition & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ requirements:
- make # [unix]
- ninja # [win]
- numpy >=1.17
- gtest >=1.10
run:
- python
- numpy >=1.17
Expand Down