forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.hpp
More file actions
84 lines (74 loc) · 2.45 KB
/
Copy pathplugin.hpp
File metadata and controls
84 lines (74 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//==--------------------- plugin.hpp - SYCL platform-------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#pragma once
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/stl.hpp>
__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {
/// The plugin class provides a unified interface to the underlying low-level
/// runtimes for the device-agnostic SYCL runtime.
///
/// \ingroup sycl_pi
class plugin {
public:
plugin() = delete;
plugin(RT::PiPlugin Plugin) : MPlugin(Plugin) {
MPiEnableTrace = (std::getenv("SYCL_PI_TRACE") != nullptr);
}
~plugin() = default;
/// Checks return value from PI calls.
///
/// \throw Exception if pi_result is not a PI_SUCCESS.
template <typename Exception = cl::sycl::runtime_error>
void checkPiResult(RT::PiResult pi_result) const {
CHECK_OCL_CODE_THROW(pi_result, Exception);
}
/// Calls the PiApi, traces the call, and returns the result.
///
/// Usage:
/// \code{cpp}
/// PiResult Err = plugin.call<PiApiKind::pi>(Args);
/// Plugin.checkPiResult(Err); // Checks Result and throws a runtime_error
/// // exception.
/// \endcode
///
/// \sa plugin::checkPiResult
template <PiApiKind PiApiOffset, typename... ArgsT>
RT::PiResult call_nocheck(ArgsT... Args) const {
RT::PiFuncInfo<PiApiOffset> PiCallInfo;
if (MPiEnableTrace) {
std::string FnName = PiCallInfo.getFuncName();
std::cout << "---> " << FnName << "(" << std::endl;
RT::printArgs(Args...);
}
RT::PiResult R = PiCallInfo.getFuncPtr(MPlugin)(Args...);
if (MPiEnableTrace) {
std::cout << ") ---> ";
RT::printArgs(R);
}
return R;
}
/// Calls the API, traces the call, checks the result
///
/// \throw cl::sycl::runtime_exception if the call was not successful.
template <PiApiKind PiApiOffset, typename... ArgsT>
void call(ArgsT... Args) const {
RT::PiResult Err = call_nocheck<PiApiOffset>(Args...);
checkPiResult(Err);
}
// TODO: Make this private. Currently used in program_manager to create a
// pointer to PiProgram.
RT::PiPlugin MPlugin;
private:
bool MPiEnableTrace;
}; // class plugin
} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)