ExecutionEngineImpl.h 2.9 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"
X
xiaojun.lin 已提交
21
#include "src/wrapper/vec_index.h"
S
starlord 已提交
22 23 24 25

#include <memory>
#include <string>

X
xj.lin 已提交
26

S
starlord 已提交
27 28 29 30 31 32
namespace zilliz {
namespace milvus {
namespace engine {


class ExecutionEngineImpl : public ExecutionEngine {
33
public:
S
starlord 已提交
34 35

    ExecutionEngineImpl(uint16_t dimension,
X
xj.lin 已提交
36
                        const std::string &location,
S
starlord 已提交
37 38 39
                        EngineType index_type,
                        MetricType metric_type,
                        int32_t nlist);
X
xj.lin 已提交
40 41 42

    ExecutionEngineImpl(VecIndexPtr index,
                        const std::string &location,
S
starlord 已提交
43 44 45
                        EngineType index_type,
                        MetricType metric_type,
                        int32_t nlist);
S
starlord 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58

    Status AddWithIds(long n, const float *xdata, const long *xids) override;

    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 已提交
59
    Status Load(bool to_cache) override;
S
starlord 已提交
60

61 62 63 64
    Status CopyToGpu(uint64_t device_id) override;

    Status CopyToCpu() override;

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

X
xj.lin 已提交
67
    Status Merge(const std::string &location) override;
S
starlord 已提交
68 69 70 71

    Status Search(long n,
                  const float *data,
                  long k,
Y
Yu Kun 已提交
72
                  long nprobe,
S
starlord 已提交
73 74 75
                  float *distances,
                  long *labels) const override;

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

    Status Cache() override;

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

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

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

    MetricType IndexMetricType() const override { return metric_type_; }

88 89
    std::string GetLocation() const override { return location_; }

90
private:
X
xj.lin 已提交
91 92 93
    VecIndexPtr CreatetVecIndex(EngineType type);

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

95
protected:
X
xj.lin 已提交
96
    VecIndexPtr index_ = nullptr;
S
starlord 已提交
97 98
    EngineType index_type_;
    MetricType metric_type_;
S
starlord 已提交
99

S
starlord 已提交
100
    int64_t dim_;
S
starlord 已提交
101 102
    std::string location_;

S
starlord 已提交
103 104
    int32_t nlist_ = 0;
    int64_t gpu_num_ = 0;
S
starlord 已提交
105 106 107 108 109 110
};


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