-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference.h
46 lines (35 loc) · 1.35 KB
/
inference.h
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
#pragma once
#include <filesystem>
#include <functional>
#include <memory>
class FloatResultView {
public:
explicit FloatResultView(const void* opaque) : opaque_{opaque} {}
FloatResultView(const FloatResultView&) = delete;
FloatResultView(FloatResultView&&) = delete;
FloatResultView& operator=(const FloatResultView&) = delete;
FloatResultView& operator=(FloatResultView&&) = delete;
float GetAt(std::uint32_t index) const;
std::uint32_t Size() const;
std::uint32_t GetMany(std::uint32_t start_index, std::vector<float>& items) const;
std::uint32_t GetMany(std::uint32_t start_index, float* dest, std::uint32_t dest_size) const;
private:
const void* opaque_;
};
class Inference {
public:
enum class DeviceType { Default, Cpu, DirectX, DirectXHighPerformance, DirectXMinPower, Custom };
explicit Inference(const std::filesystem::path& model_path, DeviceType dev_type = DeviceType::Default);
~Inference();
/**
Value 0 sets default number of threads.
*/
void SetIntraOpNumThreads(std::uint32_t threads_count);
const std::vector<std::int64_t>& GetInputShape() const;
const std::vector<std::int64_t>& GetOutputShape() const;
using FloatResultViewer = std::function<void(const FloatResultView&)>;
void Run(const float* data, std::size_t size, FloatResultViewer result_view);
private:
struct Impl;
std::unique_ptr<Impl> guts_;
};