diff --git a/backends/CMakeLists.txt b/backends/CMakeLists.txt index 0485dba1f9..db683dfcfe 100644 --- a/backends/CMakeLists.txt +++ b/backends/CMakeLists.txt @@ -77,6 +77,7 @@ add_library( source/dppl_sycl_queue_manager.cpp source/dppl_sycl_usm_interface.cpp source/dppl_utils.cpp + details/source/dppl_utils_details.cpp ) # Install DPPLSyclInterface @@ -84,6 +85,7 @@ target_include_directories( DPPLSyclInterface PRIVATE ${CMAKE_SOURCE_DIR}/include/ + ${CMAKE_SOURCE_DIR}/details/include/ ) if(WIN32) @@ -123,6 +125,12 @@ foreach(HEADER ${HEADERS}) install(FILES "${HEADER}" DESTINATION include/Support) endforeach() +# Install all headers in details/include +file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/details/include/*.h*") +foreach(HEADER ${HEADERS}) + install(FILES "${HEADER}" DESTINATION details/include) +endforeach() + option( BUILD_CAPI_TESTS "Build dpctl C API google tests" diff --git a/backends/details/include/dppl_utils_details.h b/backends/details/include/dppl_utils_details.h new file mode 100644 index 0000000000..07e8ead6e5 --- /dev/null +++ b/backends/details/include/dppl_utils_details.h @@ -0,0 +1,31 @@ +//===------------------- dppl_utils.h - dpctl-C_API ---*--- C++ -----*-----===// +// +// Data Parallel Control Library (dpCtl) +// +// Copyright 2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file defines common helper functions used in other places in DPPL. +//===----------------------------------------------------------------------===// + +#pragma once + +#include +using namespace cl::sycl; + +std::string DDPL_StrToDeviceType(info::device_type devTy); +info::device_type DPPL_DeviceTypeToStr(std::string devTyStr); diff --git a/backends/details/source/dppl_utils_details.cpp b/backends/details/source/dppl_utils_details.cpp new file mode 100644 index 0000000000..04b553e415 --- /dev/null +++ b/backends/details/source/dppl_utils_details.cpp @@ -0,0 +1,82 @@ +//===------ dppl_utils_details.cpp - dpctl-C_API ----*---- C++ -----*-----===// +// +// Data Parallel Control Library (dpCtl) +// +// Copyright 2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file implements the helper functions defined in dppl_utils_details.h. +/// +//===----------------------------------------------------------------------===// + +#include "dppl_utils_details.h" +#include +#include + +using namespace cl::sycl; + +/*! +* Transforms enum info::device_type to string. +*/ +std::string DDPL_StrToDeviceType(info::device_type devTy) +{ + std::stringstream ss; + switch (devTy) + { + case info::device_type::cpu: + ss << "cpu" << '\n'; + break; + case info::device_type::gpu: + ss << "gpu" << '\n'; + break; + case info::device_type::accelerator: + ss << "accelerator" << '\n'; + break; + case info::device_type::custom: + ss << "custom" << '\n'; + break; + case info::device_type::host: + ss << "host" << '\n'; + break; + default: + ss << "unknown" << '\n'; + } + return ss.str(); +} + +/*! +* Transforms string to enum info::device_type. +*/ +info::device_type DPPL_DeviceTypeToStr(std::string devTyStr) +{ + info::device_type devTy; + if (devTyStr == "cpu") { + devTy = info::device_type::cpu; + } else if(devTyStr == "gpu") { + devTy = info::device_type::gpu; + } else if(devTyStr == "accelerator") { + devTy = info::device_type::accelerator; + } else if(devTyStr == "custom") { + devTy = info::device_type::custom; + } else if(devTyStr == "host") { + devTy = info::device_type::host; + } else { + // \todo handle the error + throw std::runtime_error("Unknown device type."); + } + return devTy; +} diff --git a/backends/source/dppl_sycl_device_interface.cpp b/backends/source/dppl_sycl_device_interface.cpp index 5aca623418..3a421e9f55 100644 --- a/backends/source/dppl_sycl_device_interface.cpp +++ b/backends/source/dppl_sycl_device_interface.cpp @@ -30,6 +30,7 @@ #include #include #include /* SYCL headers */ +#include "../details/include/dppl_utils_details.h" using namespace cl::sycl; @@ -58,26 +59,7 @@ void dump_device_info (const device & Device) ss << std::setw(4) << " " << std::left << std::setw(16) << "Device type"; auto devTy = Device.get_info(); - switch(devTy) - { - case info::device_type::cpu: - ss << "cpu" << '\n'; - break; - case info::device_type::gpu: - ss << "gpu" << '\n'; - break; - case info::device_type::accelerator: - ss << "accelerator" << '\n'; - break; - case info::device_type::custom: - ss << "custom" << '\n'; - break; - case info::device_type::host: - ss << "host" << '\n'; - break; - default: - ss << "unknown" << '\n'; - } + ss << DDPL_StrToDeviceType(devTy); std::cout << ss.str(); } diff --git a/backends/source/dppl_sycl_platform_interface.cpp b/backends/source/dppl_sycl_platform_interface.cpp index 1db0987145..89b1377fa8 100644 --- a/backends/source/dppl_sycl_platform_interface.cpp +++ b/backends/source/dppl_sycl_platform_interface.cpp @@ -29,6 +29,7 @@ #include #include #include +#include "../details/include/dppl_utils_details.h" #include @@ -124,26 +125,7 @@ void DPPLPlatform_DumpInfo () << "Device type"; auto devTy = devices[dn].get_info(); - switch (devTy) - { - case info::device_type::cpu: - ss << "cpu" << '\n'; - break; - case info::device_type::gpu: - ss << "gpu" << '\n'; - break; - case info::device_type::accelerator: - ss << "accelerator" << '\n'; - break; - case info::device_type::custom: - ss << "custom" << '\n'; - break; - case info::device_type::host: - ss << "host" << '\n'; - break; - default: - ss << "unknown" << '\n'; - } + ss << DDPL_StrToDeviceType(devTy); } std::cout << ss.str(); ++i;