xref: /freebsd-src/contrib/llvm-project/llvm/lib/Analysis/NoInferenceModelRunner.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
1*0eae32dcSDimitry Andric //===- NoInferenceModelRunner.cpp - noop ML model runner   ----------------===//
2*0eae32dcSDimitry Andric //
3*0eae32dcSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0eae32dcSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0eae32dcSDimitry Andric //
7*0eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
8*0eae32dcSDimitry Andric //
9*0eae32dcSDimitry Andric // A pseudo model runner. We use it to store feature values when collecting
10*0eae32dcSDimitry Andric // logs for the default policy, in 'development' mode, but never ask it to
11*0eae32dcSDimitry Andric // 'run'.
12*0eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
13*0eae32dcSDimitry Andric #include "llvm/Config/config.h"
14*0eae32dcSDimitry Andric #if defined(LLVM_HAVE_TF_API)
15*0eae32dcSDimitry Andric 
16*0eae32dcSDimitry Andric #include "llvm/Analysis/NoInferenceModelRunner.h"
17*0eae32dcSDimitry Andric #include "llvm/Analysis/Utils/TFUtils.h"
18*0eae32dcSDimitry Andric 
19*0eae32dcSDimitry Andric using namespace llvm;
20*0eae32dcSDimitry Andric 
21*0eae32dcSDimitry Andric NoInferenceModelRunner::NoInferenceModelRunner(
22*0eae32dcSDimitry Andric     LLVMContext &Ctx, const std::vector<TensorSpec> &Inputs)
23*0eae32dcSDimitry Andric     : MLModelRunner(Ctx) {
24*0eae32dcSDimitry Andric   ValuesBuffer.reserve(Inputs.size());
25*0eae32dcSDimitry Andric   for (const auto &TS : Inputs)
26*0eae32dcSDimitry Andric     ValuesBuffer.push_back(std::make_unique<char[]>(TS.getElementCount() *
27*0eae32dcSDimitry Andric                                                     TS.getElementByteSize()));
28*0eae32dcSDimitry Andric }
29*0eae32dcSDimitry Andric 
30*0eae32dcSDimitry Andric void *NoInferenceModelRunner::getTensorUntyped(size_t Index) {
31*0eae32dcSDimitry Andric   return ValuesBuffer[Index].get();
32*0eae32dcSDimitry Andric }
33*0eae32dcSDimitry Andric #endif // defined(LLVM_HAVE_TF_API)
34