From 3978c2a71f73397a15ccc465ed1f339c6e3fa08a Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Thu, 19 Sep 2019 11:04:56 +0800 Subject: [PATCH 1/3] add Log.h in knowhere Former-commit-id: e866a09e487f1ef60816bd0ee6c7308e4bf1ff7e --- cpp/src/core/knowhere/knowhere/common/Log.h | 35 +++++++++++++++++++ .../knowhere/knowhere/common/exception.cpp | 1 + .../knowhere/index/vector_index/gpu_ivf.cpp | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 cpp/src/core/knowhere/knowhere/common/Log.h diff --git a/cpp/src/core/knowhere/knowhere/common/Log.h b/cpp/src/core/knowhere/knowhere/common/Log.h new file mode 100644 index 0000000000..0d99c624ab --- /dev/null +++ b/cpp/src/core/knowhere/knowhere/common/Log.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 "utils/easylogging++.h" + +namespace zilliz { +namespace knowhere { +#define KNOWHERE_DOMAIN_NAME "[KNOWHERE] " +#define KNOWHERE_ERROR_TEXT "KNOWHERE Error:" + +#define KNOWHERE_LOG_TRACE LOG(TRACE) << KNOWHERE_DOMAIN_NAME +#define KNOWHERE_LOG_DEBUG LOG(DEBUG) << KNOWHERE_DOMAIN_NAME +#define KNOWHERE_LOG_INFO LOG(INFO) << KNOWHERE_DOMAIN_NAME +#define KNOWHERE_LOG_WARNING LOG(WARNING) << KNOWHERE_DOMAIN_NAME +#define KNOWHERE_LOG_ERROR LOG(ERROR) << KNOWHERE_DOMAIN_NAME +#define KNOWHERE_LOG_FATAL LOG(FATAL) << KNOWHERE_DOMAIN_NAME +} // namespace knowhere +} // namespace zilliz \ No newline at end of file diff --git a/cpp/src/core/knowhere/knowhere/common/exception.cpp b/cpp/src/core/knowhere/knowhere/common/exception.cpp index fcf3886d9b..eb19e21bb0 100644 --- a/cpp/src/core/knowhere/knowhere/common/exception.cpp +++ b/cpp/src/core/knowhere/knowhere/common/exception.cpp @@ -19,6 +19,7 @@ #include #include "exception.h" +#include "Log.h" namespace zilliz { namespace knowhere { diff --git a/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp index fd04501c83..51fe237658 100644 --- a/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp @@ -30,6 +30,7 @@ #include "cloner.h" #include "knowhere/adapter/faiss_adopt.h" #include "gpu_ivf.h" +#include "knowhere/common/Log.h" #include @@ -223,6 +224,7 @@ VectorIndexPtr GPUIVFPQ::CopyGpuToCpu(const Config &config) { } IndexModelPtr GPUIVFSQ::Train(const DatasetPtr &dataset, const Config &config) { + KNOWHERE_LOG_WARNING << "lalalalalalala"; auto nlist = config["nlist"].as(); auto nbits = config["nbits"].as(); // TODO(linxj): gpu only support SQ4 SQ8 SQ16 gpu_id_ = config.get_with_default("gpu_id", gpu_id_); From 029d4a97b3967e2ac6f150562c7f2a15bca7fec6 Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Thu, 19 Sep 2019 15:12:46 +0800 Subject: [PATCH 2/3] MS-573 Enable log in knowhere Former-commit-id: 7b60e5fc6edcaabea9e967ba4f3312a17533c986 --- cpp/src/core/test/CMakeLists.txt | 9 ++++++--- cpp/src/core/test/test_nsg/CMakeLists.txt | 1 + cpp/src/core/test/utils.cpp | 9 +++++++++ cpp/src/core/test/utils.h | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cpp/src/core/test/CMakeLists.txt b/cpp/src/core/test/CMakeLists.txt index 5b8dca2e4b..d70007229b 100644 --- a/cpp/src/core/test/CMakeLists.txt +++ b/cpp/src/core/test/CMakeLists.txt @@ -22,6 +22,9 @@ set(basic_libs gomp gfortran pthread ) +set(util_srcs + ${MILVUS_ENGINE_SRC}/utils/easylogging++.cc + ) # set(ivf_srcs @@ -35,7 +38,7 @@ set(ivf_srcs utils.cpp ) if(NOT TARGET test_ivf) - add_executable(test_ivf test_ivf.cpp ${ivf_srcs}) + add_executable(test_ivf test_ivf.cpp ${ivf_srcs} ${util_srcs}) endif() target_link_libraries(test_ivf ${depend_libs} ${unittest_libs} ${basic_libs}) @@ -51,7 +54,7 @@ set(idmap_srcs utils.cpp ) if(NOT TARGET test_idmap) - add_executable(test_idmap test_idmap.cpp ${idmap_srcs}) + add_executable(test_idmap test_idmap.cpp ${idmap_srcs} ${util_srcs}) endif() target_link_libraries(test_idmap ${depend_libs} ${unittest_libs} ${basic_libs}) @@ -68,7 +71,7 @@ set(kdt_srcs utils.cpp ) if(NOT TARGET test_kdt) - add_executable(test_kdt test_kdt.cpp ${kdt_srcs}) + add_executable(test_kdt test_kdt.cpp ${kdt_srcs} ${util_srcs}) endif() target_link_libraries(test_kdt SPTAGLibStatic diff --git a/cpp/src/core/test/test_nsg/CMakeLists.txt b/cpp/src/core/test/test_nsg/CMakeLists.txt index 9ee8e76525..17b62cd40d 100644 --- a/cpp/src/core/test/test_nsg/CMakeLists.txt +++ b/cpp/src/core/test/test_nsg/CMakeLists.txt @@ -34,6 +34,7 @@ if(NOT TARGET test_nsg) test_nsg.cpp ${interface_src} ${nsg_src} + ${util_srcs} ) endif() diff --git a/cpp/src/core/test/utils.cpp b/cpp/src/core/test/utils.cpp index 97f4600ca7..4e240f5f74 100644 --- a/cpp/src/core/test/utils.cpp +++ b/cpp/src/core/test/utils.cpp @@ -18,6 +18,15 @@ #include "utils.h" +INITIALIZE_EASYLOGGINGPP + +void InitLog() { + el::Configurations defaultConf; + defaultConf.setToDefault(); + defaultConf.set(el::Level::Debug, + el::ConfigurationType::Format, "[%thread-%datetime-%level]: %msg (%fbase:%line)"); + el::Loggers::reconfigureLogger("default", defaultConf); +} void DataGen::Init_with_default() { Generate(dim, nb, nq); diff --git a/cpp/src/core/test/utils.h b/cpp/src/core/test/utils.h index b9db01de51..df7f11d689 100644 --- a/cpp/src/core/test/utils.h +++ b/cpp/src/core/test/utils.h @@ -24,6 +24,7 @@ #include #include "knowhere/adapter/structure.h" +#include "knowhere/common/Log.h" class DataGen { protected: @@ -65,6 +66,8 @@ extern void GenBase(const int64_t &dim, float *xb, int64_t *ids); +extern void InitLog(); + zilliz::knowhere::DatasetPtr generate_dataset(int64_t nb, int64_t dim, float *xb, long *ids); From e26948e85859e7f5b327b7a238c20f92dcc2c421 Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Thu, 19 Sep 2019 15:18:37 +0800 Subject: [PATCH 3/3] MS-573 remove useless code Former-commit-id: 4db9733a33dcbc26b5b11a66f54087d3af51ccc6 --- cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp index 51fe237658..fd04501c83 100644 --- a/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp +++ b/cpp/src/core/knowhere/knowhere/index/vector_index/gpu_ivf.cpp @@ -30,7 +30,6 @@ #include "cloner.h" #include "knowhere/adapter/faiss_adopt.h" #include "gpu_ivf.h" -#include "knowhere/common/Log.h" #include @@ -224,7 +223,6 @@ VectorIndexPtr GPUIVFPQ::CopyGpuToCpu(const Config &config) { } IndexModelPtr GPUIVFSQ::Train(const DatasetPtr &dataset, const Config &config) { - KNOWHERE_LOG_WARNING << "lalalalalalala"; auto nlist = config["nlist"].as(); auto nbits = config["nbits"].as(); // TODO(linxj): gpu only support SQ4 SQ8 SQ16 gpu_id_ = config.get_with_default("gpu_id", gpu_id_);