ExecutionEngineImpl.h 2.8 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 59
    Status
    CopyToGpu(uint64_t device_id) override;
60

S
starlord 已提交
61 62
    Status
    CopyToCpu() override;
63

S
starlord 已提交
64 65
    ExecutionEnginePtr
    Clone() override;
W
wxyu 已提交
66

S
starlord 已提交
67 68
    Status
    Merge(const std::string& location) override;
S
starlord 已提交
69

S
starlord 已提交
70 71
    Status
    Search(int64_t n, const float* data, int64_t k, int64_t nprobe, float* distances, int64_t* labels) const override;
S
starlord 已提交
72

S
starlord 已提交
73 74
    ExecutionEnginePtr
    BuildIndex(const std::string& location, EngineType engine_type) override;
S
starlord 已提交
75

S
starlord 已提交
76 77
    Status
    Cache() override;
S
starlord 已提交
78

S
starlord 已提交
79 80
    Status
    GpuCache(uint64_t gpu_id) override;
Y
Yu Kun 已提交
81

S
starlord 已提交
82 83
    Status
    Init() override;
S
starlord 已提交
84

S
starlord 已提交
85 86
    EngineType
    IndexEngineType() const override {
S
starlord 已提交
87 88
        return index_type_;
    }
S
starlord 已提交
89

S
starlord 已提交
90 91
    MetricType
    IndexMetricType() const override {
S
starlord 已提交
92 93
        return metric_type_;
    }
S
starlord 已提交
94

S
starlord 已提交
95 96
    std::string
    GetLocation() const override {
S
starlord 已提交
97 98
        return location_;
    }
99

S
starlord 已提交
100
 private:
S
starlord 已提交
101 102
    VecIndexPtr
    CreatetVecIndex(EngineType type);
X
xj.lin 已提交
103

S
starlord 已提交
104 105
    VecIndexPtr
    Load(const std::string& location);
S
starlord 已提交
106

S
starlord 已提交
107
 protected:
X
xj.lin 已提交
108
    VecIndexPtr index_ = nullptr;
S
starlord 已提交
109 110
    EngineType index_type_;
    MetricType metric_type_;
S
starlord 已提交
111

S
starlord 已提交
112
    int64_t dim_;
S
starlord 已提交
113 114
    std::string location_;

S
starlord 已提交
115
    int32_t nlist_ = 0;
116
    int32_t gpu_num_ = 0;
S
starlord 已提交
117 118
};

S
starlord 已提交
119 120
}  // namespace engine
}  // namespace milvus