Skip to content

Fixed dpctl_config, added dpctl_service.h, .cpp #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dpctl-capi/include/Config/dpctl_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
46 changes: 46 additions & 0 deletions dpctl-capi/include/dpctl_service.h
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions dpctl-capi/source/dpctl_service.cpp
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
#include <cstring>
#include <iostream>

__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;
}
48 changes: 48 additions & 0 deletions dpctl-capi/tests/test_service.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <string>

#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);
}