14#include "llvm/Config/config.h"
30void Logger::writeHeader(std::optional<TensorSpec> AdviceSpec) {
31 json::OStream JOS(*OS);
33 JOS.attributeArray(
"features", [&]() {
34 for (
const auto &TS : FeatureSpecs)
38 JOS.attributeBegin(
"score");
39 RewardSpec.toJSON(JOS);
42 if (AdviceSpec.has_value()) {
43 JOS.attributeBegin(
"advice");
44 AdviceSpec->toJSON(JOS);
52 CurrentContext = Name.str();
59 auto I = ObservationIDs.insert({CurrentContext, 0});
60 size_t NewObservationID =
I.second ? 0 : ++
I.first->second;
63 JOS.
attribute(
"observation",
static_cast<int64_t
>(NewObservationID));
70void Logger::logRewardImpl(
const char *RawData) {
74 JOS.attribute(
"outcome",
static_cast<int64_t
>(
75 ObservationIDs.
find(CurrentContext)->second));
78 writeTensor(RewardSpec, RawData);
83 const std::vector<TensorSpec> &FeatureSpecs,
84 const TensorSpec &RewardSpec,
bool IncludeReward,
85 std::optional<TensorSpec> AdviceSpec)
86 : OS(
std::
move(OS)), FeatureSpecs(FeatureSpecs), RewardSpec(RewardSpec),
87 IncludeReward(IncludeReward) {
88 writeHeader(AdviceSpec);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file supports working with JSON data.
LLVM_ABI void startObservation()
LLVM_ABI void switchContext(StringRef Name)
LLVM_ABI void endObservation()
LLVM_ABI Logger(std::unique_ptr< raw_ostream > OS, const std::vector< TensorSpec > &FeatureSpecs, const TensorSpec &RewardSpec, bool IncludeReward, std::optional< TensorSpec > AdviceSpec=std::nullopt)
Construct a Logger.
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
void object(Block Contents)
Emit an object whose elements are emitted in the provided Block.
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.