ExecutionEngine.h 2.6 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.

X
Xu Peng 已提交
18 19
#pragma once

S
starlord 已提交
20
#include "utils/Status.h"
21

X
Xu Peng 已提交
22
#include <memory>
S
starlord 已提交
23
#include <string>
S
starlord 已提交
24
#include <vector>
X
Xu Peng 已提交
25

J
jinhai 已提交
26
namespace milvus {
X
Xu Peng 已提交
27 28
namespace engine {

Z
zirui.chen 已提交
29
// TODO(linxj): replace with VecIndex::IndexType
G
groot 已提交
30
enum class EngineType {
G
groot 已提交
31
    INVALID = 0,
G
groot 已提交
32 33
    FAISS_IDMAP = 1,
    FAISS_IVFFLAT,
S
starlord 已提交
34
    FAISS_IVFSQ8,
X
xj.lin 已提交
35
    NSG_MIX,
W
wxyu 已提交
36
    FAISS_IVFSQ8H,
Z
zirui.chen 已提交
37
    FAISS_PQ,
38 39 40
    SPTAG_KDT,
    SPTAG_BKT,
    MAX_VALUE = SPTAG_BKT,
G
groot 已提交
41 42
};

43 44 45 46 47
enum class MetricType {
    L2 = 1,
    IP = 2,
};

48
class ExecutionEngine {
S
starlord 已提交
49
 public:
S
starlord 已提交
50 51
    virtual Status
    AddWithIds(int64_t n, const float* xdata, const int64_t* xids) = 0;
52

S
starlord 已提交
53 54
    virtual size_t
    Count() const = 0;
55

S
starlord 已提交
56 57
    virtual size_t
    Size() const = 0;
58

S
starlord 已提交
59 60
    virtual size_t
    Dimension() const = 0;
G
groot 已提交
61

S
starlord 已提交
62 63
    virtual size_t
    PhysicalSize() const = 0;
64

S
starlord 已提交
65 66
    virtual Status
    Serialize() = 0;
67

S
starlord 已提交
68 69
    virtual Status
    Load(bool to_cache = true) = 0;
70

S
starlord 已提交
71
    virtual Status
W
wxyu 已提交
72
    CopyToGpu(uint64_t device_id, bool hybrid) = 0;
73

Y
Yu Kun 已提交
74 75 76
    virtual Status
    CopyToIndexFileToGpu(uint64_t device_id) = 0;

S
starlord 已提交
77 78
    virtual Status
    CopyToCpu() = 0;
79

80 81
    //    virtual std::shared_ptr<ExecutionEngine>
    //    Clone() = 0;
W
wxyu 已提交
82

S
starlord 已提交
83 84
    virtual Status
    Merge(const std::string& location) = 0;
85

S
starlord 已提交
86
    virtual Status
J
JinHai-CN 已提交
87
    Search(int64_t n, const float* data, int64_t k, int64_t nprobe, float* distances, int64_t* labels, bool hybrid) = 0;
88

S
starlord 已提交
89 90
    virtual std::shared_ptr<ExecutionEngine>
    BuildIndex(const std::string& location, EngineType engine_type) = 0;
91

S
starlord 已提交
92 93
    virtual Status
    Cache() = 0;
Y
yu yunfeng 已提交
94

S
starlord 已提交
95 96
    virtual Status
    GpuCache(uint64_t gpu_id) = 0;
Y
Yu Kun 已提交
97

S
starlord 已提交
98 99
    virtual Status
    Init() = 0;
S
starlord 已提交
100

S
starlord 已提交
101 102
    virtual EngineType
    IndexEngineType() const = 0;
S
starlord 已提交
103

S
starlord 已提交
104 105
    virtual MetricType
    IndexMetricType() const = 0;
106

S
starlord 已提交
107 108
    virtual std::string
    GetLocation() const = 0;
109 110
};

G
groot 已提交
111 112
using ExecutionEnginePtr = std::shared_ptr<ExecutionEngine>;

S
starlord 已提交
113 114
}  // namespace engine
}  // namespace milvus