-
Notifications
You must be signed in to change notification settings - Fork 798
Closed
Labels
Description
Describe the bug
sycl-example build by cmake execuate error
sycl build from source release version 2021-12
simple-sycl-app
#include <CL/sycl.hpp>
void show_platforms() {
auto platforms = sycl::platform::get_platforms();
for (auto &platform : platforms) {
std::cout << "Platform: "
<< platform.get_info<sycl::info::platform::name>()
<< std::endl;
auto devices = platform.get_devices();
for (auto &device : devices ) {
std::cout << " Device: "
<< device.get_info<sycl::info::device::name>()
<< std::endl;
}
}
}
int main() {
show_platforms();
// auto name = sycl::info::platform::name;
// auto con = cl::sycl::context();
// auto properties = cl::sycl::property_list();
// Creating buffer of 4 ints to be used inside the kernel code
cl::sycl::buffer<cl::sycl::cl_int, 1> Buffer(4);
//sycl::gpu_selector s;
// Creating SYCL queue
cl::sycl::queue Queue;
//cl::sycl::queue Queue();
auto dev = Queue.get_device();
std::cout<<"================================"<<std::endl;
std::cout << "Default Device: "
<< dev.get_info<sycl::info::device::name>()
<< std::endl;
// Size of index space for kernel
cl::sycl::range<1> NumOfWorkItems{Buffer.size()};
// Submitting command group(work) to queue
Queue.submit([&](cl::sycl::handler &cgh) {
// Getting write only access to the buffer on a device
auto Accessor = Buffer.get_access<cl::sycl::access::mode::write>(cgh);
// auto out = sycl::stream(1024, 768, cgh);
// auto task = [=]() { out << "In a task\n"; };
// Executing kernel
cgh.parallel_for<class FillBuffer>(
NumOfWorkItems, [=](cl::sycl::id<1> WIid) {
// out<<"parallel for before\n";
// Fill buffer with indexes
Accessor[WIid] = (cl::sycl::cl_int)WIid.get(0);
});
// cgh.single_task<class stream_task>(task);
});
// Getting read only access to the buffer on the host.
// Implicit barrier waiting for queue to complete the work.
const auto HostAccessor = Buffer.get_access<cl::sycl::access::mode::read>();
// Check the results
bool MismatchFound = false;
for (size_t I = 0; I < Buffer.size(); ++I) {
if (HostAccessor[I] != I) {
std::cout << "The result is incorrect for element: " << I
<< " , expected: " << I << " , got: " << HostAccessor[I]
<< std::endl;
MismatchFound = true;
}
}
if (!MismatchFound) {
std::cout << "The results are correct!" << std::endl;
}
return MismatchFound;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_C_COMPILER "/home/wzy/sycl_workspace/build-cuda/bin/clang")
set(CMAKE_CXX_COMPILER "/home/wzy/sycl_workspace/build-cuda/bin/clang++")
set(CMAKE_CXX_STANDARD 17)
project(simple-sycl-app)
set(DPCPP_HOME "/home/wzy/sycl_workspace")
set(DPCPP_SYCL_HOME "${DPCPP_HOME}/build-cuda")
message(STATUS "dpcpp_home : ${DPCPP_HOME}")
message(STATUS "dpcpp_cuda_sycl_home : ${DPCPP_SYCL_HOME}")
#link_directories("${DPCPP_SYCL_HOME}/build-cuda-debug/lib")
message(STATUS "find library path : ${DPCPP_SYCL_HOME}/lib")
set(CMAKE_BUILD_RPATH "${DPCPP_SYCL_HOME}/lib;${CMAKE_BUILD_RPATH}")
message(STATUS "cmake build rpath : ${CMAKE_BUILD_RPATH}")
# set(CMAKE_BUILD_PATH "${DPCPP_SYCL_HOME}/lib:${CMAKE_BUILD_PATH}")
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -std=c++17")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -std=c++17")
# include_directories(simple-sycl-app PRIVATE "${DPCPP_SYCL_HOME}/include/sycl")
# include_directories(simple-sycl-app PRIVATE "${DPCPP_SYCL_HOME}/include")
add_compile_options(-fsycl -fsycl-targets=nvptx64-nvidia-cuda)
link_directories("${DPCPP_SYCL_HOME}/lib")
aux_source_directory(. DIR_SRCS)
add_executable(simple-sycl-app ${DIR_SRCS})
add_link_options(-fsycl -fsycl-targets=nvptx64-nvidia-cuda)
target_include_directories(simple-sycl-app PRIVATE "${DPCPP_SYCL_HOME}/include/sycl")
target_include_directories(simple-sycl-app PRIVATE "${DPCPP_SYCL_HOME}/include")
#target_link_libraries(simple-sycl-app -fsycl -fsycl-targets=nvptx64-nvidia-cuda -lsycl)
# target_link_libraries(simple-sycl-app PRIVATE ${SYCL} )
target_link_libraries(simple-sycl-app PRIVATE sycl )
how to solve the problem?
To Reproduce
Please describe the steps to reproduce the behavior:
- Include code snippet as short as possible
- Specify the command which should be used to compile the program
- Specify the comment which should be used to launch the program
- Indicate what is wrong and what was expected
Environment (please complete the following information):
- OS: ubuntu-server 18.04
- Target device and vendor: Nvidia GPU V100-PCIE-32G
- DPC++ version: clang version 14.0.0
- Dependencies version: cuda-11.2
Additional context
Add any other context about the problem here.