From e3e22cedc5b0665600a399be0a211bc092eaf0c8 Mon Sep 17 00:00:00 2001 From: milvus-ci-robot Date: Thu, 31 Oct 2019 10:34:55 +0800 Subject: [PATCH 1/6] delete GIT_CREDENTIALS_ID parameter Former-commit-id: 8308271362483b047c3b406f6cbe0de32734e73d --- ci/jenkins/Jenkinsfile | 19 +++++++++---------- ci/jenkins/{jenkinsfile => step}/build.groovy | 0 .../cleanupSingleDev.groovy | 0 .../{jenkinsfile => step}/coverage.groovy | 0 .../deploySingle2Dev.groovy | 2 +- .../{jenkinsfile => step}/package.groovy | 0 .../publishImages.groovy | 0 .../singleDevNightlyTest.groovy | 2 +- .../singleDevTest.groovy | 2 +- 9 files changed, 12 insertions(+), 13 deletions(-) rename ci/jenkins/{jenkinsfile => step}/build.groovy (100%) rename ci/jenkins/{jenkinsfile => step}/cleanupSingleDev.groovy (100%) rename ci/jenkins/{jenkinsfile => step}/coverage.groovy (100%) rename ci/jenkins/{jenkinsfile => step}/deploySingle2Dev.groovy (57%) rename ci/jenkins/{jenkinsfile => step}/package.groovy (100%) rename ci/jenkins/{jenkinsfile => step}/publishImages.groovy (100%) rename ci/jenkins/{jenkinsfile => step}/singleDevNightlyTest.groovy (79%) rename ci/jenkins/{jenkinsfile => step}/singleDevTest.groovy (81%) diff --git a/ci/jenkins/Jenkinsfile b/ci/jenkins/Jenkinsfile index 67bff5ac1e..24f972748a 100644 --- a/ci/jenkins/Jenkinsfile +++ b/ci/jenkins/Jenkinsfile @@ -16,7 +16,6 @@ pipeline { parameters{ choice choices: ['Release', 'Debug'], description: '', name: 'BUILD_TYPE' - string defaultValue: 'cf1434e7-5a4b-4d25-82e8-88d667aef9e5', description: 'GIT CREDENTIALS ID', name: 'GIT_CREDENTIALS_ID', trim: true string defaultValue: 'registry.zilliz.com', description: 'DOCKER REGISTRY URL', name: 'DOKCER_REGISTRY_URL', trim: true string defaultValue: 'ba070c98-c8cc-4f7c-b657-897715f359fc', description: 'DOCKER CREDENTIALS ID', name: 'DOCKER_CREDENTIALS_ID', trim: true string defaultValue: 'http://192.168.1.202/artifactory/milvus', description: 'JFROG ARTFACTORY URL', name: 'JFROG_ARTFACTORY_URL', trim: true @@ -56,7 +55,7 @@ pipeline { steps { container('milvus-build-env') { script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/build.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/build.groovy" } } } @@ -65,7 +64,7 @@ pipeline { steps { container('milvus-build-env') { script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/coverage.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/coverage.groovy" } } } @@ -74,7 +73,7 @@ pipeline { steps { container('milvus-build-env') { script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/package.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/package.groovy" } } } @@ -96,7 +95,7 @@ pipeline { steps { container('publish-images'){ script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/publishImages.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/publishImages.groovy" } } } @@ -118,7 +117,7 @@ pipeline { steps { container('milvus-test-env') { script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/deploySingle2Dev.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/deploySingle2Dev.groovy" } } } @@ -130,9 +129,9 @@ pipeline { script { boolean isNightlyTest = isTimeTriggeredBuild() if (isNightlyTest) { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/singleDevNightlyTest.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/singleDevNightlyTest.groovy" } else { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/singleDevTest.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/singleDevTest.groovy" } } } @@ -143,7 +142,7 @@ pipeline { steps { container('milvus-test-env') { script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/cleanupSingleDev.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/cleanupSingleDev.groovy" } } } @@ -153,7 +152,7 @@ pipeline { unsuccessful { container('milvus-test-env') { script { - load "${env.WORKSPACE}/ci/jenkins/jenkinsfile/cleanupSingleDev.groovy" + load "${env.WORKSPACE}/ci/jenkins/step/cleanupSingleDev.groovy" } } } diff --git a/ci/jenkins/jenkinsfile/build.groovy b/ci/jenkins/step/build.groovy similarity index 100% rename from ci/jenkins/jenkinsfile/build.groovy rename to ci/jenkins/step/build.groovy diff --git a/ci/jenkins/jenkinsfile/cleanupSingleDev.groovy b/ci/jenkins/step/cleanupSingleDev.groovy similarity index 100% rename from ci/jenkins/jenkinsfile/cleanupSingleDev.groovy rename to ci/jenkins/step/cleanupSingleDev.groovy diff --git a/ci/jenkins/jenkinsfile/coverage.groovy b/ci/jenkins/step/coverage.groovy similarity index 100% rename from ci/jenkins/jenkinsfile/coverage.groovy rename to ci/jenkins/step/coverage.groovy diff --git a/ci/jenkins/jenkinsfile/deploySingle2Dev.groovy b/ci/jenkins/step/deploySingle2Dev.groovy similarity index 57% rename from ci/jenkins/jenkinsfile/deploySingle2Dev.groovy rename to ci/jenkins/step/deploySingle2Dev.groovy index bc6c6f4438..f4964df5e2 100644 --- a/ci/jenkins/jenkinsfile/deploySingle2Dev.groovy +++ b/ci/jenkins/step/deploySingle2Dev.groovy @@ -1,7 +1,7 @@ sh 'helm init --client-only --skip-refresh --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts' sh 'helm repo update' dir ('milvus-helm') { - checkout([$class: 'GitSCM', branches: [[name: "0.5.0"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_CREDENTIALS_ID}", url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.5.0:refs/remotes/origin/0.5.0"]]]) + checkout([$class: 'GitSCM', branches: [[name: "0.5.0"]], userRemoteConfigs: [[url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.5.0:refs/remotes/origin/0.5.0"]]]) dir ("milvus-gpu") { sh "helm install --wait --timeout 300 --set engine.image.tag=${DOCKER_VERSION} --set expose.type=clusterIP --name ${env.PIPELINE_NAME}-${env.BUILD_NUMBER}-single-gpu -f ci/db_backend/sqlite_values.yaml -f ci/filebeat/values.yaml --namespace milvus ." } diff --git a/ci/jenkins/jenkinsfile/package.groovy b/ci/jenkins/step/package.groovy similarity index 100% rename from ci/jenkins/jenkinsfile/package.groovy rename to ci/jenkins/step/package.groovy diff --git a/ci/jenkins/jenkinsfile/publishImages.groovy b/ci/jenkins/step/publishImages.groovy similarity index 100% rename from ci/jenkins/jenkinsfile/publishImages.groovy rename to ci/jenkins/step/publishImages.groovy diff --git a/ci/jenkins/jenkinsfile/singleDevNightlyTest.groovy b/ci/jenkins/step/singleDevNightlyTest.groovy similarity index 79% rename from ci/jenkins/jenkinsfile/singleDevNightlyTest.groovy rename to ci/jenkins/step/singleDevNightlyTest.groovy index 5140ad858f..9aeab2eb4e 100644 --- a/ci/jenkins/jenkinsfile/singleDevNightlyTest.groovy +++ b/ci/jenkins/step/singleDevNightlyTest.groovy @@ -8,7 +8,7 @@ timeout(time: 90, unit: 'MINUTES') { if (!fileExists('milvus-helm')) { dir ("milvus-helm") { - checkout([$class: 'GitSCM', branches: [[name: "0.5.0"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_CREDENTIALS_ID}", url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.5.0:refs/remotes/origin/0.5.0"]]]) + checkout([$class: 'GitSCM', branches: [[name: "0.5.0"]], userRemoteConfigs: [[url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.5.0:refs/remotes/origin/0.5.0"]]]) } } dir ("milvus-helm") { diff --git a/ci/jenkins/jenkinsfile/singleDevTest.groovy b/ci/jenkins/step/singleDevTest.groovy similarity index 81% rename from ci/jenkins/jenkinsfile/singleDevTest.groovy rename to ci/jenkins/step/singleDevTest.groovy index 16fe65a9b3..86e6f126d9 100644 --- a/ci/jenkins/jenkinsfile/singleDevTest.groovy +++ b/ci/jenkins/step/singleDevTest.groovy @@ -10,7 +10,7 @@ timeout(time: 60, unit: 'MINUTES') { // if (!fileExists('milvus-helm')) { // dir ("milvus-helm") { - // checkout([$class: 'GitSCM', branches: [[name: "0.5.0"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_CREDENTIALS_ID}", url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.5.0:refs/remotes/origin/0.5.0"]]]) + // checkout([$class: 'GitSCM', branches: [[name: "0.5.0"]], userRemoteConfigs: [[url: "https://github.com/milvus-io/milvus-helm.git", name: 'origin', refspec: "+refs/heads/0.5.0:refs/remotes/origin/0.5.0"]]]) // } // } // dir ("milvus-helm") { From 28ac93a22653b44bccfaad9b2ce50ff2d3d6f12c Mon Sep 17 00:00:00 2001 From: milvus-ci-robot Date: Thu, 31 Oct 2019 14:30:55 +0800 Subject: [PATCH 2/6] make sure to put #!/usr/bin/env groovy at the top of the Jenkinsfile Former-commit-id: 5af0774e12ea9d10f3fe10b77336df22d748c7de --- ci/jenkins/Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/jenkins/Jenkinsfile b/ci/jenkins/Jenkinsfile index 24f972748a..40d9686415 100644 --- a/ci/jenkins/Jenkinsfile +++ b/ci/jenkins/Jenkinsfile @@ -1,3 +1,5 @@ +#!/usr/bin/env groovy + String cron_timezone = "TZ=Asia/Shanghai" String cron_string = BRANCH_NAME == "master" ? "H 0 * * * " : "" cron_string = BRANCH_NAME == "0.5.1" ? "H 1 * * * " : cron_string From 49105e44f329242f9bf175ec369c10d8db78cbcd Mon Sep 17 00:00:00 2001 From: fishpenguin Date: Thu, 31 Oct 2019 14:39:02 +0800 Subject: [PATCH 3/6] Add only GPU and only CPU version for IVF_SQ8 and IVF_FLAT Former-commit-id: 14f5b095df2988d5f65ecd1cb2628fd3a3791a14 --- CHANGELOG.md | 1 + core/src/scheduler/SchedInst.h | 4 ++ core/src/scheduler/optimizer/OnlyCPUPass.cpp | 48 ++++++++++++++ core/src/scheduler/optimizer/OnlyCPUPass.h | 47 ++++++++++++++ core/src/scheduler/optimizer/OnlyGPUPass.cpp | 66 ++++++++++++++++++++ core/src/scheduler/optimizer/OnlyGPUPass.h | 50 +++++++++++++++ 6 files changed, 216 insertions(+) create mode 100644 core/src/scheduler/optimizer/OnlyCPUPass.cpp create mode 100644 core/src/scheduler/optimizer/OnlyCPUPass.h create mode 100644 core/src/scheduler/optimizer/OnlyGPUPass.cpp create mode 100644 core/src/scheduler/optimizer/OnlyGPUPass.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 5176ce2b79..f277ec2a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Please mark all change in change log and use the ticket from JIRA. - \#104 - test_scheduler core dump - \#115 - Using new structure for tasktable - \#139 - New config opion use_gpu_threshold +- \#146 - Add only GPU and only CPU version for IVF_SQ8 and IVF_FLAT ## Improvement - \#64 - Improvement dump function in scheduler diff --git a/core/src/scheduler/SchedInst.h b/core/src/scheduler/SchedInst.h index b9153d3bc3..e758f37851 100644 --- a/core/src/scheduler/SchedInst.h +++ b/core/src/scheduler/SchedInst.h @@ -23,6 +23,8 @@ #include "Scheduler.h" #include "optimizer/HybridPass.h" #include "optimizer/LargeSQ8HPass.h" +#include "optimizer/OnlyCPUPass.h" +#include "optimizer/OnlyGPUPass.h" #include "optimizer/Optimizer.h" #include @@ -96,6 +98,8 @@ class OptimizerInst { std::vector pass_list; pass_list.push_back(std::make_shared()); pass_list.push_back(std::make_shared()); + pass_list.push_back(std::make_shared()); + pass_list.push_back(std::make_shared()); instance = std::make_shared(pass_list); } } diff --git a/core/src/scheduler/optimizer/OnlyCPUPass.cpp b/core/src/scheduler/optimizer/OnlyCPUPass.cpp new file mode 100644 index 0000000000..d974887bb7 --- /dev/null +++ b/core/src/scheduler/optimizer/OnlyCPUPass.cpp @@ -0,0 +1,48 @@ +// 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 "scheduler/optimizer/OnlyCPUPass.h" +#include "scheduler/SchedInst.h" +#include "scheduler/task/SearchTask.h" +#include "scheduler/tasklabel/SpecResLabel.h" +#include "scheduler/Utils.h" + +namespace milvus { +namespace scheduler { + +bool +OnlyCPUPass::Run(const TaskPtr& task) { + if (task->Type() != TaskType::SearchTask) + return false; + auto search_task = std::static_pointer_cast(task); + if (search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFSQ8 && + search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFFLAT) { + return false; + } + + auto gpu_id = get_gpu_pool(); + if (gpu_id.empty()) { + ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("cpu"); + auto label = std::make_shared(std::weak_ptr(res_ptr)); + task->label() = label; + return true; + } + return false; +} + +} // namespace scheduler +} // namespace milvus diff --git a/core/src/scheduler/optimizer/OnlyCPUPass.h b/core/src/scheduler/optimizer/OnlyCPUPass.h new file mode 100644 index 0000000000..edc3848ed4 --- /dev/null +++ b/core/src/scheduler/optimizer/OnlyCPUPass.h @@ -0,0 +1,47 @@ +// 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 +#include +#include +#include +#include +#include +#include + +#include "Pass.h" + +namespace milvus { +namespace scheduler { + +class OnlyCPUPass : public Pass { +public: + OnlyCPUPass() = default; + +public: + bool + Run(const TaskPtr &task) override; +}; + +using OnlyCPUPassPtr = std::shared_ptr; + +} // namespace scheduler +} // namespace milvus diff --git a/core/src/scheduler/optimizer/OnlyGPUPass.cpp b/core/src/scheduler/optimizer/OnlyGPUPass.cpp new file mode 100644 index 0000000000..20127aefb8 --- /dev/null +++ b/core/src/scheduler/optimizer/OnlyGPUPass.cpp @@ -0,0 +1,66 @@ +// 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 "scheduler/optimizer/OnlyGPUPass.h" +#include "scheduler/SchedInst.h" +#include "scheduler/task/SearchTask.h" +#include "scheduler/tasklabel/SpecResLabel.h" +#include "scheduler/Utils.h" +#include "server/Config.h" + +namespace milvus { +namespace scheduler { + +bool +OnlyGPUPass::Run(const TaskPtr& task) { + if (task->Type() != TaskType::SearchTask) + return false; + + auto search_task = std::static_pointer_cast(task); + if (search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFSQ8 && + search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFFLAT) { + return false; + } + + server::Config& config = server::Config::GetInstance(); + std::vector search_resources; + config.GetResourceConfigSearchResources(search_resources); + for (auto &resource : search_resources) { + if (resource == "cpu") { + return false; + } + } + + auto gpu_id = get_gpu_pool(); + if (!gpu_id.empty()) { + ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, gpu_id[specified_gpu_id_]); + auto label = std::make_shared(std::weak_ptr(res_ptr)); + task->label() = label; + } else { + return false; + } + + if (specified_gpu_id_ < gpu_id.size() - 1) { + ++specified_gpu_id_; + } else { + specified_gpu_id_ = 0; + } + return true; +} + +} // namespace scheduler +} // namespace milvus diff --git a/core/src/scheduler/optimizer/OnlyGPUPass.h b/core/src/scheduler/optimizer/OnlyGPUPass.h new file mode 100644 index 0000000000..9220bab11d --- /dev/null +++ b/core/src/scheduler/optimizer/OnlyGPUPass.h @@ -0,0 +1,50 @@ +// 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 +#include +#include +#include +#include +#include +#include + +#include "Pass.h" + +namespace milvus { +namespace scheduler { + +class OnlyGPUPass : public Pass { +public: + OnlyGPUPass() = default; + +public: + bool + Run(const TaskPtr &task) override; + +private: + uint64_t specified_gpu_id_ = 0; +}; + +using OnlyGPUPassPtr = std::shared_ptr; + +} // namespace scheduler +} // namespace milvus From a68255f9d005a53bf0769a3bb3610f6c85322173 Mon Sep 17 00:00:00 2001 From: fishpenguin Date: Thu, 31 Oct 2019 14:44:59 +0800 Subject: [PATCH 4/6] clang format Former-commit-id: 3f99d7df6b042683696dd70c9dc0f14fee57b388 --- core/src/scheduler/optimizer/OnlyCPUPass.cpp | 6 +++--- core/src/scheduler/optimizer/OnlyCPUPass.h | 8 ++++---- core/src/scheduler/optimizer/OnlyGPUPass.cpp | 8 ++++---- core/src/scheduler/optimizer/OnlyGPUPass.h | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/scheduler/optimizer/OnlyCPUPass.cpp b/core/src/scheduler/optimizer/OnlyCPUPass.cpp index d974887bb7..2651a6e1a5 100644 --- a/core/src/scheduler/optimizer/OnlyCPUPass.cpp +++ b/core/src/scheduler/optimizer/OnlyCPUPass.cpp @@ -17,9 +17,9 @@ #include "scheduler/optimizer/OnlyCPUPass.h" #include "scheduler/SchedInst.h" +#include "scheduler/Utils.h" #include "scheduler/task/SearchTask.h" #include "scheduler/tasklabel/SpecResLabel.h" -#include "scheduler/Utils.h" namespace milvus { namespace scheduler { @@ -29,8 +29,8 @@ OnlyCPUPass::Run(const TaskPtr& task) { if (task->Type() != TaskType::SearchTask) return false; auto search_task = std::static_pointer_cast(task); - if (search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFSQ8 && - search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFFLAT) { + if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8 && + search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFFLAT) { return false; } diff --git a/core/src/scheduler/optimizer/OnlyCPUPass.h b/core/src/scheduler/optimizer/OnlyCPUPass.h index edc3848ed4..76b42e3766 100644 --- a/core/src/scheduler/optimizer/OnlyCPUPass.h +++ b/core/src/scheduler/optimizer/OnlyCPUPass.h @@ -32,13 +32,13 @@ namespace milvus { namespace scheduler { -class OnlyCPUPass : public Pass { -public: +class OnlyCPUPass : public Pass { + public: OnlyCPUPass() = default; -public: + public: bool - Run(const TaskPtr &task) override; + Run(const TaskPtr& task) override; }; using OnlyCPUPassPtr = std::shared_ptr; diff --git a/core/src/scheduler/optimizer/OnlyGPUPass.cpp b/core/src/scheduler/optimizer/OnlyGPUPass.cpp index 20127aefb8..f39ca1a042 100644 --- a/core/src/scheduler/optimizer/OnlyGPUPass.cpp +++ b/core/src/scheduler/optimizer/OnlyGPUPass.cpp @@ -17,9 +17,9 @@ #include "scheduler/optimizer/OnlyGPUPass.h" #include "scheduler/SchedInst.h" +#include "scheduler/Utils.h" #include "scheduler/task/SearchTask.h" #include "scheduler/tasklabel/SpecResLabel.h" -#include "scheduler/Utils.h" #include "server/Config.h" namespace milvus { @@ -31,15 +31,15 @@ OnlyGPUPass::Run(const TaskPtr& task) { return false; auto search_task = std::static_pointer_cast(task); - if (search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFSQ8 && - search_task->file_->engine_type_ != (int) engine::EngineType::FAISS_IVFFLAT) { + if (search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFSQ8 && + search_task->file_->engine_type_ != (int)engine::EngineType::FAISS_IVFFLAT) { return false; } server::Config& config = server::Config::GetInstance(); std::vector search_resources; config.GetResourceConfigSearchResources(search_resources); - for (auto &resource : search_resources) { + for (auto& resource : search_resources) { if (resource == "cpu") { return false; } diff --git a/core/src/scheduler/optimizer/OnlyGPUPass.h b/core/src/scheduler/optimizer/OnlyGPUPass.h index 9220bab11d..75a5f9e4f1 100644 --- a/core/src/scheduler/optimizer/OnlyGPUPass.h +++ b/core/src/scheduler/optimizer/OnlyGPUPass.h @@ -32,15 +32,15 @@ namespace milvus { namespace scheduler { -class OnlyGPUPass : public Pass { -public: +class OnlyGPUPass : public Pass { + public: OnlyGPUPass() = default; -public: + public: bool - Run(const TaskPtr &task) override; + Run(const TaskPtr& task) override; -private: + private: uint64_t specified_gpu_id_ = 0; }; From 1dc7b321a45a178813350ea7c87d2d0ce57103c8 Mon Sep 17 00:00:00 2001 From: fishpenguin Date: Thu, 31 Oct 2019 16:41:48 +0800 Subject: [PATCH 5/6] Read config once in optimizer Former-commit-id: 8fee2a3cfa20cdc8b51e86867b7b3eb71dd2e759 --- core/src/scheduler/SchedInst.h | 14 ++++++++- core/src/scheduler/optimizer/OnlyCPUPass.cpp | 14 ++++----- core/src/scheduler/optimizer/OnlyGPUPass.cpp | 32 ++++++-------------- core/src/scheduler/optimizer/OnlyGPUPass.h | 3 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/core/src/scheduler/SchedInst.h b/core/src/scheduler/SchedInst.h index e758f37851..a3048069f9 100644 --- a/core/src/scheduler/SchedInst.h +++ b/core/src/scheduler/SchedInst.h @@ -26,9 +26,11 @@ #include "optimizer/OnlyCPUPass.h" #include "optimizer/OnlyGPUPass.h" #include "optimizer/Optimizer.h" +#include "server/Config.h" #include #include +#include #include namespace milvus { @@ -95,11 +97,21 @@ class OptimizerInst { if (instance == nullptr) { std::lock_guard lock(mutex_); if (instance == nullptr) { + server::Config& config = server::Config::GetInstance(); + std::vector search_resources; + bool has_cpu = false; + config.GetResourceConfigSearchResources(search_resources); + for (auto& resource : search_resources) { + if (resource == "cpu") { + has_cpu = true; + } + } + std::vector pass_list; pass_list.push_back(std::make_shared()); pass_list.push_back(std::make_shared()); pass_list.push_back(std::make_shared()); - pass_list.push_back(std::make_shared()); + pass_list.push_back(std::make_shared(has_cpu)); instance = std::make_shared(pass_list); } } diff --git a/core/src/scheduler/optimizer/OnlyCPUPass.cpp b/core/src/scheduler/optimizer/OnlyCPUPass.cpp index 2651a6e1a5..238a91a82c 100644 --- a/core/src/scheduler/optimizer/OnlyCPUPass.cpp +++ b/core/src/scheduler/optimizer/OnlyCPUPass.cpp @@ -35,13 +35,13 @@ OnlyCPUPass::Run(const TaskPtr& task) { } auto gpu_id = get_gpu_pool(); - if (gpu_id.empty()) { - ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("cpu"); - auto label = std::make_shared(std::weak_ptr(res_ptr)); - task->label() = label; - return true; - } - return false; + if (not gpu_id.empty()) + return false; + + ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource("cpu"); + auto label = std::make_shared(std::weak_ptr(res_ptr)); + task->label() = label; + return true; } } // namespace scheduler diff --git a/core/src/scheduler/optimizer/OnlyGPUPass.cpp b/core/src/scheduler/optimizer/OnlyGPUPass.cpp index f39ca1a042..3fcda0e8a3 100644 --- a/core/src/scheduler/optimizer/OnlyGPUPass.cpp +++ b/core/src/scheduler/optimizer/OnlyGPUPass.cpp @@ -20,14 +20,16 @@ #include "scheduler/Utils.h" #include "scheduler/task/SearchTask.h" #include "scheduler/tasklabel/SpecResLabel.h" -#include "server/Config.h" namespace milvus { namespace scheduler { +OnlyGPUPass::OnlyGPUPass(bool has_cpu) : has_cpu_(has_cpu) { +} + bool OnlyGPUPass::Run(const TaskPtr& task) { - if (task->Type() != TaskType::SearchTask) + if (task->Type() != TaskType::SearchTask || has_cpu_) return false; auto search_task = std::static_pointer_cast(task); @@ -36,29 +38,15 @@ OnlyGPUPass::Run(const TaskPtr& task) { return false; } - server::Config& config = server::Config::GetInstance(); - std::vector search_resources; - config.GetResourceConfigSearchResources(search_resources); - for (auto& resource : search_resources) { - if (resource == "cpu") { - return false; - } - } - auto gpu_id = get_gpu_pool(); - if (!gpu_id.empty()) { - ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, gpu_id[specified_gpu_id_]); - auto label = std::make_shared(std::weak_ptr(res_ptr)); - task->label() = label; - } else { + if (gpu_id.empty()) return false; - } - if (specified_gpu_id_ < gpu_id.size() - 1) { - ++specified_gpu_id_; - } else { - specified_gpu_id_ = 0; - } + ResourcePtr res_ptr = ResMgrInst::GetInstance()->GetResource(ResourceType::GPU, gpu_id[specified_gpu_id_]); + auto label = std::make_shared(std::weak_ptr(res_ptr)); + task->label() = label; + + specified_gpu_id_ = specified_gpu_id_++ % gpu_id.size(); return true; } diff --git a/core/src/scheduler/optimizer/OnlyGPUPass.h b/core/src/scheduler/optimizer/OnlyGPUPass.h index 75a5f9e4f1..10d909d30e 100644 --- a/core/src/scheduler/optimizer/OnlyGPUPass.h +++ b/core/src/scheduler/optimizer/OnlyGPUPass.h @@ -34,7 +34,7 @@ namespace scheduler { class OnlyGPUPass : public Pass { public: - OnlyGPUPass() = default; + explicit OnlyGPUPass(bool has_cpu); public: bool @@ -42,6 +42,7 @@ class OnlyGPUPass : public Pass { private: uint64_t specified_gpu_id_ = 0; + bool has_cpu_ = false; }; using OnlyGPUPassPtr = std::shared_ptr; From 4df6f4b5a93fa9c6cfc54479d52edf0371224ddd Mon Sep 17 00:00:00 2001 From: wxyu Date: Thu, 31 Oct 2019 16:58:47 +0800 Subject: [PATCH 6/6] Not return error when search_resources and index_build_device set cpu Former-commit-id: 0e0313e59cfbf8f8b17fc62db02f2e21a25d25a2 --- CHANGELOG.md | 1 + core/src/server/Config.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f399b87f6..e2ed8f4b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Please mark all change in change log and use the ticket from JIRA. - \#122 - Add unique id for Job - \#130 - Set task state MOVED after resource copy it completed - \#149 - Improve large query optimizer pass +- \#156 - Not return error when search_resources and index_build_device set cpu ## Task diff --git a/core/src/server/Config.cpp b/core/src/server/Config.cpp index 86caf6dd37..2a04128411 100644 --- a/core/src/server/Config.cpp +++ b/core/src/server/Config.cpp @@ -714,9 +714,12 @@ Config::CheckResourceConfigSearchResources(const std::vector& value return Status(SERVER_INVALID_ARGUMENT, msg); } - for (auto& gpu_device : value) { - if (!CheckGpuDevice(gpu_device).ok()) { - std::string msg = "Invalid search resource: " + gpu_device + + for (auto& device : value) { + if (device == "cpu") { + continue; + } + if (!CheckGpuDevice(device).ok()) { + std::string msg = "Invalid search resource: " + device + ". Possible reason: resource_config.search_resources does not match your hardware."; return Status(SERVER_INVALID_ARGUMENT, msg); } @@ -726,6 +729,9 @@ Config::CheckResourceConfigSearchResources(const std::vector& value Status Config::CheckResourceConfigIndexBuildDevice(const std::string& value) { + if (value == "cpu") { + return Status::OK(); + } if (!CheckGpuDevice(value).ok()) { std::string msg = "Invalid index build device: " + value + ". Possible reason: resource_config.index_build_device does not match your hardware.";