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 30

#include <memory>
#include <string>

namespace zilliz {
namespace milvus {
namespace engine {

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

    ExecutionEngineImpl(VecIndexPtr index,
                        const std::string &location,
S
starlord 已提交
40 41 42
                        EngineType index_type,
                        MetricType metric_type,
                        int32_t nlist);
S
starlord 已提交
43

S
starlord 已提交
44
    Status AddWithIds(int64_t n, const float *xdata, const int64_t *xids) override;
S
starlord 已提交
45 46 47 48 49 50 51 52 53 54 55

    size_t Count() const override;

    size_t Size() const override;

    size_t Dimension() const override;

    size_t PhysicalSize() const override;

    Status Serialize() override;

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

58 59 60 61
    Status CopyToGpu(uint64_t device_id) override;

    Status CopyToCpu() override;

W
wxyu 已提交
62 63
    ExecutionEnginePtr Clone() override;

X
xj.lin 已提交
64
    Status Merge(const std::string &location) override;
S
starlord 已提交
65

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

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

    Status Cache() override;

Y
Yu Kun 已提交
77 78
    Status GpuCache(uint64_t gpu_id) override;

S
starlord 已提交
79 80
    Status Init() override;

S
starlord 已提交
81 82 83
    EngineType IndexEngineType() const override {
        return index_type_;
    }
S
starlord 已提交
84

S
starlord 已提交
85 86 87
    MetricType IndexMetricType() const override {
        return metric_type_;
    }
S
starlord 已提交
88

S
starlord 已提交
89 90 91
    std::string GetLocation() const override {
        return location_;
    }
92

S
starlord 已提交
93
 private:
X
xj.lin 已提交
94 95 96
    VecIndexPtr CreatetVecIndex(EngineType type);

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

S
starlord 已提交
98
 protected:
X
xj.lin 已提交
99
    VecIndexPtr index_ = nullptr;
S
starlord 已提交
100 101
    EngineType index_type_;
    MetricType metric_type_;
S
starlord 已提交
102

S
starlord 已提交
103
    int64_t dim_;
S
starlord 已提交
104 105
    std::string location_;

S
starlord 已提交
106
    int32_t nlist_ = 0;
107
    int32_t gpu_num_ = 0;
S
starlord 已提交
108 109 110 111 112
};

} // namespace engine
} // namespace milvus
} // namespace zilliz