DPC++ Runtime
Runtime libraries for oneAPI DPC++
spec_constant_impl.cpp
Go to the documentation of this file.
1 //==-- spec_constant_impl.cpp - SYCL RT model for specialization constants -==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include <sycl/detail/defines.hpp>
13 #include <sycl/detail/pi.h>
14 #include <sycl/detail/util.hpp>
15 #include <sycl/exception.hpp>
16 
17 #include <cstring>
18 
19 namespace sycl {
20 inline namespace _V1 {
21 namespace detail {
22 
23 void spec_constant_impl::set(size_t Size, const void *Val) {
24  if (0 == Size)
25  throw sycl::runtime_error("invalid spec constant size",
26  PI_ERROR_INVALID_VALUE);
27  auto *BytePtr = reinterpret_cast<const char *>(Val);
28  this->Bytes.assign(BytePtr, BytePtr + Size);
29 }
30 
32  SerializedObj &Dst) {
33  for (const auto &E : Reg) {
34  Dst.insert(Dst.end(), E.first.begin(), E.first.end());
35  const spec_constant_impl &SC = E.second;
36  Dst.insert(Dst.end(), SC.getValuePtr(), SC.getValuePtr() + SC.getSize());
37  }
38 }
39 
40 std::ostream &operator<<(std::ostream &Out, const spec_constant_impl &V) {
41  Out << "spec_constant_impl"
42  << " { Size=" << V.getSize() << " IsSet=" << V.isSet() << " Val=[";
43  std::ios_base::fmtflags FlagsSav = Out.flags();
44  Out << std::hex;
45  for (unsigned I = 0; I < V.getSize(); ++I) {
46  Out << (I == 0 ? "" : " ") << static_cast<int>(*(V.getValuePtr() + I));
47  }
48  Out << "]" << FlagsSav;
49  return Out;
50 }
51 
52 } // namespace detail
53 } // namespace _V1
54 } // namespace sycl
void set(size_t Size, const void *Val)
std::map< std::string, spec_constant_impl > SpecConstRegistryT
void stableSerializeSpecConstRegistry(const SpecConstRegistryT &Reg, SerializedObj &Dst)
std::ostream & operator<<(std::ostream &os, std::optional< T > const &opt)
std::vector< unsigned char > SerializedObj
Definition: util.hpp:69
Definition: access.hpp:18