Program Listing for File interface.hpp¶
↰ Return to documentation for file (/workspace/amdinfer/src/amdinfer/core/interface.hpp)
// Copyright 2021 Xilinx, Inc.
// Copyright 2022 Advanced Micro Devices, Inc.
//
// 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.
#ifndef GUARD_AMDINFER_CORE_INTERFACE
#define GUARD_AMDINFER_CORE_INTERFACE
#include <chrono> // for high_resolution_clock
#include <cstddef> // for size_t
#include <exception> // for exception
#include <memory> // for shared_ptr
#include <vector> // for vector
#include "amdinfer/build_options.hpp" // for AMDINFER_ENABLE_LOGGING
#include "amdinfer/declarations.hpp" // for BufferRawPtrs
#include "amdinfer/observation/logging.hpp" // for Logger, Loggers, Loggers...
#include "amdinfer/observation/tracing.hpp" // for TracePtr
namespace amdinfer {
class InferenceRequest;
} // namespace amdinfer
namespace amdinfer {
enum class InterfaceType {
Unknown,
DrogonHttp,
DrogonWs,
Cpp,
Grpc,
};
class Interface {
public:
Interface();
virtual ~Interface() = default;
[[nodiscard]] InterfaceType getType() const;
#ifdef AMDINFER_ENABLE_TRACING
void setTrace(TracePtr &&trace);
TracePtr &&getTrace();
#endif
#ifdef AMDINFER_ENABLE_METRICS
void setTime(
const std::chrono::high_resolution_clock::time_point &start_time);
[[nodiscard]] std::chrono::high_resolution_clock::time_point getTime() const;
#endif
virtual size_t getInputSize() = 0;
virtual std::shared_ptr<InferenceRequest> getRequest(
const BufferRawPtrs &input_buffers, std::vector<size_t> &input_offsets,
const BufferRawPtrs &output_buffers,
std::vector<size_t> &output_offsets) = 0;
virtual void errorHandler(const std::exception &e) = 0;
protected:
InterfaceType type_;
#ifdef AMDINFER_ENABLE_TRACING
TracePtr trace_;
#endif
#ifdef AMDINFER_ENABLE_METRICS
std::chrono::_V2::system_clock::time_point start_time_;
#endif
#ifdef AMDINFER_ENABLE_LOGGING
[[nodiscard]] const Logger &getLogger() const;
#endif
private:
#ifdef AMDINFER_ENABLE_LOGGING
Logger logger_{Loggers::Server};
#endif
};
} // namespace amdinfer
#endif // GUARD_AMDINFER_CORE_INTERFACE