ExecutionEngineImpl.h 3.0 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.

S
starlord 已提交
18 19 20
#pragma once

#include "ExecutionEngine.h"
21
#include "src/wrapper/VecIndex.h"
S
starlord 已提交
22 23 24 25 26 27 28 29

#include <memory>
#include <string>

namespace milvus {
namespace engine {

class ExecutionEngineImpl : public ExecutionEngine {
S
starlord 已提交
30
 public:
S
starlord 已提交
31
    ExecutionEngineImpl(uint16_t dimension, const std::string& location, EngineType index_type, MetricType metric_type,
S
starlord 已提交
32
                        int32_t nlist);
X
xj.lin 已提交
33

S
starlord 已提交
34
    ExecutionEngineImpl(VecIndexPtr index, const std::string& location, EngineType index_type, MetricType metric_type,
S
starlord 已提交
35
                        int32_t nlist);
S
starlord 已提交
36

S
starlord 已提交
37 38
    Status
    AddWithIds(int64_t n, const float* xdata, const int64_t* xids) override;
S
starlord 已提交
39

S
starlord 已提交
40 41
    size_t
    Count() const override;
S
starlord 已提交
42

S
starlord 已提交
43 44
    size_t
    Size() const override;
S
starlord 已提交
45

S
starlord 已提交
46 47
    size_t
    Dimension() const override;
S
starlord 已提交
48

S
starlord 已提交
49 50
    size_t
    PhysicalSize() const override;
S
starlord 已提交
51

S
starlord 已提交
52 53
    Status
    Serialize() override;
S
starlord 已提交
54

S
starlord 已提交
55 56
    Status
    Load(bool to_cache) override;
S
starlord 已提交
57

S
starlord 已提交
58
    Status
W
wxyu 已提交
59
    CopyToGpu(uint64_t device_id, bool hybrid = false) override;
60

Y
Yu Kun 已提交
61
    Status
Y
Yu Kun 已提交
62
    CopyToIndexFileToGpu(uint64_t device_id) override;
Y
Yu Kun 已提交
63

S
starlord 已提交
64 65
    Status
    CopyToCpu() override;
66

S
starlord 已提交
67 68
    ExecutionEnginePtr
    Clone() override;
W
wxyu 已提交
69

S
starlord 已提交
70 71
    Status
    Merge(const std::string& location) override;
S
starlord 已提交
72

S
starlord 已提交
73
    Status
W
wxyu 已提交
74
    Search(int64_t n, const float* data, int64_t k, int64_t nprobe, float* distances, int64_t* labels,
W
wxyu 已提交
75
           bool hybrid = false) const override;
S
starlord 已提交
76

S
starlord 已提交
77 78
    ExecutionEnginePtr
    BuildIndex(const std::string& location, EngineType engine_type) override;
S
starlord 已提交
79

S
starlord 已提交
80 81
    Status
    Cache() override;
S
starlord 已提交
82

S
starlord 已提交
83 84
    Status
    GpuCache(uint64_t gpu_id) override;
Y
Yu Kun 已提交
85

S
starlord 已提交
86 87
    Status
    Init() override;
S
starlord 已提交
88

S
starlord 已提交
89 90
    EngineType
    IndexEngineType() const override {
S
starlord 已提交
91 92
        return index_type_;
    }
S
starlord 已提交
93

S
starlord 已提交
94 95
    MetricType
    IndexMetricType() const override {
S
starlord 已提交
96 97
        return metric_type_;
    }
S
starlord 已提交
98

S
starlord 已提交
99 100
    std::string
    GetLocation() const override {
S
starlord 已提交
101 102
        return location_;
    }
103

S
starlord 已提交
104
 private:
S
starlord 已提交
105 106
    VecIndexPtr
    CreatetVecIndex(EngineType type);
X
xj.lin 已提交
107

S
starlord 已提交
108 109
    VecIndexPtr
    Load(const std::string& location);
S
starlord 已提交
110

111
    void
W
wxyu 已提交
112
    HybridLoad() const;
W
wxyu 已提交
113

W
wxyu 已提交
114 115
    void
    HybridUnset() const;
116

S
starlord 已提交
117
 protected:
X
xj.lin 已提交
118
    VecIndexPtr index_ = nullptr;
S
starlord 已提交
119 120
    EngineType index_type_;
    MetricType metric_type_;
S
starlord 已提交
121

S
starlord 已提交
122
    int64_t dim_;
S
starlord 已提交
123 124
    std::string location_;

S
starlord 已提交
125
    int32_t nlist_ = 0;
126
    int32_t gpu_num_ = 0;
S
starlord 已提交
127 128
};

S
starlord 已提交
129 130
}  // namespace engine
}  // namespace milvus