Skip to content

Commit ef53568

Browse files
Fixed dpctl_config, added dpctl_service.h, .cpp
Fixed Config/dpctl_config.h.in so that DPCTL_DPCPP_VERSION preprocessor variable is now non-empty. Created `const char * DPCTLService_GetDPCPPVersion(void)` service function to get the version stored in that preprocessor variable. This would allow Python to record minimum version requirement for the DPC++ toolchain runtime. ``` Python 3.7.10 (default, Jun 4 2021, 06:52:02) Type 'copyright', 'credits' or 'license' for more information IPython 7.25.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import dpctl, ctypes In [2]: lib = ctypes.cdll.LoadLibrary('dpctl/libDPCTLSyclInterface.so') In [3]: fn = lib.DPCTLService_GetDPCPPVersion In [4]: fn.argtypes=[] In [5]: fn.restype = ctypes.c_char_p In [6]: fn() Out[6]: b'2021.3.0' ```
1 parent ab0faea commit ef53568

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

dpctl-capi/include/Config/dpctl_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
#cmakedefine DPCTL_ENABLE_LO_PROGRAM_CREATION @DPCTL_ENABLE_LO_PROGRAM_CREATION@
3030

3131
/* The DPCPP version used to build dpctl */
32-
#define DPCTL_DPCPP_VERSION "@DPCPP_VERSION@"
32+
#define DPCTL_DPCPP_VERSION "@IntelSycl_VERSION@"

dpctl-capi/include/dpctl_service.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===- dpctl_service.h - C API for service functions -*-C++-*- ===//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This header defines dpctl service functions.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#include "Support/DllExport.h"
29+
#include "Support/ExternC.h"
30+
#include "Support/MemOwnershipAttrs.h"
31+
32+
DPCTL_C_EXTERN_C_BEGIN
33+
/**
34+
* @defgroup Service Service functions
35+
*/
36+
37+
/*!
38+
* @brief Get version of DPC++ toolchain the library was compiled with.
39+
*
40+
* @return A C string containing the version of DPC++ toolchain.
41+
* @ingroup Service
42+
*/
43+
DPCTL_API
44+
__dpctl_give const char *DPCTLService_GetDPCPPVersion(void);
45+
46+
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_service.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===- dpctl_service.cpp - C API for service functions -*-C++-*- ===//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This header defines dpctl service functions.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#include "dpctl_service.h"
27+
#include "Config/dpctl_config.h"
28+
29+
#include <algorithm>
30+
#include <cstring>
31+
#include <iostream>
32+
33+
__dpctl_give const char *DPCTLService_GetDPCPPVersion(void)
34+
{
35+
std::string version = DPCTL_DPCPP_VERSION;
36+
char *version_cstr = nullptr;
37+
try {
38+
auto cstr_len = version.length() + 1;
39+
version_cstr = new char[cstr_len];
40+
#ifdef _WIN32
41+
strncpy_s(version_cstr, cstr_len, version.c_str(), cstr_len);
42+
#else
43+
std::strncpy(version_cstr, version.c_str(), cstr_len);
44+
#endif
45+
} catch (std::bad_alloc const &ba) {
46+
// \todo log error
47+
std::cerr << ba.what() << '\n';
48+
}
49+
return version_cstr;
50+
}

dpctl-capi/tests/test_service.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===--- test_service.cpp - Test cases for sevice functions ===//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This file has unit test cases for functions defined in
23+
/// dpctl_service.h.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
#include "Config/dpctl_config.h"
28+
#include "dpctl_service.h"
29+
#include <agorithm>
30+
#include <string>
31+
32+
TEST(TestServicesFns, ChkDPCPPVersion)
33+
{
34+
auto c_ver = DPCTLService_GetDPCPPVersion();
35+
std::string ver = std::string(c_ver);
36+
ASSERT_TRUE(ver.length() > 0);
37+
38+
ver.erase(std::remove(ver.begin(), ver.end(), '.'), ver.end());
39+
std::string expected(#__VERSION);
40+
41+
ASSERT_TRUE(expected == ver);
42+
}

0 commit comments

Comments
 (0)