diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index c8cba4d9aa..60def5c4ca 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -35,7 +35,7 @@ aux_source_directory(db/engine db_engine_files) aux_source_directory(db/insert db_insert_files) aux_source_directory(db/meta db_meta_files) aux_source_directory(metrics metrics_files) -aux_source_directory(wrapper/knowhere knowhere_files) +aux_source_directory(wrapper wrapper_files) aux_source_directory(scheduler/action scheduler_action_files) aux_source_directory(scheduler/event scheduler_event_files) @@ -88,7 +88,7 @@ set(db_files ${db_meta_files} ${db_scheduler_files} ${metrics_files} - ${knowhere_files} + ${wrapper_files} ${utils_files} ) diff --git a/cpp/src/cache/DataObj.h b/cpp/src/cache/DataObj.h index 8ba59104cd..12406301cb 100644 --- a/cpp/src/cache/DataObj.h +++ b/cpp/src/cache/DataObj.h @@ -18,7 +18,7 @@ #pragma once -#include "wrapper/knowhere/vec_index.h" +#include "src/wrapper/vec_index.h" #include diff --git a/cpp/src/core/CMakeLists.txt b/cpp/src/core/CMakeLists.txt index b18af23f1e..bef3f5e2f6 100644 --- a/cpp/src/core/CMakeLists.txt +++ b/cpp/src/core/CMakeLists.txt @@ -84,7 +84,7 @@ include(DefineOptionsCore) include(BuildUtilsCore) include(ThirdPartyPackagesCore) -add_subdirectory(src) +add_subdirectory(knowhere) if (BUILD_COVERAGE STREQUAL "ON") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") diff --git a/cpp/src/core/include/knowhere/adapter/arrow.h b/cpp/src/core/include/knowhere/adapter/arrow.h deleted file mode 100644 index 338ab691df..0000000000 --- a/cpp/src/core/include/knowhere/adapter/arrow.h +++ /dev/null @@ -1,18 +0,0 @@ - -#pragma once - -#include -#include - - -namespace zilliz { -namespace knowhere { - -ArrayPtr -CopyArray(const ArrayPtr &origin); - -SchemaPtr -CopySchema(const SchemaPtr &origin); - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/adapter/sptag.h b/cpp/src/core/include/knowhere/adapter/sptag.h deleted file mode 100644 index 08c4a625ee..0000000000 --- a/cpp/src/core/include/knowhere/adapter/sptag.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - - -namespace zilliz { -namespace knowhere { - -std::shared_ptr -ConvertToVectorSet(const DatasetPtr &dataset); - -std::shared_ptr -ConvertToMetadataSet(const DatasetPtr &dataset); - -std::vector -ConvertToQueryResult(const DatasetPtr &dataset, const Config &config); - -DatasetPtr -ConvertToDataset(std::vector query_results); - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/common/config.h b/cpp/src/core/include/knowhere/common/config.h deleted file mode 100644 index 3a3fee1219..0000000000 --- a/cpp/src/core/include/knowhere/common/config.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - - -namespace zilliz { -namespace knowhere { - - -using Config = jsoncons::json; - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/common/device_type.h b/cpp/src/core/include/knowhere/common/device_type.h deleted file mode 100644 index 09fa362643..0000000000 --- a/cpp/src/core/include/knowhere/common/device_type.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - - -namespace zilliz { -namespace sched { -namespace master { - -} // namespace master -} // namespace sched -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/common/error.h b/cpp/src/core/include/knowhere/common/error.h deleted file mode 100644 index ba7b5cf315..0000000000 --- a/cpp/src/core/include/knowhere/common/error.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include "zlibrary/error/error.h" - - -namespace zilliz { -namespace knowhere { - -using Error = zilliz::lib::ErrorCode; - -constexpr Error STORE_SUCCESS = zilliz::lib::SUCCESS_CODE; - -constexpr Error ERROR_CODE_BASE = 0x36000; -constexpr Error ERROR_CODE_END = 0x37000; - -constexpr Error -ToGlobalErrorCode(const Error error_code) { - return zilliz::lib::ToGlobalErrorCode(error_code, ERROR_CODE_BASE); -} - -class Exception : public zilliz::lib::Exception { - public: - Exception(const Error error_code, - const std::string &message = nullptr) - : zilliz::lib::Exception(error_code, "KNOWHERE", message) {} -}; - -constexpr Error UNEXPECTED = ToGlobalErrorCode(0x001); -constexpr Error UNSUPPORTED = ToGlobalErrorCode(0x002); -constexpr Error NULL_POINTER = ToGlobalErrorCode(0x003); -constexpr Error OVERFLOW = ToGlobalErrorCode(0x004); -constexpr Error INVALID_ARGUMENT = ToGlobalErrorCode(0x005); -constexpr Error UNSUPPORTED_TYPE = ToGlobalErrorCode(0x006); - - -} // namespace store -} // namespace zilliz - -using Error = zilliz::store::Error; diff --git a/cpp/src/core/include/knowhere/common/id.h b/cpp/src/core/include/knowhere/common/id.h deleted file mode 100644 index dc823e6e22..0000000000 --- a/cpp/src/core/include/knowhere/common/id.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -//#include "zcommon/id/id.h" -//using ID = zilliz::common::ID; - -#include -#include - -namespace zilliz { -namespace knowhere { - - - -class ID { - public: - constexpr static int64_t kIDSize = 20; - - public: - const int32_t * - data() const { return content_; } - - int32_t * - mutable_data() { return content_; } - - bool - IsValid() const; - - std::string - ToString() const; - - bool - operator==(const ID &that) const; - - bool - operator<(const ID &that) const; - - protected: - int32_t content_[5] = {}; -}; - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/common/schema.h b/cpp/src/core/include/knowhere/common/schema.h deleted file mode 100644 index fe87721470..0000000000 --- a/cpp/src/core/include/knowhere/common/schema.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include "arrow/type.h" - - -namespace zilliz { -namespace knowhere { - - -using DataType = arrow::DataType; -using Field = arrow::Field; -using FieldPtr = std::shared_ptr; -using Schema = arrow::Schema; -using SchemaPtr = std::shared_ptr; -using SchemaConstPtr = std::shared_ptr; - - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/common/tensor.h b/cpp/src/core/include/knowhere/common/tensor.h deleted file mode 100644 index 93b7642cd1..0000000000 --- a/cpp/src/core/include/knowhere/common/tensor.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include "arrow/tensor.h" - - -namespace zilliz { -namespace knowhere { - - -using Tensor = arrow::Tensor; -using TensorPtr = std::shared_ptr; - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/index.h b/cpp/src/core/include/knowhere/index/index.h deleted file mode 100644 index 40f3a8d5c0..0000000000 --- a/cpp/src/core/include/knowhere/index/index.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include "knowhere/common/binary_set.h" -#include "knowhere/common/dataset.h" -#include "knowhere/index/index_type.h" -#include "knowhere/index/index_model.h" -#include "knowhere/index/preprocessor/preprocessor.h" - - -namespace zilliz { -namespace knowhere { - - -class Index { - public: - virtual BinarySet - Serialize() = 0; - - virtual void - Load(const BinarySet &index_binary) = 0; - - // @throw - virtual DatasetPtr - Search(const DatasetPtr &dataset, const Config &config) = 0; - - public: - IndexType - idx_type() const { return idx_type_; } - - void - set_idx_type(IndexType idx_type) { idx_type_ = idx_type; } - - virtual void - set_preprocessor(PreprocessorPtr preprocessor) {} - - virtual void - set_index_model(IndexModelPtr model) {} - - private: - IndexType idx_type_; -}; - - -using IndexPtr = std::shared_ptr; - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/index_model.h b/cpp/src/core/include/knowhere/index/index_model.h deleted file mode 100644 index 4b3a4e439c..0000000000 --- a/cpp/src/core/include/knowhere/index/index_model.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include "knowhere/common/binary_set.h" - -namespace zilliz { -namespace knowhere { - - -class IndexModel { - public: - virtual BinarySet - Serialize() = 0; - - virtual void - Load(const BinarySet &binary) = 0; -}; - -using IndexModelPtr = std::shared_ptr; - - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/index_type.h b/cpp/src/core/include/knowhere/index/index_type.h deleted file mode 100644 index c7f9e39057..0000000000 --- a/cpp/src/core/include/knowhere/index/index_type.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - - -namespace zilliz { -namespace knowhere { - - -enum class IndexType { - kUnknown = 0, - kVecIdxBegin = 100, - kVecIVFFlat = kVecIdxBegin, - kVecIdxEnd, -}; - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/preprocessor/preprocessor.h b/cpp/src/core/include/knowhere/index/preprocessor/preprocessor.h deleted file mode 100644 index 368276e513..0000000000 --- a/cpp/src/core/include/knowhere/index/preprocessor/preprocessor.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include "knowhere/common/dataset.h" - - -namespace zilliz { -namespace knowhere { - - -class Preprocessor { - public: - virtual DatasetPtr - Preprocess(const DatasetPtr &input) = 0; -}; - - -using PreprocessorPtr = std::shared_ptr; - - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/vector_index/definitions.h b/cpp/src/core/include/knowhere/index/vector_index/definitions.h deleted file mode 100644 index 9904597584..0000000000 --- a/cpp/src/core/include/knowhere/index/vector_index/definitions.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - - -namespace zilliz { -namespace knowhere { - -#define META_ROWS ("rows") -#define META_DIM ("dimension") -#define META_K ("k") - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/vector_index/kdt_parameters.h b/cpp/src/core/include/knowhere/index/vector_index/kdt_parameters.h deleted file mode 100644 index 6f2d631d42..0000000000 --- a/cpp/src/core/include/knowhere/index/vector_index/kdt_parameters.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - - -namespace zilliz { -namespace knowhere { - -using KDTParameter = std::pair; - -class KDTParameterManagement { - public: - const std::vector & - GetKDTParameters(); - - public: - static KDTParameterManagement & - GetInstance() { - static KDTParameterManagement instance; - return instance; - } - - KDTParameterManagement(const KDTParameterManagement &) = delete; - KDTParameterManagement &operator=(const KDTParameterManagement &) = delete; - private: - KDTParameterManagement(); - - private: - std::vector kdt_parameters_; -}; - -} // namespace knowhere -} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.i b/cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.i deleted file mode 100644 index d66dc49029..0000000000 --- a/cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.i +++ /dev/null @@ -1,15 +0,0 @@ -%module nsg -%{ -#define SWIG_FILE_WITH_INIT -#include - -/* Include the header in the wrapper code */ -#include "nsg.h" - - -%} - - -/* Parse the header file */ -%include "index.h" - diff --git a/cpp/src/core/src/CMakeLists.txt b/cpp/src/core/knowhere/CMakeLists.txt similarity index 97% rename from cpp/src/core/src/CMakeLists.txt rename to cpp/src/core/knowhere/CMakeLists.txt index a51a62b44a..6e6d81c02c 100644 --- a/cpp/src/core/src/CMakeLists.txt +++ b/cpp/src/core/knowhere/CMakeLists.txt @@ -5,7 +5,7 @@ include_directories(${TBB_DIR}/include) include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64) -include_directories(${CORE_SOURCE_DIR}/include) +include_directories(${CORE_SOURCE_DIR}/knowhere) include_directories(${CORE_SOURCE_DIR}/thirdparty) include_directories(${CORE_SOURCE_DIR}/thirdparty/SPTAG/AnnService) include_directories(${CORE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include) @@ -107,7 +107,7 @@ INSTALL(FILES ${CORE_SOURCE_DIR}/thirdparty/tbb/libtbb.so ) set(CORE_INCLUDE_DIRS - ${CORE_SOURCE_DIR}/include + ${CORE_SOURCE_DIR}/knowhere ${CORE_SOURCE_DIR}/thirdparty ${CORE_SOURCE_DIR}/thirdparty/SPTAG/AnnService ${CORE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include diff --git a/cpp/src/core/src/knowhere/adapter/arrow.cpp b/cpp/src/core/knowhere/knowhere/adapter/arrow.cpp similarity index 58% rename from cpp/src/core/src/knowhere/adapter/arrow.cpp rename to cpp/src/core/knowhere/knowhere/adapter/arrow.cpp index c70c584278..c4804d3322 100644 --- a/cpp/src/core/src/knowhere/adapter/arrow.cpp +++ b/cpp/src/core/knowhere/knowhere/adapter/arrow.cpp @@ -1,5 +1,22 @@ +// 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. -#include "knowhere/adapter/arrow.h" + +#include "arrow.h" namespace zilliz { namespace knowhere { diff --git a/cpp/src/core/knowhere/knowhere/adapter/arrow.h b/cpp/src/core/knowhere/knowhere/adapter/arrow.h new file mode 100644 index 0000000000..318336e703 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/adapter/arrow.h @@ -0,0 +1,36 @@ +// 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. + + +#pragma once + +#include + +#include "knowhere/common/array.h" + + +namespace zilliz { +namespace knowhere { + +ArrayPtr +CopyArray(const ArrayPtr &origin); + +SchemaPtr +CopySchema(const SchemaPtr &origin); + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/adapter/faiss_adopt.h b/cpp/src/core/knowhere/knowhere/adapter/faiss_adopt.h similarity index 100% rename from cpp/src/core/include/knowhere/adapter/faiss_adopt.h rename to cpp/src/core/knowhere/knowhere/adapter/faiss_adopt.h diff --git a/cpp/src/core/src/knowhere/adapter/sptag.cpp b/cpp/src/core/knowhere/knowhere/adapter/sptag.cpp similarity index 83% rename from cpp/src/core/src/knowhere/adapter/sptag.cpp rename to cpp/src/core/knowhere/knowhere/adapter/sptag.cpp index a724a27d91..995d068577 100644 --- a/cpp/src/core/src/knowhere/adapter/sptag.cpp +++ b/cpp/src/core/knowhere/knowhere/adapter/sptag.cpp @@ -1,7 +1,23 @@ +// 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. #include "knowhere/index/vector_index/definitions.h" -#include "knowhere/adapter/sptag.h" -#include "knowhere/adapter/structure.h" +#include "sptag.h" +#include "structure.h" namespace zilliz { diff --git a/cpp/src/core/knowhere/knowhere/adapter/sptag.h b/cpp/src/core/knowhere/knowhere/adapter/sptag.h new file mode 100644 index 0000000000..eb7886c263 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/adapter/sptag.h @@ -0,0 +1,43 @@ +// 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. + + +#pragma once + +#include + +#include + +#include "knowhere/common/dataset.h" + +namespace zilliz { +namespace knowhere { + +std::shared_ptr +ConvertToVectorSet(const DatasetPtr &dataset); + +std::shared_ptr +ConvertToMetadataSet(const DatasetPtr &dataset); + +std::vector +ConvertToQueryResult(const DatasetPtr &dataset, const Config &config); + +DatasetPtr +ConvertToDataset(std::vector query_results); + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/src/knowhere/adapter/structure.cpp b/cpp/src/core/knowhere/knowhere/adapter/structure.cpp similarity index 98% rename from cpp/src/core/src/knowhere/adapter/structure.cpp rename to cpp/src/core/knowhere/knowhere/adapter/structure.cpp index f30479dd5a..10b6af8138 100644 --- a/cpp/src/core/src/knowhere/adapter/structure.cpp +++ b/cpp/src/core/knowhere/knowhere/adapter/structure.cpp @@ -16,7 +16,7 @@ // under the License. -#include "knowhere/adapter/structure.h" +#include "structure.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/adapter/structure.h b/cpp/src/core/knowhere/knowhere/adapter/structure.h similarity index 97% rename from cpp/src/core/include/knowhere/adapter/structure.h rename to cpp/src/core/knowhere/knowhere/adapter/structure.h index 9ffac4fdac..76a03a23e4 100644 --- a/cpp/src/core/include/knowhere/adapter/structure.h +++ b/cpp/src/core/knowhere/knowhere/adapter/structure.h @@ -19,7 +19,7 @@ #pragma once #include -#include +#include "knowhere/common/dataset.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/common/array.h b/cpp/src/core/knowhere/knowhere/common/array.h similarity index 52% rename from cpp/src/core/include/knowhere/common/array.h rename to cpp/src/core/knowhere/knowhere/common/array.h index f3d0310596..1860524e8a 100644 --- a/cpp/src/core/include/knowhere/common/array.h +++ b/cpp/src/core/knowhere/knowhere/common/array.h @@ -1,7 +1,25 @@ +// 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. + + #pragma once #include "arrow/array.h" -#include "knowhere/common/schema.h" +#include "schema.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/common/binary_set.h b/cpp/src/core/knowhere/knowhere/common/binary_set.h similarity index 58% rename from cpp/src/core/include/knowhere/common/binary_set.h rename to cpp/src/core/knowhere/knowhere/common/binary_set.h index b83d96dfe4..019c42a2b9 100644 --- a/cpp/src/core/include/knowhere/common/binary_set.h +++ b/cpp/src/core/knowhere/knowhere/common/binary_set.h @@ -1,3 +1,21 @@ +// 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. + + #pragma once #include @@ -5,7 +23,7 @@ #include #include -#include "knowhere/common/id.h" +#include "id.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/common/buffer.h b/cpp/src/core/knowhere/knowhere/common/buffer.h similarity index 56% rename from cpp/src/core/include/knowhere/common/buffer.h rename to cpp/src/core/knowhere/knowhere/common/buffer.h index 44867e760a..019c0487b7 100644 --- a/cpp/src/core/include/knowhere/common/buffer.h +++ b/cpp/src/core/knowhere/knowhere/common/buffer.h @@ -1,6 +1,25 @@ +// 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. + + #pragma once #include + #include "arrow/buffer.h" diff --git a/cpp/src/core/knowhere/knowhere/common/config.h b/cpp/src/core/knowhere/knowhere/common/config.h new file mode 100644 index 0000000000..399555c0e9 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/common/config.h @@ -0,0 +1,32 @@ +// 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. + + +#pragma once + +#include + + +namespace zilliz { +namespace knowhere { + + +using Config = jsoncons::json; + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/include/knowhere/common/dataset.h b/cpp/src/core/knowhere/knowhere/common/dataset.h similarity index 77% rename from cpp/src/core/include/knowhere/common/dataset.h rename to cpp/src/core/knowhere/knowhere/common/dataset.h index ee1d6e5100..068bbe4356 100644 --- a/cpp/src/core/include/knowhere/common/dataset.h +++ b/cpp/src/core/knowhere/knowhere/common/dataset.h @@ -1,12 +1,31 @@ +// 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. + + #pragma once #include #include -#include "knowhere/common/array.h" -#include "knowhere/common/buffer.h" -#include "knowhere/common/tensor.h" -#include "knowhere/common/schema.h" -#include "knowhere/common/config.h" + +#include "array.h" +#include "buffer.h" +#include "tensor.h" +#include "schema.h" +#include "config.h" #include "knowhere/adapter/arrow.h" diff --git a/cpp/src/core/src/knowhere/common/exception.cpp b/cpp/src/core/knowhere/knowhere/common/exception.cpp similarity index 97% rename from cpp/src/core/src/knowhere/common/exception.cpp rename to cpp/src/core/knowhere/knowhere/common/exception.cpp index f46cbfc35a..fcf3886d9b 100644 --- a/cpp/src/core/src/knowhere/common/exception.cpp +++ b/cpp/src/core/knowhere/knowhere/common/exception.cpp @@ -16,9 +16,10 @@ // under the License. -#include "knowhere/common/exception.h" #include +#include "exception.h" + namespace zilliz { namespace knowhere { diff --git a/cpp/src/core/include/knowhere/common/exception.h b/cpp/src/core/knowhere/knowhere/common/exception.h similarity index 100% rename from cpp/src/core/include/knowhere/common/exception.h rename to cpp/src/core/knowhere/knowhere/common/exception.h diff --git a/cpp/src/core/knowhere/knowhere/common/id.h b/cpp/src/core/knowhere/knowhere/common/id.h new file mode 100644 index 0000000000..87e1467c44 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/common/id.h @@ -0,0 +1,60 @@ +// 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. + + +#pragma once + +//#include "zcommon/id/id.h" +//using ID = zilliz::common::ID; + +#include +#include + +namespace zilliz { +namespace knowhere { + + + +class ID { + public: + constexpr static int64_t kIDSize = 20; + + public: + const int32_t * + data() const { return content_; } + + int32_t * + mutable_data() { return content_; } + + bool + IsValid() const; + + std::string + ToString() const; + + bool + operator==(const ID &that) const; + + bool + operator<(const ID &that) const; + + protected: + int32_t content_[5] = {}; +}; + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/knowhere/knowhere/common/schema.h b/cpp/src/core/knowhere/knowhere/common/schema.h new file mode 100644 index 0000000000..1ab3d42f8c --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/common/schema.h @@ -0,0 +1,40 @@ +// 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. + + +#pragma once + +#include + +#include "arrow/type.h" + + +namespace zilliz { +namespace knowhere { + + +using DataType = arrow::DataType; +using Field = arrow::Field; +using FieldPtr = std::shared_ptr; +using Schema = arrow::Schema; +using SchemaPtr = std::shared_ptr; +using SchemaConstPtr = std::shared_ptr; + + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/knowhere/knowhere/common/tensor.h b/cpp/src/core/knowhere/knowhere/common/tensor.h new file mode 100644 index 0000000000..8b92f1f891 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/common/tensor.h @@ -0,0 +1,35 @@ +// 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. + + +#pragma once + +#include + +#include "arrow/tensor.h" + + +namespace zilliz { +namespace knowhere { + + +using Tensor = arrow::Tensor; +using TensorPtr = std::shared_ptr; + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/src/knowhere/common/timer.cpp b/cpp/src/core/knowhere/knowhere/common/timer.cpp similarity index 98% rename from cpp/src/core/src/knowhere/common/timer.cpp rename to cpp/src/core/knowhere/knowhere/common/timer.cpp index 08654413ff..f57de535d4 100644 --- a/cpp/src/core/src/knowhere/common/timer.cpp +++ b/cpp/src/core/knowhere/knowhere/common/timer.cpp @@ -18,7 +18,7 @@ #include // TODO(linxj): using Log instead -#include "knowhere/common/timer.h" +#include "timer.h" namespace zilliz { namespace knowhere { diff --git a/cpp/src/core/include/knowhere/common/timer.h b/cpp/src/core/knowhere/knowhere/common/timer.h similarity index 100% rename from cpp/src/core/include/knowhere/common/timer.h rename to cpp/src/core/knowhere/knowhere/common/timer.h diff --git a/cpp/src/core/knowhere/knowhere/index/index.h b/cpp/src/core/knowhere/knowhere/index/index.h new file mode 100644 index 0000000000..275a5fd387 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/index/index.h @@ -0,0 +1,68 @@ +// 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. + + +#pragma once + +#include + +#include "knowhere/common/binary_set.h" +#include "knowhere/common/dataset.h" +#include "index_type.h" +#include "index_model.h" +#include "knowhere/index/preprocessor/preprocessor.h" + + +namespace zilliz { +namespace knowhere { + + +class Index { + public: + virtual BinarySet + Serialize() = 0; + + virtual void + Load(const BinarySet &index_binary) = 0; + + // @throw + virtual DatasetPtr + Search(const DatasetPtr &dataset, const Config &config) = 0; + + public: + IndexType + idx_type() const { return idx_type_; } + + void + set_idx_type(IndexType idx_type) { idx_type_ = idx_type; } + + virtual void + set_preprocessor(PreprocessorPtr preprocessor) {} + + virtual void + set_index_model(IndexModelPtr model) {} + + private: + IndexType idx_type_; +}; + + +using IndexPtr = std::shared_ptr; + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/knowhere/knowhere/index/index_model.h b/cpp/src/core/knowhere/knowhere/index/index_model.h new file mode 100644 index 0000000000..d00a629d7e --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/index/index_model.h @@ -0,0 +1,42 @@ +// 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. + + +#pragma once + +#include +#include "knowhere/common/binary_set.h" + +namespace zilliz { +namespace knowhere { + + +class IndexModel { + public: + virtual BinarySet + Serialize() = 0; + + virtual void + Load(const BinarySet &binary) = 0; +}; + +using IndexModelPtr = std::shared_ptr; + + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/knowhere/knowhere/index/index_type.h b/cpp/src/core/knowhere/knowhere/index/index_type.h new file mode 100644 index 0000000000..3ece6287f5 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/index/index_type.h @@ -0,0 +1,35 @@ +// 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. + + +#pragma once + + +namespace zilliz { +namespace knowhere { + + +enum class IndexType { + kUnknown = 0, + kVecIdxBegin = 100, + kVecIVFFlat = kVecIdxBegin, + kVecIdxEnd, +}; + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/src/knowhere/index/preprocessor/normalize.cpp b/cpp/src/core/knowhere/knowhere/index/preprocessor/normalize.cpp similarity index 100% rename from cpp/src/core/src/knowhere/index/preprocessor/normalize.cpp rename to cpp/src/core/knowhere/knowhere/index/preprocessor/normalize.cpp diff --git a/cpp/src/core/include/knowhere/index/preprocessor/normalize.h b/cpp/src/core/knowhere/knowhere/index/preprocessor/normalize.h similarity index 100% rename from cpp/src/core/include/knowhere/index/preprocessor/normalize.h rename to cpp/src/core/knowhere/knowhere/index/preprocessor/normalize.h diff --git a/cpp/src/core/knowhere/knowhere/index/preprocessor/preprocessor.h b/cpp/src/core/knowhere/knowhere/index/preprocessor/preprocessor.h new file mode 100644 index 0000000000..10f0544270 --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/index/preprocessor/preprocessor.h @@ -0,0 +1,41 @@ +// 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. + + +#pragma once + +#include + +#include "knowhere/common/dataset.h" + + +namespace zilliz { +namespace knowhere { + + +class Preprocessor { + public: + virtual DatasetPtr + Preprocess(const DatasetPtr &input) = 0; +}; + + +using PreprocessorPtr = std::shared_ptr; + + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/src/knowhere/index/vector_index/cloner.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/cloner.cpp similarity index 91% rename from cpp/src/core/src/knowhere/index/vector_index/cloner.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/cloner.cpp index f5bcfb896d..4519def300 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/cloner.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/cloner.cpp @@ -17,10 +17,10 @@ #include "knowhere/common/exception.h" -#include "knowhere/index/vector_index/cloner.h" -#include "knowhere/index/vector_index/ivf.h" -#include "knowhere/index/vector_index/gpu_ivf.h" -#include "knowhere/index/vector_index/idmap.h" +#include "cloner.h" +#include "ivf.h" +#include "gpu_ivf.h" +#include "idmap.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/index/vector_index/cloner.h b/cpp/src/core/knowhere/knowhere/index/vector_index/cloner.h similarity index 100% rename from cpp/src/core/include/knowhere/index/vector_index/cloner.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/cloner.h diff --git a/cpp/src/core/src/knowhere/index/vector_index/cpu_kdt_rng.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/cpu_kdt_rng.cpp similarity index 83% rename from cpp/src/core/src/knowhere/index/vector_index/cpu_kdt_rng.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/cpu_kdt_rng.cpp index 0805398144..d588efb7c6 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/cpu_kdt_rng.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/cpu_kdt_rng.cpp @@ -1,3 +1,20 @@ +// 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. + #include #include @@ -7,10 +24,10 @@ #undef mkdir -#include "knowhere/index/vector_index/cpu_kdt_rng.h" -#include "knowhere/index/vector_index/definitions.h" +#include "cpu_kdt_rng.h" +#include "definitions.h" //#include "knowhere/index/preprocessor/normalize.h" -#include "knowhere/index/vector_index/kdt_parameters.h" +#include "kdt_parameters.h" #include "knowhere/adapter/sptag.h" #include "knowhere/common/exception.h" diff --git a/cpp/src/core/include/knowhere/index/vector_index/cpu_kdt_rng.h b/cpp/src/core/knowhere/knowhere/index/vector_index/cpu_kdt_rng.h similarity index 66% rename from cpp/src/core/include/knowhere/index/vector_index/cpu_kdt_rng.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/cpu_kdt_rng.h index 0e1cc55e5d..35d488999e 100644 --- a/cpp/src/core/include/knowhere/index/vector_index/cpu_kdt_rng.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/cpu_kdt_rng.h @@ -1,8 +1,26 @@ +// 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. + + #pragma once #include #include -#include "knowhere/index/vector_index/vector_index.h" +#include "vector_index.h" #include "knowhere/index/index_model.h" #include diff --git a/cpp/src/core/knowhere/knowhere/index/vector_index/definitions.h b/cpp/src/core/knowhere/knowhere/index/vector_index/definitions.h new file mode 100644 index 0000000000..3db32e00dc --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/definitions.h @@ -0,0 +1,32 @@ +// 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. + + +#pragma once + +#include + + +namespace zilliz { +namespace knowhere { + +#define META_ROWS ("rows") +#define META_DIM ("dimension") +#define META_K ("k") + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp similarity index 99% rename from cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp index 590ded16bf..fd04501c83 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp @@ -27,9 +27,9 @@ #include "knowhere/common/exception.h" -#include "knowhere/index/vector_index/cloner.h" +#include "cloner.h" #include "knowhere/adapter/faiss_adopt.h" -#include "knowhere/index/vector_index/gpu_ivf.h" +#include "gpu_ivf.h" #include diff --git a/cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.h similarity index 87% rename from cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.h index 8eed6f8fd1..429a94167a 100644 --- a/cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.h @@ -1,3 +1,21 @@ +// 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. + + #pragma once #include diff --git a/cpp/src/core/src/knowhere/index/vector_index/idmap.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/idmap.cpp similarity index 99% rename from cpp/src/core/src/knowhere/index/vector_index/idmap.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/idmap.cpp index 142d06b5d8..b4085e6df8 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/idmap.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/idmap.cpp @@ -25,7 +25,7 @@ #include "knowhere/common/exception.h" #include "knowhere/adapter/faiss_adopt.h" -#include "knowhere/index/vector_index/idmap.h" +#include "idmap.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/index/vector_index/idmap.h b/cpp/src/core/knowhere/knowhere/index/vector_index/idmap.h similarity index 100% rename from cpp/src/core/include/knowhere/index/vector_index/idmap.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/idmap.h diff --git a/cpp/src/core/src/knowhere/index/vector_index/ivf.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/ivf.cpp similarity index 98% rename from cpp/src/core/src/knowhere/index/vector_index/ivf.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/ivf.cpp index acfbb17651..6d72479002 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/ivf.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/ivf.cpp @@ -25,13 +25,12 @@ #include #include #include -#include #include "knowhere/common/exception.h" -#include "knowhere/index/vector_index/ivf.h" +#include "ivf.h" #include "knowhere/adapter/faiss_adopt.h" -#include "knowhere/index/vector_index/gpu_ivf.h" +#include "gpu_ivf.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/index/vector_index/ivf.h b/cpp/src/core/knowhere/knowhere/index/vector_index/ivf.h similarity index 98% rename from cpp/src/core/include/knowhere/index/vector_index/ivf.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/ivf.h index e8ac6cae99..c23b5abcc2 100644 --- a/cpp/src/core/include/knowhere/index/vector_index/ivf.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/ivf.h @@ -25,7 +25,7 @@ #include #include -#include "knowhere/index/vector_index/vector_index.h" +#include "vector_index.h" namespace zilliz { diff --git a/cpp/src/core/src/knowhere/index/vector_index/kdt_parameters.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/kdt_parameters.cpp similarity index 54% rename from cpp/src/core/src/knowhere/index/vector_index/kdt_parameters.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/kdt_parameters.cpp index 9f62b5d3a2..b0ed9f6d56 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/kdt_parameters.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/kdt_parameters.cpp @@ -1,6 +1,24 @@ +// 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. + #include -#include "knowhere/index/vector_index/kdt_parameters.h" + +#include "kdt_parameters.h" namespace zilliz { diff --git a/cpp/src/core/knowhere/knowhere/index/vector_index/kdt_parameters.h b/cpp/src/core/knowhere/knowhere/index/vector_index/kdt_parameters.h new file mode 100644 index 0000000000..03f660a0ef --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/kdt_parameters.h @@ -0,0 +1,52 @@ +// 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. + + +#pragma once + +#include +#include + + +namespace zilliz { +namespace knowhere { + +using KDTParameter = std::pair; + +class KDTParameterManagement { + public: + const std::vector & + GetKDTParameters(); + + public: + static KDTParameterManagement & + GetInstance() { + static KDTParameterManagement instance; + return instance; + } + + KDTParameterManagement(const KDTParameterManagement &) = delete; + KDTParameterManagement &operator=(const KDTParameterManagement &) = delete; + private: + KDTParameterManagement(); + + private: + std::vector kdt_parameters_; +}; + +} // namespace knowhere +} // namespace zilliz diff --git a/cpp/src/core/src/knowhere/index/vector_index/nsg/index_io.h b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/index_io.h similarity index 95% rename from cpp/src/core/src/knowhere/index/vector_index/nsg/index_io.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/index_io.h index fd8fc9e7ad..60e27bd7f6 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/nsg/index_io.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/index_io.h @@ -18,7 +18,7 @@ #pragma once -#include "knowhere/index/vector_index/nsg/nsg.h" +#include "nsg.h" namespace zilliz { namespace knowhere { diff --git a/cpp/src/core/include/knowhere/index/vector_index/nsg/neighbor.h b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/neighbor.h similarity index 100% rename from cpp/src/core/include/knowhere/index/vector_index/nsg/neighbor.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/neighbor.h diff --git a/cpp/src/core/src/knowhere/index/vector_index/nsg/nsg.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg.cpp similarity index 99% rename from cpp/src/core/src/knowhere/index/vector_index/nsg/nsg.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg.cpp index d3efc5e38a..d42f4c5662 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/nsg/nsg.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg.cpp @@ -22,7 +22,7 @@ #include #include -#include "knowhere/index/vector_index/nsg/nsg.h" +#include "nsg.h" #include "knowhere/common/exception.h" #include "knowhere/common/timer.h" #include "utils.h" diff --git a/cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.h b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg.h similarity index 100% rename from cpp/src/core/include/knowhere/index/vector_index/nsg/nsg.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg.h diff --git a/cpp/src/core/src/knowhere/index/vector_index/nsg/nsg_io.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg_io.cpp similarity index 97% rename from cpp/src/core/src/knowhere/index/vector_index/nsg/nsg_io.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg_io.cpp index 283e8cc7e2..34d629ec4b 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/nsg/nsg_io.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg_io.cpp @@ -18,7 +18,7 @@ #include -#include "knowhere/index/vector_index/nsg/nsg_io.h" +#include "nsg_io.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/index/vector_index/nsg/nsg_io.h b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg_io.h similarity index 100% rename from cpp/src/core/include/knowhere/index/vector_index/nsg/nsg_io.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/nsg_io.h diff --git a/cpp/src/core/src/knowhere/index/vector_index/nsg/utils.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/utils.cpp similarity index 100% rename from cpp/src/core/src/knowhere/index/vector_index/nsg/utils.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/utils.cpp diff --git a/cpp/src/core/src/knowhere/index/vector_index/nsg/utils.h b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/utils.h similarity index 95% rename from cpp/src/core/src/knowhere/index/vector_index/nsg/utils.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg/utils.h index 82c8a00dc8..a57a7738fd 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/nsg/utils.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg/utils.h @@ -23,7 +23,7 @@ #include -#include "knowhere/index/vector_index/nsg/nsg.h" +#include "nsg.h" #include "knowhere/common/config.h" diff --git a/cpp/src/core/src/knowhere/index/vector_index/nsg_index.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg_index.cpp similarity index 96% rename from cpp/src/core/src/knowhere/index/vector_index/nsg_index.cpp rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg_index.cpp index 550efef70d..724c80dfca 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/nsg_index.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg_index.cpp @@ -16,12 +16,12 @@ // under the License. -#include "knowhere/index/vector_index/nsg_index.h" +#include "nsg_index.h" #include "knowhere/index/vector_index/nsg/nsg.h" #include "knowhere/index/vector_index/nsg/nsg_io.h" -#include "knowhere/index/vector_index/idmap.h" -#include "knowhere/index/vector_index/ivf.h" -#include "knowhere/index/vector_index/gpu_ivf.h" +#include "idmap.h" +#include "ivf.h" +#include "gpu_ivf.h" #include "knowhere/adapter/faiss_adopt.h" #include "knowhere/common/exception.h" #include "knowhere/common/timer.h" diff --git a/cpp/src/core/include/knowhere/index/vector_index/nsg_index.h b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg_index.h similarity index 96% rename from cpp/src/core/include/knowhere/index/vector_index/nsg_index.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/nsg_index.h index a0829f381c..e63dbb03b4 100644 --- a/cpp/src/core/include/knowhere/index/vector_index/nsg_index.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/nsg_index.h @@ -18,7 +18,7 @@ #pragma once -#include "knowhere/index/vector_index/vector_index.h" +#include "vector_index.h" namespace zilliz { diff --git a/cpp/src/core/include/knowhere/index/vector_index/vector_index.h b/cpp/src/core/knowhere/knowhere/index/vector_index/vector_index.h similarity index 52% rename from cpp/src/core/include/knowhere/index/vector_index/vector_index.h rename to cpp/src/core/knowhere/knowhere/index/vector_index/vector_index.h index 1618bc01bb..1828e3573d 100644 --- a/cpp/src/core/include/knowhere/index/vector_index/vector_index.h +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/vector_index.h @@ -1,7 +1,26 @@ +// 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. + + #pragma once #include + #include "knowhere/common/config.h" #include "knowhere/common/dataset.h" #include "knowhere/index/index.h" diff --git a/cpp/src/core/test/CMakeLists.txt b/cpp/src/core/test/CMakeLists.txt index cba8a03b94..5b8dca2e4b 100644 --- a/cpp/src/core/test/CMakeLists.txt +++ b/cpp/src/core/test/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(${CORE_SOURCE_DIR}/thirdparty) include_directories(${CORE_SOURCE_DIR}/thirdparty/SPTAG/AnnService) -include_directories(${CORE_SOURCE_DIR}/include) +include_directories(${CORE_SOURCE_DIR}/knowhere) include_directories(${CORE_SOURCE_DIR}/thirdparty/jsoncons-0.126.0/include) include_directories(/usr/local/cuda/include) link_directories(/usr/local/cuda/lib64) @@ -25,13 +25,13 @@ set(basic_libs # set(ivf_srcs - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/ivf.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/gpu_ivf.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/cloner.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/idmap.cpp - ${CORE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp - ${CORE_SOURCE_DIR}/src/knowhere/common/exception.cpp - ${CORE_SOURCE_DIR}/src/knowhere/common/timer.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/ivf.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/gpu_ivf.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/cloner.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/idmap.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/adapter/structure.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/common/exception.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/common/timer.cpp utils.cpp ) if(NOT TARGET test_ivf) @@ -41,13 +41,13 @@ target_link_libraries(test_ivf ${depend_libs} ${unittest_libs} ${basic_libs}) # set(idmap_srcs - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/idmap.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/ivf.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/cloner.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/gpu_ivf.cpp - ${CORE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp - ${CORE_SOURCE_DIR}/src/knowhere/common/exception.cpp - ${CORE_SOURCE_DIR}/src/knowhere/common/timer.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/idmap.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/ivf.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/cloner.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/gpu_ivf.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/adapter/structure.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/common/exception.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/common/timer.cpp utils.cpp ) if(NOT TARGET test_idmap) @@ -57,14 +57,14 @@ target_link_libraries(test_idmap ${depend_libs} ${unittest_libs} ${basic_libs}) # set(kdt_srcs - ${CORE_SOURCE_DIR}/src/knowhere/index/preprocessor/normalize.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/kdt_parameters.cpp - ${CORE_SOURCE_DIR}/src/knowhere/index/vector_index/cpu_kdt_rng.cpp - ${CORE_SOURCE_DIR}/src/knowhere/adapter/structure.cpp - ${CORE_SOURCE_DIR}/src/knowhere/adapter/sptag.cpp - ${CORE_SOURCE_DIR}/src/knowhere/common/exception.cpp - ${CORE_SOURCE_DIR}/src/knowhere/adapter/arrow.cpp - ${CORE_SOURCE_DIR}/src/knowhere/common/timer.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/preprocessor/normalize.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/kdt_parameters.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/index/vector_index/cpu_kdt_rng.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/adapter/structure.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/adapter/sptag.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/common/exception.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/adapter/arrow.cpp + ${CORE_SOURCE_DIR}/knowhere/knowhere/common/timer.cpp utils.cpp ) if(NOT TARGET test_kdt) diff --git a/cpp/src/db/engine/ExecutionEngineImpl.cpp b/cpp/src/db/engine/ExecutionEngineImpl.cpp index 7ad9d3ea12..2fb868f548 100644 --- a/cpp/src/db/engine/ExecutionEngineImpl.cpp +++ b/cpp/src/db/engine/ExecutionEngineImpl.cpp @@ -23,8 +23,8 @@ #include "utils/CommonUtil.h" #include "utils/Exception.h" -#include "wrapper/knowhere/vec_index.h" -#include "wrapper/knowhere/vec_impl.h" +#include "src/wrapper/vec_index.h" +#include "src/wrapper/vec_impl.h" #include "knowhere/common/exception.h" #include diff --git a/cpp/src/db/engine/ExecutionEngineImpl.h b/cpp/src/db/engine/ExecutionEngineImpl.h index 611a247a08..cb08c50ad4 100644 --- a/cpp/src/db/engine/ExecutionEngineImpl.h +++ b/cpp/src/db/engine/ExecutionEngineImpl.h @@ -18,7 +18,7 @@ #pragma once #include "ExecutionEngine.h" -#include "wrapper/knowhere/vec_index.h" +#include "src/wrapper/vec_index.h" #include #include diff --git a/cpp/src/server/Server.cpp b/cpp/src/server/Server.cpp index 252f92a5f0..9920b30246 100644 --- a/cpp/src/server/Server.cpp +++ b/cpp/src/server/Server.cpp @@ -32,7 +32,7 @@ #include #include #include -#include "wrapper/knowhere/KnowhereResource.h" +#include "src/wrapper/KnowhereResource.h" #include "metrics/Metrics.h" #include "DBWrapper.h" diff --git a/cpp/src/wrapper/knowhere/KnowhereResource.cpp b/cpp/src/wrapper/KnowhereResource.cpp similarity index 100% rename from cpp/src/wrapper/knowhere/KnowhereResource.cpp rename to cpp/src/wrapper/KnowhereResource.cpp diff --git a/cpp/src/wrapper/knowhere/KnowhereResource.h b/cpp/src/wrapper/KnowhereResource.h similarity index 100% rename from cpp/src/wrapper/knowhere/KnowhereResource.h rename to cpp/src/wrapper/KnowhereResource.h diff --git a/cpp/src/wrapper/knowhere/data_transfer.cpp b/cpp/src/wrapper/data_transfer.cpp similarity index 100% rename from cpp/src/wrapper/knowhere/data_transfer.cpp rename to cpp/src/wrapper/data_transfer.cpp diff --git a/cpp/src/wrapper/knowhere/data_transfer.h b/cpp/src/wrapper/data_transfer.h similarity index 100% rename from cpp/src/wrapper/knowhere/data_transfer.h rename to cpp/src/wrapper/data_transfer.h diff --git a/cpp/src/wrapper/gpu/Arithmetic.h b/cpp/src/wrapper/gpu/Arithmetic.h deleted file mode 100644 index c6ab7a2bc8..0000000000 --- a/cpp/src/wrapper/gpu/Arithmetic.h +++ /dev/null @@ -1,79 +0,0 @@ -// 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. - -#pragma once - -#include -#include -#include -#include - - -namespace zilliz { -namespace milvus { -namespace engine { - -using Bool = int8_t; -using Byte = uint8_t; -using Word = unsigned long; -using EnumType = uint64_t; - -using Float32 = float; -using Float64 = double; - -constexpr bool kBoolMax = std::numeric_limits::max(); -constexpr bool kBoolMin = std::numeric_limits::lowest(); - -constexpr int8_t kInt8Max = std::numeric_limits::max(); -constexpr int8_t kInt8Min = std::numeric_limits::lowest(); - -constexpr int16_t kInt16Max = std::numeric_limits::max(); -constexpr int16_t kInt16Min = std::numeric_limits::lowest(); - -constexpr int32_t kInt32Max = std::numeric_limits::max(); -constexpr int32_t kInt32Min = std::numeric_limits::lowest(); - -constexpr int64_t kInt64Max = std::numeric_limits::max(); -constexpr int64_t kInt64Min = std::numeric_limits::lowest(); - -constexpr float kFloatMax = std::numeric_limits::max(); -constexpr float kFloatMin = std::numeric_limits::lowest(); - -constexpr double kDoubleMax = std::numeric_limits::max(); -constexpr double kDoubleMin = std::numeric_limits::lowest(); - -constexpr uint32_t kFloat32DecimalPrecision = std::numeric_limits::digits10; -constexpr uint32_t kFloat64DecimalPrecision = std::numeric_limits::digits10; - - -constexpr uint8_t kByteWidth = 8; -constexpr uint8_t kCharWidth = kByteWidth; -constexpr uint8_t kWordWidth = sizeof(Word) * kByteWidth; -constexpr uint8_t kEnumTypeWidth = sizeof(EnumType) * kByteWidth; - -template -inline size_t -WidthOf() { return sizeof(T) << 3; } - -template -inline size_t -WidthOf(const T &) { return sizeof(T) << 3; } - - -} -} // namespace lib -} // namespace zilliz diff --git a/cpp/src/wrapper/gpu/Topk.cu b/cpp/src/wrapper/gpu/Topk.cu deleted file mode 100644 index 423c8806c4..0000000000 --- a/cpp/src/wrapper/gpu/Topk.cu +++ /dev/null @@ -1,586 +0,0 @@ -// 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. - - -#include "faiss/FaissAssert.h" -#include "faiss/gpu/utils/Limits.cuh" -#include "Arithmetic.h" - - -namespace faiss { -namespace gpu { - -constexpr bool kBoolMax = zilliz::milvus::engine::kBoolMax; -constexpr bool kBoolMin = zilliz::milvus::engine::kBoolMin; - -template<> -struct Limits { - static __device__ __host__ - inline bool getMin() { - return kBoolMin; - } - static __device__ __host__ - inline bool getMax() { - return kBoolMax; - } -}; - -constexpr int8_t kInt8Max = zilliz::milvus::engine::kInt8Max; -constexpr int8_t kInt8Min = zilliz::milvus::engine::kInt8Min; - -template<> -struct Limits { - static __device__ __host__ - inline int8_t getMin() { - return kInt8Min; - } - static __device__ __host__ - inline int8_t getMax() { - return kInt8Max; - } -}; - -constexpr int16_t kInt16Max = zilliz::milvus::engine::kInt16Max; -constexpr int16_t kInt16Min = zilliz::milvus::engine::kInt16Min; - -template<> -struct Limits { - static __device__ __host__ - inline int16_t getMin() { - return kInt16Min; - } - static __device__ __host__ - inline int16_t getMax() { - return kInt16Max; - } -}; - -constexpr int64_t kInt64Max = zilliz::milvus::engine::kInt64Max; -constexpr int64_t kInt64Min = zilliz::milvus::engine::kInt64Min; - -template<> -struct Limits { - static __device__ __host__ - inline int64_t getMin() { - return kInt64Min; - } - static __device__ __host__ - inline int64_t getMax() { - return kInt64Max; - } -}; - -constexpr double kDoubleMax = zilliz::milvus::engine::kDoubleMax; -constexpr double kDoubleMin = zilliz::milvus::engine::kDoubleMin; - -template<> -struct Limits { - static __device__ __host__ - inline double getMin() { - return kDoubleMin; - } - static __device__ __host__ - inline double getMax() { - return kDoubleMax; - } -}; - -} -} - -#include "faiss/gpu/utils/DeviceUtils.h" -#include "faiss/gpu/utils/MathOperators.cuh" -#include "faiss/gpu/utils/Pair.cuh" -#include "faiss/gpu/utils/Reductions.cuh" -#include "faiss/gpu/utils/Select.cuh" -#include "faiss/gpu/utils/Tensor.cuh" -#include "faiss/gpu/utils/StaticUtils.h" - -#include "Topk.h" - - -namespace zilliz { -namespace milvus { -namespace engine { -namespace gpu { - -constexpr int kWarpSize = 32; - -template -using Tensor = faiss::gpu::Tensor; - -template -using Pair = faiss::gpu::Pair; - - -// select kernel for k == 1 -template -__global__ void topkSelectMin1(Tensor productDistances, - Tensor outDistances, - Tensor outIndices) { - // Each block handles kRowsPerBlock rows of the distances (results) - Pair threadMin[kRowsPerBlock]; - __shared__ - Pair blockMin[kRowsPerBlock * (kBlockSize / kWarpSize)]; - - T distance[kRowsPerBlock]; - -#pragma unroll - for (int i = 0; i < kRowsPerBlock; ++i) { - threadMin[i].k = faiss::gpu::Limits::getMax(); - threadMin[i].v = -1; - } - - // blockIdx.x: which chunk of rows we are responsible for updating - int rowStart = blockIdx.x * kRowsPerBlock; - - // FIXME: if we have exact multiples, don't need this - bool endRow = (blockIdx.x == gridDim.x - 1); - - if (endRow) { - if (productDistances.getSize(0) % kRowsPerBlock == 0) { - endRow = false; - } - } - - if (endRow) { - for (int row = rowStart; row < productDistances.getSize(0); ++row) { - for (int col = threadIdx.x; col < productDistances.getSize(1); - col += blockDim.x) { - distance[0] = productDistances[row][col]; - - if (faiss::gpu::Math::lt(distance[0], threadMin[0].k)) { - threadMin[0].k = distance[0]; - threadMin[0].v = col; - } - } - - // Reduce within the block - threadMin[0] = - faiss::gpu::blockReduceAll, faiss::gpu::Min >, false, false>( - threadMin[0], faiss::gpu::Min >(), blockMin); - - if (threadIdx.x == 0) { - outDistances[row][0] = threadMin[0].k; - outIndices[row][0] = threadMin[0].v; - } - - // so we can use the shared memory again - __syncthreads(); - - threadMin[0].k = faiss::gpu::Limits::getMax(); - threadMin[0].v = -1; - } - } else { - for (int col = threadIdx.x; col < productDistances.getSize(1); - col += blockDim.x) { - -#pragma unroll - for (int row = 0; row < kRowsPerBlock; ++row) { - distance[row] = productDistances[rowStart + row][col]; - } - -#pragma unroll - for (int row = 0; row < kRowsPerBlock; ++row) { - if (faiss::gpu::Math::lt(distance[row], threadMin[row].k)) { - threadMin[row].k = distance[row]; - threadMin[row].v = col; - } - } - } - - // Reduce within the block - faiss::gpu::blockReduceAll, faiss::gpu::Min >, false, false>( - threadMin, faiss::gpu::Min >(), blockMin); - - if (threadIdx.x == 0) { -#pragma unroll - for (int row = 0; row < kRowsPerBlock; ++row) { - outDistances[rowStart + row][0] = threadMin[row].k; - outIndices[rowStart + row][0] = threadMin[row].v; - } - } - } -} - -// L2 + select kernel for k > 1, no re-use of ||c||^2 -template -__global__ void topkSelectMinK(Tensor productDistances, - Tensor outDistances, - Tensor outIndices, - int k, T initK) { - // Each block handles a single row of the distances (results) - constexpr int kNumWarps = ThreadsPerBlock / kWarpSize; - - __shared__ - T smemK[kNumWarps * NumWarpQ]; - __shared__ - int64_t smemV[kNumWarps * NumWarpQ]; - - faiss::gpu::BlockSelect, - NumWarpQ, NumThreadQ, ThreadsPerBlock> - heap(initK, -1, smemK, smemV, k); - - int row = blockIdx.x; - - // Whole warps must participate in the selection - int limit = faiss::gpu::utils::roundDown(productDistances.getSize(1), kWarpSize); - int i = threadIdx.x; - - for (; i < limit; i += blockDim.x) { - T v = productDistances[row][i]; - heap.add(v, i); - } - - if (i < productDistances.getSize(1)) { - T v = productDistances[row][i]; - heap.addThreadQ(v, i); - } - - heap.reduce(); - for (int i = threadIdx.x; i < k; i += blockDim.x) { - outDistances[row][i] = smemK[i]; - outIndices[row][i] = smemV[i]; - } -} - -// FIXME: no TVec specialization -template -void runTopKSelectMin(Tensor &productDistances, - Tensor &outDistances, - Tensor &outIndices, - int k, - cudaStream_t stream) { - FAISS_ASSERT(productDistances.getSize(0) == outDistances.getSize(0)); - FAISS_ASSERT(productDistances.getSize(0) == outIndices.getSize(0)); - FAISS_ASSERT(outDistances.getSize(1) == k); - FAISS_ASSERT(outIndices.getSize(1) == k); - FAISS_ASSERT(k <= 1024); - - if (k == 1) { - constexpr int kThreadsPerBlock = 256; - constexpr int kRowsPerBlock = 8; - - auto block = dim3(kThreadsPerBlock); - auto grid = dim3(faiss::gpu::utils::divUp(outDistances.getSize(0), kRowsPerBlock)); - - topkSelectMin1 - << < grid, block, 0, stream >> > (productDistances, outDistances, outIndices); - } else { - constexpr int kThreadsPerBlock = 128; - - auto block = dim3(kThreadsPerBlock); - auto grid = dim3(outDistances.getSize(0)); - -#define RUN_TOPK_SELECT_MIN(NUM_WARP_Q, NUM_THREAD_Q) \ - do { \ - topkSelectMinK \ - <<>>(productDistances, \ - outDistances, outIndices, \ - k, faiss::gpu::Limits::getMax()); \ - } while (0) - - if (k <= 32) { - RUN_TOPK_SELECT_MIN(32, 2); - } else if (k <= 64) { - RUN_TOPK_SELECT_MIN(64, 3); - } else if (k <= 128) { - RUN_TOPK_SELECT_MIN(128, 3); - } else if (k <= 256) { - RUN_TOPK_SELECT_MIN(256, 4); - } else if (k <= 512) { - RUN_TOPK_SELECT_MIN(512, 8); - } else if (k <= 1024) { - RUN_TOPK_SELECT_MIN(1024, 8); - } else { - FAISS_ASSERT(false); - } - } - - CUDA_TEST_ERROR(); -} - -//////////////////////////////////////////////////////////// -// select kernel for k == 1 -template -__global__ void topkSelectMax1(Tensor productDistances, - Tensor outDistances, - Tensor outIndices) { - // Each block handles kRowsPerBlock rows of the distances (results) - Pair threadMax[kRowsPerBlock]; - __shared__ - Pair blockMax[kRowsPerBlock * (kBlockSize / kWarpSize)]; - - T distance[kRowsPerBlock]; - -#pragma unroll - for (int i = 0; i < kRowsPerBlock; ++i) { - threadMax[i].k = faiss::gpu::Limits::getMin(); - threadMax[i].v = -1; - } - - // blockIdx.x: which chunk of rows we are responsible for updating - int rowStart = blockIdx.x * kRowsPerBlock; - - // FIXME: if we have exact multiples, don't need this - bool endRow = (blockIdx.x == gridDim.x - 1); - - if (endRow) { - if (productDistances.getSize(0) % kRowsPerBlock == 0) { - endRow = false; - } - } - - if (endRow) { - for (int row = rowStart; row < productDistances.getSize(0); ++row) { - for (int col = threadIdx.x; col < productDistances.getSize(1); - col += blockDim.x) { - distance[0] = productDistances[row][col]; - - if (faiss::gpu::Math::gt(distance[0], threadMax[0].k)) { - threadMax[0].k = distance[0]; - threadMax[0].v = col; - } - } - - // Reduce within the block - threadMax[0] = - faiss::gpu::blockReduceAll, faiss::gpu::Max >, false, false>( - threadMax[0], faiss::gpu::Max >(), blockMax); - - if (threadIdx.x == 0) { - outDistances[row][0] = threadMax[0].k; - outIndices[row][0] = threadMax[0].v; - } - - // so we can use the shared memory again - __syncthreads(); - - threadMax[0].k = faiss::gpu::Limits::getMin(); - threadMax[0].v = -1; - } - } else { - for (int col = threadIdx.x; col < productDistances.getSize(1); - col += blockDim.x) { - -#pragma unroll - for (int row = 0; row < kRowsPerBlock; ++row) { - distance[row] = productDistances[rowStart + row][col]; - } - -#pragma unroll - for (int row = 0; row < kRowsPerBlock; ++row) { - if (faiss::gpu::Math::gt(distance[row], threadMax[row].k)) { - threadMax[row].k = distance[row]; - threadMax[row].v = col; - } - } - } - - // Reduce within the block - faiss::gpu::blockReduceAll, faiss::gpu::Max >, false, false>( - threadMax, faiss::gpu::Max >(), blockMax); - - if (threadIdx.x == 0) { -#pragma unroll - for (int row = 0; row < kRowsPerBlock; ++row) { - outDistances[rowStart + row][0] = threadMax[row].k; - outIndices[rowStart + row][0] = threadMax[row].v; - } - } - } -} - -// L2 + select kernel for k > 1, no re-use of ||c||^2 -template -__global__ void topkSelectMaxK(Tensor productDistances, - Tensor outDistances, - Tensor outIndices, - int k, T initK) { - // Each block handles a single row of the distances (results) - constexpr int kNumWarps = ThreadsPerBlock / kWarpSize; - - __shared__ - T smemK[kNumWarps * NumWarpQ]; - __shared__ - int64_t smemV[kNumWarps * NumWarpQ]; - - faiss::gpu::BlockSelect, - NumWarpQ, NumThreadQ, ThreadsPerBlock> - heap(initK, -1, smemK, smemV, k); - - int row = blockIdx.x; - - // Whole warps must participate in the selection - int limit = faiss::gpu::utils::roundDown(productDistances.getSize(1), kWarpSize); - int i = threadIdx.x; - - for (; i < limit; i += blockDim.x) { - T v = productDistances[row][i]; - heap.add(v, i); - } - - if (i < productDistances.getSize(1)) { - T v = productDistances[row][i]; - heap.addThreadQ(v, i); - } - - heap.reduce(); - for (int i = threadIdx.x; i < k; i += blockDim.x) { - outDistances[row][i] = smemK[i]; - outIndices[row][i] = smemV[i]; - } -} - -// FIXME: no TVec specialization -template -void runTopKSelectMax(Tensor &productDistances, - Tensor &outDistances, - Tensor &outIndices, - int k, - cudaStream_t stream) { - FAISS_ASSERT(productDistances.getSize(0) == outDistances.getSize(0)); - FAISS_ASSERT(productDistances.getSize(0) == outIndices.getSize(0)); - FAISS_ASSERT(outDistances.getSize(1) == k); - FAISS_ASSERT(outIndices.getSize(1) == k); - FAISS_ASSERT(k <= 1024); - - if (k == 1) { - constexpr int kThreadsPerBlock = 256; - constexpr int kRowsPerBlock = 8; - - auto block = dim3(kThreadsPerBlock); - auto grid = dim3(faiss::gpu::utils::divUp(outDistances.getSize(0), kRowsPerBlock)); - - topkSelectMax1 - << < grid, block, 0, stream >> > (productDistances, outDistances, outIndices); - } else { - constexpr int kThreadsPerBlock = 128; - - auto block = dim3(kThreadsPerBlock); - auto grid = dim3(outDistances.getSize(0)); - -#define RUN_TOPK_SELECT_MAX(NUM_WARP_Q, NUM_THREAD_Q) \ - do { \ - topkSelectMaxK \ - <<>>(productDistances, \ - outDistances, outIndices, \ - k, faiss::gpu::Limits::getMin()); \ - } while (0) - - if (k <= 32) { - RUN_TOPK_SELECT_MAX(32, 2); - } else if (k <= 64) { - RUN_TOPK_SELECT_MAX(64, 3); - } else if (k <= 128) { - RUN_TOPK_SELECT_MAX(128, 3); - } else if (k <= 256) { - RUN_TOPK_SELECT_MAX(256, 4); - } else if (k <= 512) { - RUN_TOPK_SELECT_MAX(512, 8); - } else if (k <= 1024) { - RUN_TOPK_SELECT_MAX(1024, 8); - } else { - FAISS_ASSERT(false); - } - } - - CUDA_TEST_ERROR(); -} -////////////////////////////////////////////////////////////// - -template -void runTopKSelect(Tensor &productDistances, - Tensor &outDistances, - Tensor &outIndices, - bool dir, - int k, - cudaStream_t stream) { - if (dir) { - runTopKSelectMax(productDistances, - outDistances, - outIndices, - k, - stream); - } else { - runTopKSelectMin(productDistances, - outDistances, - outIndices, - k, - stream); - } -} - -template -void TopK(T *input, - int length, - int k, - T *output, - int64_t *idx, -// Ordering order_flag, - cudaStream_t stream) { - -// bool dir = (order_flag == Ordering::kAscending ? false : true); - bool dir = 0; - - Tensor t_input(input, {1, length}); - Tensor t_output(output, {1, k}); - Tensor t_idx(idx, {1, k}); - - runTopKSelect(t_input, t_output, t_idx, dir, k, stream); -} - -//INSTANTIATION_TOPK_2(bool); -//INSTANTIATION_TOPK_2(int8_t); -//INSTANTIATION_TOPK_2(int16_t); -INSTANTIATION_TOPK_2(int32_t); -//INSTANTIATION_TOPK_2(int64_t); -INSTANTIATION_TOPK_2(float); -//INSTANTIATION_TOPK_2(double); -//INSTANTIATION_TOPK(TimeInterval); -//INSTANTIATION_TOPK(Float128); -//INSTANTIATION_TOPK(char); - -} - -void TopK(float *host_input, - int length, - int k, - float *output, - int64_t *indices) { - float *device_input, *device_output; - int64_t *ids; - - cudaMalloc((void **) &device_input, sizeof(float) * length); - cudaMalloc((void **) &device_output, sizeof(float) * k); - cudaMalloc((void **) &ids, sizeof(int64_t) * k); - - cudaMemcpy(device_input, host_input, sizeof(float) * length, cudaMemcpyHostToDevice); - - gpu::TopK(device_input, length, k, device_output, ids, nullptr); - - cudaMemcpy(output, device_output, sizeof(float) * k, cudaMemcpyDeviceToHost); - cudaMemcpy(indices, ids, sizeof(int64_t) * k, cudaMemcpyDeviceToHost); - - cudaFree(device_input); - cudaFree(device_output); - cudaFree(ids); -} - -} -} -} diff --git a/cpp/src/wrapper/gpu/Topk.h b/cpp/src/wrapper/gpu/Topk.h deleted file mode 100644 index d8dc69fd09..0000000000 --- a/cpp/src/wrapper/gpu/Topk.h +++ /dev/null @@ -1,73 +0,0 @@ -// 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. - - -#pragma once - -#include -#include - - -namespace zilliz { -namespace milvus { -namespace engine { -namespace gpu { - -template -void -TopK(T *input, - int length, - int k, - T *output, - int64_t *indices, -// Ordering order_flag, - cudaStream_t stream = nullptr); - - -#define INSTANTIATION_TOPK_2(T) \ - template void \ - TopK(T *input, \ - int length, \ - int k, \ - T *output, \ - int64_t *indices, \ - cudaStream_t stream) -// Ordering order_flag, \ -// cudaStream_t stream) - -//extern INSTANTIATION_TOPK_2(int8_t); -//extern INSTANTIATION_TOPK_2(int16_t); -extern INSTANTIATION_TOPK_2(int32_t); -//extern INSTANTIATION_TOPK_2(int64_t); -extern INSTANTIATION_TOPK_2(float); -//extern INSTANTIATION_TOPK_2(double); -//extern INSTANTIATION_TOPK(TimeInterval); -//extern INSTANTIATION_TOPK(Float128); - -} - -// User Interface. -void TopK(float *input, - int length, - int k, - float *output, - int64_t *indices); - - -} -} -} diff --git a/cpp/src/wrapper/knowhere/vec_impl.cpp b/cpp/src/wrapper/vec_impl.cpp similarity index 100% rename from cpp/src/wrapper/knowhere/vec_impl.cpp rename to cpp/src/wrapper/vec_impl.cpp diff --git a/cpp/src/wrapper/knowhere/vec_impl.h b/cpp/src/wrapper/vec_impl.h similarity index 100% rename from cpp/src/wrapper/knowhere/vec_impl.h rename to cpp/src/wrapper/vec_impl.h diff --git a/cpp/src/wrapper/knowhere/vec_index.cpp b/cpp/src/wrapper/vec_index.cpp similarity index 100% rename from cpp/src/wrapper/knowhere/vec_index.cpp rename to cpp/src/wrapper/vec_index.cpp diff --git a/cpp/src/wrapper/knowhere/vec_index.h b/cpp/src/wrapper/vec_index.h similarity index 100% rename from cpp/src/wrapper/knowhere/vec_index.h rename to cpp/src/wrapper/vec_index.h diff --git a/cpp/unittest/knowhere/CMakeLists.txt b/cpp/unittest/knowhere/CMakeLists.txt index 27e2612ae7..21faf3568c 100644 --- a/cpp/unittest/knowhere/CMakeLists.txt +++ b/cpp/unittest/knowhere/CMakeLists.txt @@ -21,9 +21,9 @@ include_directories("${CUDA_TOOLKIT_ROOT_DIR}/include") link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib64") set(knowhere_src - ${MILVUS_ENGINE_SRC}/wrapper/knowhere/data_transfer.cpp - ${MILVUS_ENGINE_SRC}/wrapper/knowhere/vec_impl.cpp - ${MILVUS_ENGINE_SRC}/wrapper/knowhere/vec_index.cpp) + ${MILVUS_ENGINE_SRC}/wrapper/data_transfer.cpp + ${MILVUS_ENGINE_SRC}/wrapper/vec_impl.cpp + ${MILVUS_ENGINE_SRC}/wrapper/vec_index.cpp) set(helper utils.cpp diff --git a/cpp/unittest/knowhere/knowhere_test.cpp b/cpp/unittest/knowhere/knowhere_test.cpp index 6d8f57f322..ac185efbb3 100644 --- a/cpp/unittest/knowhere/knowhere_test.cpp +++ b/cpp/unittest/knowhere/knowhere_test.cpp @@ -19,7 +19,7 @@ #include #include "utils/easylogging++.h" -#include +#include "src/wrapper/vec_index.h" #include "knowhere/index/vector_index/gpu_ivf.h" #include "utils.h" diff --git a/cpp/unittest/scheduler/scheduler_test.cpp b/cpp/unittest/scheduler/scheduler_test.cpp index 6f680f4a60..13bdf53fb0 100644 --- a/cpp/unittest/scheduler/scheduler_test.cpp +++ b/cpp/unittest/scheduler/scheduler_test.cpp @@ -25,7 +25,7 @@ #include "scheduler/ResourceFactory.h" #include "scheduler/resource/Resource.h" #include "utils/Error.h" -#include "wrapper/knowhere/vec_index.h" +#include "src/wrapper/vec_index.h" #include "scheduler/tasklabel/SpecResLabel.h" diff --git a/cpp/unittest/server/cache_test.cpp b/cpp/unittest/server/cache_test.cpp index 5bb1fb8612..bf9b6edf7d 100644 --- a/cpp/unittest/server/cache_test.cpp +++ b/cpp/unittest/server/cache_test.cpp @@ -21,7 +21,7 @@ #include "server/ServerConfig.h" #include "utils/Error.h" -#include "wrapper/knowhere/vec_index.h" +#include "src/wrapper/vec_index.h" using namespace zilliz::milvus;