diff --git a/dpctl-capi/include/Config/dpctl_config.h.in b/dpctl-capi/include/Config/dpctl_config.h.in index eed64d54d6..8fc464cb40 100644 --- a/dpctl-capi/include/Config/dpctl_config.h.in +++ b/dpctl-capi/include/Config/dpctl_config.h.in @@ -29,4 +29,4 @@ #cmakedefine DPCTL_ENABLE_LO_PROGRAM_CREATION @DPCTL_ENABLE_LO_PROGRAM_CREATION@ /* The DPCPP version used to build dpctl */ -#define DPCTL_DPCPP_VERSION "@DPCPP_VERSION@" +#define DPCTL_DPCPP_VERSION "@IntelSycl_VERSION@" diff --git a/dpctl-capi/include/dpctl_service.h b/dpctl-capi/include/dpctl_service.h new file mode 100644 index 0000000000..e66c1a1c47 --- /dev/null +++ b/dpctl-capi/include/dpctl_service.h @@ -0,0 +1,46 @@ +//===- dpctl_service.h - C API for service functions -*-C++-*- ===// +// +// Data Parallel Control (dpctl) +// +// Copyright 2020-2021 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 header defines dpctl service functions. +/// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "Support/DllExport.h" +#include "Support/ExternC.h" +#include "Support/MemOwnershipAttrs.h" + +DPCTL_C_EXTERN_C_BEGIN +/** + * @defgroup Service Service functions + */ + +/*! + * @brief Get version of DPC++ toolchain the library was compiled with. + * + * @return A C string containing the version of DPC++ toolchain. + * @ingroup Service + */ +DPCTL_API +__dpctl_give const char *DPCTLService_GetDPCPPVersion(void); + +DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/source/dpctl_service.cpp b/dpctl-capi/source/dpctl_service.cpp new file mode 100644 index 0000000000..a9b6816f8c --- /dev/null +++ b/dpctl-capi/source/dpctl_service.cpp @@ -0,0 +1,50 @@ +//===- dpctl_service.cpp - C API for service functions -*-C++-*- ===// +// +// Data Parallel Control (dpctl) +// +// Copyright 2020-2021 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 header defines dpctl service functions. +/// +//===----------------------------------------------------------------------===// + +#include "dpctl_service.h" +#include "Config/dpctl_config.h" + +#include +#include +#include + +__dpctl_give const char *DPCTLService_GetDPCPPVersion(void) +{ + std::string version = DPCTL_DPCPP_VERSION; + char *version_cstr = nullptr; + try { + auto cstr_len = version.length() + 1; + version_cstr = new char[cstr_len]; +#ifdef _WIN32 + strncpy_s(version_cstr, cstr_len, version.c_str(), cstr_len); +#else + std::strncpy(version_cstr, version.c_str(), cstr_len); +#endif + } catch (std::bad_alloc const &ba) { + // \todo log error + std::cerr << ba.what() << '\n'; + } + return version_cstr; +} diff --git a/dpctl-capi/tests/test_service.cpp b/dpctl-capi/tests/test_service.cpp new file mode 100644 index 0000000000..fe357514e0 --- /dev/null +++ b/dpctl-capi/tests/test_service.cpp @@ -0,0 +1,48 @@ +//===--- test_service.cpp - Test cases for sevice functions ===// +// +// Data Parallel Control (dpctl) +// +// Copyright 2020-2021 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 has unit test cases for functions defined in +/// dpctl_service.h. +/// +//===----------------------------------------------------------------------===// + +#include "Config/dpctl_config.h" +#include "dpctl_service.h" +#include +#include + +#define ASSTR(a) TOSTR(a) +#define TOSTR(a) #a + +TEST(TestServicesFns, ChkDPCPPVersion) +{ + auto c_ver = DPCTLService_GetDPCPPVersion(); + std::string ver = std::string(c_ver); + ASSERT_TRUE(ver.length() > 0); + + std::string ver_from_cmplr(ASSTR(__VERSION__)); + std::size_t found = ver_from_cmplr.find(ver); + + // version returned by DPCTLService_GetDPCPPVersion + // should occur as a substring in the version obtained + // from compiler + ASSERT_TRUE(found != std::string::npos); +}