diff --git a/mindspore/core/mindrt/include/actor/buslog.h b/mindspore/core/mindrt/include/actor/buslog.h index 91b011fb71..b0ce050e77 100644 --- a/mindspore/core/mindrt/include/actor/buslog.h +++ b/mindspore/core/mindrt/include/actor/buslog.h @@ -22,10 +22,13 @@ #include #include -#include #include "actor/buserrcode.h" - +#ifdef USE_GLOG +#include "utils/log_adapter.h" +#else +#include "common/log_adapter.h" +#endif namespace mindspore { #define BUS_LOG(severity) // LOG(severity) @@ -37,7 +40,6 @@ namespace mindspore { #define ICTSBASE_LOG_COMMON_CODE #define HLOG_LEVEL_INFO #define PID_LITEBUS_LOG -//#define BUS_OOM_EXIT #define HLOG_LEVEL_DEBUG 1 #define ICTSBASE_LOG0(logig, level, pid, format) #define ICTSBASE_LOG1(logig, level, pid, format, para) diff --git a/mindspore/core/mindrt/include/actor/op_actor.h b/mindspore/core/mindrt/include/actor/op_actor.h index e8b50bb43d..07f0d081eb 100644 --- a/mindspore/core/mindrt/include/actor/op_actor.h +++ b/mindspore/core/mindrt/include/actor/op_actor.h @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -21,36 +22,45 @@ #include "actor/actor.h" #include "async/uuid_base.h" #include "async/future.h" +#include "async/async.h" +#include "mindrt/include/async/collect.h" namespace mindspore { // OpActor data route. struct OpArrow { - OpArrow(int from_output_index, AID *to_op_id, int to_input_index) + OpArrow(int from_output_index, AID to_op_id, int to_input_index) : from_output_index_(from_output_index), to_op_id_(to_op_id), to_input_index_(to_input_index) {} int from_output_index_; - AID *to_op_id_; + AID to_op_id_; int to_input_index_; }; // OpActor data. template struct OpData { - OpData(T *data, int to_input_index) : data_(data), to_input_index_(to_input_index) {} + OpData(const AID &op_id, T *data, int index) : op_id_(op_id), data_(data), index_(index) {} + AID op_id_; T *data_; - int to_input_index_; + int index_; }; +using OpArrowPtr = std::shared_ptr; +template +using OpDataPtr = std::shared_ptr>; // The context of opActor running. template struct OpContext { uuids::uuid *sequential_num_; - std::vector> *results_; + std::vector> *outputData_; + std::vector> *results_; + void SetFailed(int32_t code) { + for (auto promise : *results_) { + promise.SetFailed(code); + } + } + void SetResult(size_t index, int value) { results_->at(index).SetValue(value); } }; -using OpArrowPtr = std::shared_ptr; -template -using OpDataPtr = std::shared_ptr>; - template class OpActor : public ActorBase { public: @@ -62,4 +72,38 @@ class OpActor : public ActorBase { std::unordered_map>> input_op_datas_; std::vector output_op_arrow_; }; + +template +Future> MindrtAsyncRun(const std::vector> &inputData, OpContext *context) { + std::list> futures; + for (auto promise : *(context->results_)) { + futures.push_back(promise.GetFuture()); + } + Future> collect = mindspore::Collect(futures); + + for (auto data : inputData) { + Async(data->op_id_, &mindspore::OpActor::OpRun, data, context); + } + + return collect; +} + +template +int MindrtRun(const std::vector> &inputData, std::vector> *outputData) { + OpContext context; + std::vector> promises(outputData->size()); + uuids::uuid uid; + context.sequential_num_ = &uid; + context.results_ = &promises; + context.outputData_ = outputData; + + auto collect = MindrtAsyncRun(inputData, &context); + collect.Wait(); + if (!collect.IsOK()) { + return -1; + } + + return 0; +} + } // namespace mindspore diff --git a/mindspore/core/mindrt/include/async/asyncafter.h b/mindspore/core/mindrt/include/async/asyncafter.h deleted file mode 100644 index a038eb2e12..0000000000 --- a/mindspore/core/mindrt/include/async/asyncafter.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef MINDSPORE_CORE_MINDRT_INCLUDE_ASYNC_ASYNCAFTER_H -#define MINDSPORE_CORE_MINDRT_INCLUDE_ASYNC_ASYNCAFTER_H - -#include "async/async.h" - -#include "timer/timertools.h" - -constexpr mindspore::Duration MILLISECONDS = 1; -constexpr mindspore::Duration SECONDS = 1000; - -namespace mindspore { -template -Timer AsyncAfter(const Duration &duration, const AID &aid, void (T::*method)()) { - return TimerTools::AddTimer(duration, aid, [=]() { Async(aid, method); }); -} - -template -Timer AsyncAfter(const Duration &duration, const AID &aid, void (T::*method)(Arg0), Arg1 &&arg) { - return TimerTools::AddTimer(duration, aid, [=]() { Async(aid, method, arg); }); -} - -template -Timer AsyncAfter(const Duration &duration, const AID &aid, void (T::*method)(Args0...), Args1 &&... args) { - std::function f([=](Args0... args0) { Async(aid, method, args0...); }); - - auto handler = std::bind(f, args...); - - return TimerTools::AddTimer(duration, aid, [=]() { Async(aid, std::move(handler)); }); -} - -}; // namespace mindspore - -#endif diff --git a/mindspore/core/mindrt/include/async/collect.h b/mindspore/core/mindrt/include/async/collect.h index 51cb67c8c1..9dac31c577 100644 --- a/mindspore/core/mindrt/include/async/collect.h +++ b/mindspore/core/mindrt/include/async/collect.h @@ -20,9 +20,11 @@ #include #include #include - +#include +#include #include "async/common.h" #include "async/future.h" +#include "async/defer.h" #include "async/spinlock.h" #include "actor/actor.h" diff --git a/mindspore/core/mindrt/include/async/future.h b/mindspore/core/mindrt/include/async/future.h index e786da2024..aeaed23b3e 100644 --- a/mindspore/core/mindrt/include/async/future.h +++ b/mindspore/core/mindrt/include/async/future.h @@ -16,7 +16,8 @@ #ifndef MINDSPORE_CORE_MINDRT_INCLUDE_ASYNC_FUTURE_H #define MINDSPORE_CORE_MINDRT_INCLUDE_ASYNC_FUTURE_H - +#include +#include #include #include #include @@ -30,7 +31,7 @@ #include "litebus.hpp" -#include "future_base.h" +#include "async/future_base.h" namespace mindspore { @@ -114,22 +115,6 @@ class Future : public FutureBase { return data->t; } - Option Get(uint64_t timeMs) const { - if (data->gotten) { - return Option(data->t); - } - - if (WaitFor(timeMs).IsError()) { - return Option(); - } - - if (data->status.IsError()) { - return Option(); - } - - return Option(Get()); - } - bool Valid() const noexcept { return data->future.valid(); } bool IsInit() const { return data->status.IsInit(); } @@ -157,32 +142,6 @@ class Future : public FutureBase { data->future.wait(); } - WaitForStatus WaitFor(uint64_t timeMs) const { - if (!data->status.IsInit()) { - return Status::KOK; - } - - AID aid = mindspore::Spawn(std::make_shared( - internal::WAIT_ACTOR_NAME + std::to_string(mindspore::localid_generator::GenLocalActorId()))); - - mindspore::Timer timer = TimerTools::AddTimer(timeMs, aid, std::bind(&internal::Waitf, aid)); - - OnComplete(std::bind(&internal::Wait, aid, timer)); - - // block - mindspore::Await(aid); - - data->lock.Lock(); - bool ret = data->status.IsInit(); - data->lock.Unlock(); - - if (!ret) { - return Status::KOK; - } - - return Status::KERROR; - } - template const Future &OnComplete(internal::DeferredHelper &&deferred) const { return OnComplete(std::move(deferred).operator std::function &)>()); @@ -341,19 +300,6 @@ class Future : public FutureBase { return OnAbandoned(std::forward(f), FutureBase()); } - Future After(const Duration &timeMs, const std::function(const Future &)> &f) const { - std::shared_ptr> promise(new (std::nothrow) Promise()); - BUS_OOM_EXIT(promise); - Future future = promise->GetFuture(); - - mindspore::Timer timer = - TimerTools::AddTimer(timeMs, "__After__", std::bind(&internal::Afterf, f, promise, *this)); - - OnComplete(std::bind(&internal::After, promise, timer, std::placeholders::_1)); - - return future; - } - private: template ::type>::type> Future Then(internal::DeferredHelper &&f, FutureBase) const { diff --git a/mindspore/core/mindrt/include/async/future_base.h b/mindspore/core/mindrt/include/async/future_base.h index 0960e7ad72..88d86922e6 100644 --- a/mindspore/core/mindrt/include/async/future_base.h +++ b/mindspore/core/mindrt/include/async/future_base.h @@ -19,6 +19,9 @@ #include #include +#include +#include +#include #include #include "actor/actor.h" @@ -26,8 +29,6 @@ #include "async/spinlock.h" #include "async/status.h" -#include "timer/timertools.h" - namespace mindspore { template @@ -104,15 +105,6 @@ struct FutureData { namespace internal { -const std::string WAIT_ACTOR_NAME = "WACTOR_"; - -class WaitActor : public ActorBase { - public: - explicit WaitActor(const std::string &name) : mindspore::ActorBase(name) {} - - ~WaitActor() override {} -}; - template class DeferredHelper; @@ -186,16 +178,8 @@ static void Afterf(const std::function(const Future &)> &f, const s promise->Associate(f(future)); } -template -static void After(const std::shared_ptr> &promise, const mindspore::Timer &timer, const Future &future) { - (void)mindspore::TimerTools::Cancel(timer); - promise->Associate(future); -} - void Waitf(const AID &aid); -void Wait(const AID &aid, const mindspore::Timer &timer); - } // namespace internal } // namespace mindspore diff --git a/mindspore/core/mindrt/include/async/option.h b/mindspore/core/mindrt/include/async/option.h index f34bb60856..93d5d17e8b 100644 --- a/mindspore/core/mindrt/include/async/option.h +++ b/mindspore/core/mindrt/include/async/option.h @@ -26,7 +26,7 @@ namespace mindspore { template struct InnerSome { - InnerSome(const T &t) : _t(std::move(t)) {} + explicit InnerSome(const T &t) : _t(std::move(t)) {} T _t; }; @@ -35,7 +35,7 @@ InnerSome::type> Some(T &&t) { return InnerSome::type>(std::forward(t)); } -struct None {}; +struct MindrtNone {}; template class Option { @@ -48,7 +48,7 @@ class Option { Option(const InnerSome &some) : data(some._t), state(SOME) {} - Option(const None &none) : data(), state(NONE) {} + Option(const MindrtNone &none) : data(), state(NONE) {} Option(const Option &that) : data(), state(that.state) { if (that.IsSome()) { diff --git a/mindspore/core/mindrt/include/timer/duration.h b/mindspore/core/mindrt/include/timer/duration.h deleted file mode 100755 index d99a975a96..0000000000 --- a/mindspore/core/mindrt/include/timer/duration.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef __LITEBUS_DURATION_HPP__ -#define __LITEBUS_DURATION_HPP__ - -#include -#include -#include -#include -#include -#include - -#include "async/spinlock.h" - -namespace mindspore { -using Duration = uint64_t; -} -#endif diff --git a/mindspore/core/mindrt/include/timer/timer.h b/mindspore/core/mindrt/include/timer/timer.h deleted file mode 100644 index ca3285d8b9..0000000000 --- a/mindspore/core/mindrt/include/timer/timer.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef __LITEBUS_TIMER_HPP__ -#define __LITEBUS_TIMER_HPP__ - -#include "actor/aid.h" -#include "timer/timewatch.h" - -namespace mindspore { -class Timer { - public: - Timer(); - ~Timer(); - bool operator==(const Timer &that) const; - // run this timer's thunk. - void operator()() const; - TimeWatch GetTimeWatch() const; - AID GetTimerAID() const; - uint64_t GetTimerID() const; - - private: - friend class TimerTools; - - Timer(uint64_t timerId, const TimeWatch &timeWatch, const AID &timeAid, const std::function &handler); - - uint64_t id; - TimeWatch t; - AID aid; - std::function thunk; -}; - -} // namespace mindspore - -#endif diff --git a/mindspore/core/mindrt/include/timer/timertools.h b/mindspore/core/mindrt/include/timer/timertools.h deleted file mode 100644 index 0b19a51e9a..0000000000 --- a/mindspore/core/mindrt/include/timer/timertools.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef __LITEBUS_TIMETOOLS_HPP__ -#define __LITEBUS_TIMETOOLS_HPP__ - -#include -#include -#include -#include - -#include "timer/duration.h" -#include "timer/timer.h" - -namespace mindspore { -class TimerTools { - public: - static bool Initialize(); - static void Finalize(); - static Timer AddTimer(const Duration &duration, const AID &aid, const std::function &thunk); - static bool Cancel(const Timer &timer); - static std::atomic_bool g_initStatus; -}; -} // namespace mindspore - -#endif diff --git a/mindspore/core/mindrt/include/timer/timewatch.h b/mindspore/core/mindrt/include/timer/timewatch.h deleted file mode 100644 index 87da4d39a4..0000000000 --- a/mindspore/core/mindrt/include/timer/timewatch.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef __LITEBUS_TIMEWATCH_HPP__ -#define __LITEBUS_TIMEWATCH_HPP__ - -#include "timer/duration.h" -namespace mindspore { -constexpr Duration MICRTONANO = 1000; -constexpr Duration MILLITOMICR = 1000; -constexpr Duration SECTOMILLI = 1000; - -class TimeWatch { - public: - TimeWatch(); - - TimeWatch(const Duration &duration); - - TimeWatch(const TimeWatch &that); - ~TimeWatch(); - - // Constructs a Time instance that is the 'duration' from now. - static TimeWatch In(const Duration &duration); - - static Duration Now(); - - TimeWatch &operator=(const TimeWatch &that); - - TimeWatch &operator=(const Duration &duration); - - bool operator==(const TimeWatch &that) const; - - bool operator<(const TimeWatch &that) const; - - bool operator<=(const TimeWatch &that) const; - - // Returns the value of the timewatch as a Duration object. - Duration Time() const; - - // Returns the amount of time remaining. - Duration Remaining() const; - - // return true if the time expired. - bool Expired() const; - - private: - Duration duration; -}; - -} // namespace mindspore - -#endif diff --git a/mindspore/core/mindrt/src/actor/actor.cc b/mindspore/core/mindrt/src/actor/actor.cc index f9d85117c9..bdb331a04d 100644 --- a/mindspore/core/mindrt/src/actor/actor.cc +++ b/mindspore/core/mindrt/src/actor/actor.cc @@ -18,7 +18,6 @@ #include "actor/actormgr.h" #include "actor/actorpolicyinterface.h" #include "actor/iomgr.h" -#include "utils/log_adapter.h" namespace mindspore { diff --git a/mindspore/core/mindrt/src/actor/actormgr.cc b/mindspore/core/mindrt/src/actor/actormgr.cc index 82a29862f5..16f2065e59 100644 --- a/mindspore/core/mindrt/src/actor/actormgr.cc +++ b/mindspore/core/mindrt/src/actor/actormgr.cc @@ -17,7 +17,6 @@ #include "actor/actormgr.h" #include "actor/actorpolicy.h" #include "actor/iomgr.h" -#include "utils/log_adapter.h" namespace mindspore { diff --git a/mindspore/core/mindrt/src/actor/actorpolicy.cc b/mindspore/core/mindrt/src/actor/actorpolicy.cc index 9ebfd5b830..303478872d 100644 --- a/mindspore/core/mindrt/src/actor/actorpolicy.cc +++ b/mindspore/core/mindrt/src/actor/actorpolicy.cc @@ -17,7 +17,6 @@ #include "actor/actor.h" #include "actor/actormgr.h" #include "actor/actorpolicy.h" -#include "utils/log_adapter.h" namespace mindspore { diff --git a/mindspore/core/mindrt/src/actor/actorthread.cc b/mindspore/core/mindrt/src/actor/actorthread.cc index fa40729f13..9a1347d6af 100644 --- a/mindspore/core/mindrt/src/actor/actorthread.cc +++ b/mindspore/core/mindrt/src/actor/actorthread.cc @@ -16,7 +16,6 @@ #include "actor/actorthread.h" #include -#include "utils/log_adapter.h" namespace mindspore { constexpr int MAXTHREADNAMELEN = 12; @@ -97,7 +96,6 @@ void ActorThread::Run() { terminate = true; MS_LOG(DEBUG) << "Actor this Threads have finished exiting."; } - } while (!terminate); } diff --git a/mindspore/core/mindrt/src/actor/aid.cc b/mindspore/core/mindrt/src/actor/aid.cc index a5bab35bbc..f3536beed9 100644 --- a/mindspore/core/mindrt/src/actor/aid.cc +++ b/mindspore/core/mindrt/src/actor/aid.cc @@ -15,7 +15,6 @@ */ #include "actor/aid.h" -#include "utils/log_adapter.h" namespace mindspore { @@ -121,6 +120,9 @@ std::string AID::GetIp() const { uint16_t AID::GetPort() const { size_t index = url.rfind(':'); + if (index == std::string::npos) { + return 0; + } return (uint16_t)std::stoul(url.substr(index + 1)); } diff --git a/mindspore/core/mindrt/src/actor/sysmgr_actor.cc b/mindspore/core/mindrt/src/actor/sysmgr_actor.cc deleted file mode 100644 index 62a6a3c6c4..0000000000 --- a/mindspore/core/mindrt/src/actor/sysmgr_actor.cc +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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 "actor/actormgr.h" -#include "actor/iomgr.h" -#include "utils/log_adapter.h" - -namespace mindspore { - -Duration SysMgrActor::linkRecycleDuration = 10000; - -void MetricsMessage::PrintMetrics() { - // print sendMetrics by default, in the future we can add more metrics format - std::ostringstream out; - - while (!intTypeMetrics.empty()) { - out << intTypeMetrics.front() << "-"; - intTypeMetrics.pop(); - } - - out << "|"; - - while (!stringTypeMetrics.empty()) { - std::string stringMetric = stringTypeMetrics.front(); - if (stringMetric.empty()) { - out << "null" - << "-"; - } else { - out << stringMetric << "-"; - } - - stringTypeMetrics.pop(); - } - - MS_LOG(INFO) << "[format:fd-err-sum-size|to-okmsg-failmsg], value:" << out.str().c_str(); -} - -void SysMgrActor::SendMetricsDurationCallback() { - std::string protocol = "tcp"; - std::shared_ptr ioMgrRef = ActorMgr::GetIOMgrRef(protocol); - if (ioMgrRef == nullptr) { - MS_LOG(INFO) << "tcp protocol is not exist."; - } else { - ioMgrRef->CollectMetrics(); - } - - (void)AsyncAfter(printSendMetricsDuration, GetAID(), &SysMgrActor::SendMetricsDurationCallback); -} - -void SysMgrActor::HandleSendMetricsCallback(const AID &from, std::unique_ptr message) { - if (message == nullptr) { - MS_LOG(WARNING) << "Can't transform to MetricsMessage."; - return; - } - message->PrintMetrics(); - return; -} - -void SysMgrActor::LinkRecycleDurationCallback() { - std::string protocol = "tcp"; - std::shared_ptr ioMgrRef = ActorMgr::GetIOMgrRef(protocol); - if (ioMgrRef == nullptr) { - MS_LOG(INFO) << "tcp protocol is not exist."; - } else { - ioMgrRef->LinkRecycleCheck(linkRecyclePeriod); - } - - (void)AsyncAfter(linkRecycleDuration, GetAID(), &SysMgrActor::LinkRecycleDurationCallback); -} - -} // namespace mindspore diff --git a/mindspore/core/mindrt/src/actor/sysmgr_actor.h b/mindspore/core/mindrt/src/actor/sysmgr_actor.h deleted file mode 100644 index 36191c5e61..0000000000 --- a/mindspore/core/mindrt/src/actor/sysmgr_actor.h +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef MINDSPORE_CORE_MINDRT_SRC_ACTOR_SYSMGR_ACTOR_H -#define MINDSPORE_CORE_MINDRT_SRC_ACTOR_SYSMGR_ACTOR_H - -#include - -#include "async/async.h" -#include "async/asyncafter.h" -#include "actor/actorapp.h" -#include "utils/log_adapter.h" - -namespace mindspore { - -const std::string SYSMGR_ACTOR_NAME = "SysMgrActor"; -const std::string METRICS_SEND_MSGNAME = "SendMetrics"; -const int LINK_RECYCLE_PERIOD_MIN = 20; -const int LINK_RECYCLE_PERIOD_MAX = 360; - -using IntTypeMetrics = std::queue; -using StringTypeMetrics = std::queue; - -class MetricsMessage : public MessageBase { - public: - explicit MetricsMessage(const std::string &tfrom, const std::string &tTo, const std::string &tName, - const IntTypeMetrics &tInts = IntTypeMetrics(), - const StringTypeMetrics &tStrings = StringTypeMetrics()) - : MessageBase(tfrom, tTo, tName), intTypeMetrics(tInts), stringTypeMetrics(tStrings) {} - - ~MetricsMessage() override {} - - void PrintMetrics(); - - private: - IntTypeMetrics intTypeMetrics; - StringTypeMetrics stringTypeMetrics; -}; - -class SysMgrActor : public mindspore::AppActor { - public: - explicit SysMgrActor(const std::string &name, const Duration &duration) - : mindspore::AppActor(name), printSendMetricsDuration(duration) { - linkRecyclePeriod = 0; - } - - ~SysMgrActor() override {} - - protected: - virtual void Init() override { - MS_LOG(INFO) << "Initiaize SysMgrActor"; - // register receive handle - Receive("SendMetrics", &SysMgrActor::HandleSendMetricsCallback); - - // start sys manager timers - (void)AsyncAfter(printSendMetricsDuration, GetAID(), &SysMgrActor::SendMetricsDurationCallback); - - char *linkRecycleEnv = getenv("LITEBUS_LINK_RECYCLE_PERIOD"); - if (linkRecycleEnv != nullptr) { - int period = 0; - period = std::stoi(linkRecycleEnv); - if (period >= LINK_RECYCLE_PERIOD_MIN && period <= LINK_RECYCLE_PERIOD_MAX) { - MS_LOG(INFO) << "link recycle set:" << period; - linkRecyclePeriod = period; - (void)AsyncAfter(linkRecycleDuration, GetAID(), &SysMgrActor::LinkRecycleDurationCallback); - } - } - } - - private: - void SendMetricsDurationCallback(); - void HandleSendMetricsCallback(const AID &from, std::unique_ptr message); - void LinkRecycleDurationCallback(); - Duration printSendMetricsDuration; - static Duration linkRecycleDuration; - int linkRecyclePeriod; -}; - -} // namespace mindspore -#endif diff --git a/mindspore/core/mindrt/src/async/future.cc b/mindspore/core/mindrt/src/async/future.cc index b7ace76722..e859ea75d0 100644 --- a/mindspore/core/mindrt/src/async/future.cc +++ b/mindspore/core/mindrt/src/async/future.cc @@ -15,7 +15,6 @@ */ #include "async/future.h" -#include "utils/log_adapter.h" namespace mindspore { namespace internal { @@ -25,10 +24,5 @@ void Waitf(const AID &aid) { MS_LOG(WARNING) << "WaitFor is timeout."; } -void Wait(const AID &aid, const mindspore::Timer &timer) { - mindspore::TimerTools::Cancel(timer); - mindspore::Terminate(aid); -} - } // namespace internal } // namespace mindspore diff --git a/mindspore/core/mindrt/src/async/uuid_base.cc b/mindspore/core/mindrt/src/async/uuid_base.cc index 1fec8aa19b..b1276deea9 100644 --- a/mindspore/core/mindrt/src/async/uuid_base.cc +++ b/mindspore/core/mindrt/src/async/uuid_base.cc @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include #include "async/uuid_base.h" -#include -#include "utils/log_adapter.h" namespace mindspore { namespace uuids { @@ -41,7 +39,7 @@ std::string uuid::ToBytes(const uuid &u) { Option uuid::FromBytes(const std::string &s) { if (s.size() != UUID_SIZE) { - return None(); + return MindrtNone(); } uuid u; memcpy(&u.uuidData, s.data(), s.size()); @@ -57,7 +55,7 @@ Option uuid::GetValue(char c) { size_t pos = std::find(digitsBegin, digitsEnd, c) - digitsBegin; if (pos >= digitsLen) { MS_LOG(ERROR) << "invalid char"; - return None(); + return MindrtNone(); } return values[pos]; } @@ -65,7 +63,7 @@ Option uuid::GetValue(char c) { Option uuid::FromString(const std::string &s) { auto sBegin = s.begin(); if (sBegin == s.end()) { - return None(); + return MindrtNone(); } auto c = *sBegin; bool hasOpenBrace = (c == '{'); @@ -84,12 +82,12 @@ Option uuid::FromString(const std::string &s) { c = *(sBegin++); } else { MS_LOG(ERROR) << "str invalid"; - return None(); + return MindrtNone(); } } Option oc1 = GetValue(c); if (oc1.IsNone()) { - return None(); + return MindrtNone(); } u.uuidData[i] = oc1.Get(); if (sBegin != s.end()) { @@ -98,13 +96,13 @@ Option uuid::FromString(const std::string &s) { u.uuidData[i] <<= SHIFT_BIT; Option oc2 = GetValue(c); if (oc2.IsNone()) { - return None(); + return MindrtNone(); } u.uuidData[i] |= oc2.Get(); } if ((hasOpenBrace && (c != '}')) || (sBegin != s.end())) { MS_LOG(ERROR) << "No } end or leng invalid"; - return None(); + return MindrtNone(); } return u; } @@ -140,14 +138,14 @@ uuid RandomBasedGenerator::GenerateRandomUuid() { std::mt19937 gen(rd()); // We use uniform distribution - std::uniform_int_distribution distribution((std::numeric_limits::min)(), - (std::numeric_limits::max)()); + std::uniform_int_distribution distribution((std::numeric_limits::min)(), + (std::numeric_limits::max)()); - unsigned long randomValue = distribution(gen); + uint64_t randomValue = distribution(gen); unsigned int i = 0; for (uint8_t *it = tmpUUID.BeginAddress(); it != tmpUUID.EndAddress(); ++it, ++i) { - if (i == sizeof(unsigned long)) { + if (i == sizeof(uint64_t)) { randomValue = distribution(gen); i = 0; } @@ -156,9 +154,9 @@ uuid RandomBasedGenerator::GenerateRandomUuid() { } // use atomic ++ to replace random - static std::atomic ul(1); - unsigned long lCount = ul.fetch_add(1); - unsigned long offSet = distribution(gen) % RIGHT_SHIFT_BITS; + static std::atomic ul(1); + uint64_t lCount = ul.fetch_add(1); + uint64_t offSet = distribution(gen) % RIGHT_SHIFT_BITS; auto ret = memcpy(tmpUUID.BeginAddress() + offSet, &lCount, sizeof(lCount)); if (ret != 0) { MS_LOG(ERROR) << "memcpy_s error."; diff --git a/mindspore/core/mindrt/src/evloop/CMakeLists.txt b/mindspore/core/mindrt/src/evloop/CMakeLists.txt deleted file mode 100644 index 67a456f7c4..0000000000 --- a/mindspore/core/mindrt/src/evloop/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -target_sources(litebus_obj PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/evloop.cc -) \ No newline at end of file diff --git a/mindspore/core/mindrt/src/evloop/evloop.cc b/mindspore/core/mindrt/src/evloop/evloop.cc deleted file mode 100644 index d98ec17e6d..0000000000 --- a/mindspore/core/mindrt/src/evloop/evloop.cc +++ /dev/null @@ -1,387 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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 -#include - -#include -#include -#include -#include - -#include -#include - -#include "actor/buslog.h" -#include "evloop/evloop.h" -#include "utils/log_adapter.h" - -namespace mindspore { - -int EventLoopRun(EvLoop *evloop, int timeout) { - int nevent = 0; - struct epoll_event *events = nullptr; - - (void)sem_post(&evloop->semId); - - size_t size = 1; - events = (struct epoll_event *)malloc(size); - if (events == nullptr) { - MS_LOG(ERROR) << "malloc events fail"; - return BUS_ERROR; - } - // 1. dest is valid 2. destsz equals to count and both are valid. - // memset_s will always executes successfully. - (void)memset(events, 0, size); - - while (!evloop->stopLoop) { - /* free deleted event handlers */ - evloop->EventFreeDelEvents(); - - MS_LOG(DEBUG) << "timeout:" << timeout << ",epoll_fd:" << evloop->efd; - MS_LOG(DEBUG) << "nevent:" << nevent << ",epoll_fd:" << evloop->efd; - if (nevent < 0) { - if (errno != EINTR) { - MS_LOG(ERROR) << "epoll_wait failed]epoll_fd:" << evloop->efd << ",errno:" << errno; - free(events); - return BUS_ERROR; - } else { - continue; - } - } else if (nevent > 0) { - /* save the epoll modify in "stop" while dispatching handlers */ - evloop->HandleEvent(events, nevent); - } else { - MS_LOG(ERROR) << "epoll_wait failed]epoll_fd:" << evloop->efd << ",ret:0,errno:" << errno; - evloop->stopLoop = 1; - } - - if (evloop->stopLoop) { - /* free deleted event handlers */ - evloop->EventFreeDelEvents(); - } - } - evloop->stopLoop = 0; - MS_LOG(INFO) << "event epoll loop run end"; - free(events); - return BUS_OK; -} - -void *EvloopRun(void *arg) { - if (arg == nullptr) { - MS_LOG(ERROR) << "arg is null"; - } else { - (void)EventLoopRun((EvLoop *)arg, -1); - } - return nullptr; -} - -void QueueReadyCallback(int fd, uint32_t events, void *arg) { - EvLoop *evloop = (EvLoop *)arg; - if (evloop == nullptr) { - MS_LOG(ERROR) << "evloop is null]fd:" << fd << ",events:" << events; - return; - } - - uint64_t count; - if (read(evloop->queueEventfd, &count, sizeof(count)) == sizeof(count)) { - // take out functions from the queue - std::queue> q; - - evloop->queueMutex.lock(); - evloop->queue.swap(q); - evloop->queueMutex.unlock(); - - // invoke functions in the queue - while (!q.empty()) { - q.front()(); - q.pop(); - } - } -} - -void EvLoop::CleanUp() { - if (queueEventfd != -1) { - close(queueEventfd); - queueEventfd = -1; - } - - if (efd != -1) { - close(efd); - efd = -1; - } -} - -int EvLoop::AddFuncToEvLoop(std::function &&func) { - // put func to the queue - queueMutex.lock(); - queue.emplace(std::move(func)); - // return the queque size to send's caller. - int result = queue.size(); - queueMutex.unlock(); - - if (result == 1) { - // wakeup event loop - uint64_t one = 1; - if (write(queueEventfd, &one, sizeof(one)) != sizeof(one)) { - MS_LOG(WARNING) << "fail to write queueEventfd]fd:" << queueEventfd << ",errno:" << errno; - } - } - - return result; -} - -bool EvLoop::Init(const std::string &threadName) { - int retval = EventLoopCreate(); - if (retval != BUS_OK) { - return false; - } - (void)sem_init(&semId, 0, 0); - - if (pthread_create(&loopThread, nullptr, EvloopRun, (void *)this) != 0) { - MS_LOG(ERROR) << "pthread_create fail"; - Finish(); - return false; - } - // wait EvloopRun - (void)sem_wait(&semId); -#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12 - std::string name = threadName; - if (name.empty()) { - name = "EventLoopThread"; - } - retval = pthread_setname_np(loopThread, name.c_str()); - if (retval != 0) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "set pthread name fail]%s", - "name:%s,retval:%d", name.c_str(), retval); - } else { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "set pthread name success]%s", - "name:%s,loopThread:%lu", name.c_str(), loopThread); - } -#endif - - return true; -} - -void EvLoop::Finish() { - if (loopThread) { - void *threadResult = nullptr; - StopEventLoop(); - int ret = pthread_join(loopThread, &threadResult); - if (ret != 0) { - MS_LOG(INFO) << "pthread_join loopThread fail"; - } - loopThread = 0; - } - EventLoopDestroy(); - - MS_LOG(INFO) << "stop loop succ"; -} - -EvLoop::~EvLoop() { Finish(); } - -void EvLoop::DeleteEvent(int fd) { - auto iter = events.find(fd); - if (iter == events.end()) { - MS_LOG(DEBUG) << "not found event]fd:" << fd; - return; - } - MS_LOG(DEBUG) << "erase event]fd:%d" << fd; - EventData *eventData = iter->second; - if (eventData != nullptr) { - delete eventData; - } - events.erase(fd); -} - -EventData *EvLoop::FindEvent(int fd) { - auto iter = events.find(fd); - if (iter == events.end()) { - return nullptr; - } - - return iter->second; -} -void EvLoop::AddEvent(EventData *eventData) { - if (!eventData) { - return; - } - DeleteEvent(eventData->fd); - events.emplace(eventData->fd, eventData); -} - -int EvLoop::EventLoopCreate(void) { return BUS_OK; } - -int EvLoop::AddFdEvent(int fd, uint32_t tEvents, EventHandler handler, void *data) { return BUS_OK; } - -int EvLoop::DelFdEvent(int fd) { - EventData *tev = nullptr; - - eventsLock.lock(); - tev = FindEvent(fd); - if (tev == nullptr) { - eventsLock.unlock(); - MS_LOG(DEBUG) << "event search fail]fd:" << fd << ",epollfd:" << efd; - return BUS_ERROR; - } - events.erase(tev->fd); - - // Don't delete tev immediately, let's push it into deletedEvents, before next epoll_wait,we will free - // all events in deletedEvents. - AddDeletedEvents(tev); - - eventsLock.unlock(); - - return BUS_OK; -} - -int EvLoop::ModifyFdEvent(int fd, uint32_t tEvents) { - struct epoll_event ev; - EventData *tev = nullptr; - - tev = FindEvent(fd); - if (tev == nullptr) { - MS_LOG(ERROR) << "event lookup fail]fd:" << fd << ",events:" << tEvents; - return BUS_ERROR; - } - - // 1. dest is valid 2. destsz equals to count and both are valid. - // memset_s will always executes successfully. - (void)memset(&ev, 0, sizeof(ev)); - - ev.events = tEvents; - ev.data.ptr = tev; - - return BUS_OK; -} - -void EvLoop::AddDeletedEvents(EventData *eventData) { - // caller need check eventData is not nullptr - std::list deleteEventList; - - // if fd not found, push eventData into deletedEvents[fd] - std::map>::iterator fdIter = deletedEvents.find(eventData->fd); - if (fdIter == deletedEvents.end()) { - deletedEvents[eventData->fd].push_back(eventData); - return; - } - - // if fd found, check if same eventData ptr exists - deleteEventList = fdIter->second; - std::list::iterator eventIter = deleteEventList.begin(); - bool found = false; - while (eventIter != deleteEventList.end()) { - if (*eventIter == eventData) { - MS_LOG(WARNING) << "fd has been deleted before]fd:" << eventData->fd << ",efd:" << efd; - found = true; - break; - } - ++eventIter; - } - - // if found same eventData ptr, do nothing - if (found) { - return; - } - - deletedEvents[eventData->fd].push_back(eventData); - - return; -} - -void EvLoop::EventFreeDelEvents() { - std::map>::iterator fdIter = deletedEvents.begin(); - while (fdIter != deletedEvents.end()) { - std::list deleteEventList = fdIter->second; - std::list::iterator eventIter = deleteEventList.begin(); - while (eventIter != deleteEventList.end()) { - EventData *deleteEv = *eventIter; - delete deleteEv; - deleteEv = nullptr; - ++eventIter; - } - deletedEvents.erase(fdIter++); - } - deletedEvents.clear(); -} - -int EvLoop::FindDeletedEvent(const EventData *tev) { - std::map>::iterator fdIter = deletedEvents.find(tev->fd); - if (fdIter == deletedEvents.end()) { - return 0; - } - - std::list deleteEventList = fdIter->second; - std::list::iterator eventIter = deleteEventList.begin(); - while (eventIter != deleteEventList.end()) { - if (*eventIter == tev) { - return 1; - } - ++eventIter; - } - return 0; -} - -void EvLoop::HandleEvent(const struct epoll_event *tEvents, int nevent) { - int i; - int found; - EventData *tev = nullptr; - - for (i = 0; i < nevent; i++) { - tev = reinterpret_cast(tEvents[i].data.ptr); - if (tev != nullptr) { - found = FindDeletedEvent(tev); - if (found) { - MS_LOG(WARNING) << "fd has been deleted from epoll]fd:" << tev->fd << ",efd:" << efd; - continue; - } - - tev->handler(tev->fd, tEvents[i].events, tev->data); - } - } -} - -void EvLoop::StopEventLoop() { - if (stopLoop == 1) { - return; - } - - stopLoop = 1; - - uint64_t one = 1; - if (write(queueEventfd, &one, sizeof(one)) != sizeof(one)) { - MS_LOG(WARNING) << "fail to write queueEventfd]fd:" << queueEventfd << ",errno:" << errno; - } - return; -} - -void EvLoop::EventLoopDestroy() { - /* free deleted event handlers */ - EventFreeDelEvents(); - if (efd > 0) { - if (queueEventfd > 0) { - (void)DelFdEvent(queueEventfd); - close(queueEventfd); - queueEventfd = -1; - } - - close(efd); - efd = -1; - } -} - -} // namespace mindspore diff --git a/mindspore/core/mindrt/src/evloop/evloop.h b/mindspore/core/mindrt/src/evloop/evloop.h deleted file mode 100644 index 2b8b06465a..0000000000 --- a/mindspore/core/mindrt/src/evloop/evloop.h +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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. - */ - -#ifndef __LITEBUS_EVLOOP_H__ -#define __LITEBUS_EVLOOP_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "timer/duration.h" - -namespace mindspore { - -/* - * max epoll set size - */ -constexpr auto EPOLL_SIZE = 4096; - -/* - * epoll event max size - */ -constexpr auto EPOLL_EVENTS_SIZE = 64; - -typedef void (*EventHandler)(int fd, uint32_t events, void *data); - -typedef struct EventData { - EventHandler handler; - void *data; - int fd; - -} EventData; - -class EvLoop { - public: - EvLoop() { - efd = -1; - stopLoop = 0; - queueEventfd = -1; - loopThread = 0; - }; - EvLoop(const EvLoop &) = delete; - EvLoop &operator=(const EvLoop &) = delete; - - bool Init(const std::string &threadName); - - int AddFuncToEvLoop(std::function &&func); - - int AddFdEvent(int fd, uint32_t events, EventHandler handler, void *data); - int ModifyFdEvent(int fd, uint32_t events); - int DelFdEvent(int fd); - void Finish(); - - ~EvLoop(); - - int EventLoopCreate(void); - void StopEventLoop(); - - void EventLoopDestroy(); - - void EventFreeDelEvents(); - void AddDeletedEvents(EventData *eventData); - int FindDeletedEvent(const EventData *tev); - - void HandleEvent(const struct epoll_event *events, int nevent); - - void DeleteEvent(int fd); - EventData *FindEvent(int fd); - void AddEvent(EventData *eventData); - void CleanUp(); - - int efd; - int stopLoop; - std::mutex loopMutex; - sem_t semId; - pthread_t loopThread; - int queueEventfd; - std::mutex queueMutex; - std::queue> queue; - - std::mutex eventsLock; - // fd,EventData - std::map events; - - // Just to be safe, let's use a list to preserve deleted events rather than a map. Because the caller may - // delete events on the same fd twice in once epoll_wait - std::map> deletedEvents; -}; - -} // namespace mindspore - -#endif diff --git a/mindspore/core/mindrt/src/litebus.cc b/mindspore/core/mindrt/src/litebus.cc index 280489e8ee..87fc4faa83 100644 --- a/mindspore/core/mindrt/src/litebus.cc +++ b/mindspore/core/mindrt/src/litebus.cc @@ -15,16 +15,11 @@ */ #include - -#include "mindrt/src/actor/sysmgr_actor.h" +#include #include "mindrt/src/actor/actormgr.h" #include "mindrt/src/actor/iomgr.h" - -//#include "utils/os_utils.hpp" - #include "litebus.hpp" -#include "timer/timertools.h" -#include "litebus.h" +#include "include/litebus.h" extern "C" { int LitebusInitializeC(const struct LitebusConfig *config) { @@ -48,12 +43,6 @@ int LitebusInitializeC(const struct LitebusConfig *config) { void LitebusFinalizeC() { mindspore::Finalize(); } } -constexpr auto LITEBUSTHREADMIN = 3; -constexpr auto LITEBUSTHREADMAX = 100; -constexpr auto LITEBUSTHREADS = 10; - -constexpr auto SYSMGR_TIMER_DURATION = 600000; - namespace mindspore { namespace local { @@ -68,62 +57,7 @@ const LitebusAddress &GetLitebusAddress() { return *local::g_litebusAddress; } -bool SetServerIo(std::shared_ptr &io, std::string &advertiseUrl, const std::string &protocol, - const std::string &url) { -#if 0 - if (protocol == "tcp") { - size_t index = advertiseUrl.find("://"); - if (index != std::string::npos) { - advertiseUrl = advertiseUrl.substr(index + URL_PROTOCOL_IP_SEPARATOR.size()); - } - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "create tcp iomgr. (%s)", - "Url=%s,advertiseUrl=%s", url.c_str(), advertiseUrl.c_str()); - if (local::g_litebusAddress == nullptr) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, - "Couldn't allocate memory for LitebusAddress"); - return false; - } - local::g_litebusAddress->scheme = protocol; - local::g_litebusAddress->ip = AID("test@" + advertiseUrl).GetIp(); - local::g_litebusAddress->port = AID("test@" + advertiseUrl).GetPort(); - -#ifdef HTTP_ENABLED - mindspore::HttpIOMgr::EnableHttp(); -#endif - io.reset(new (std::nothrow) mindspore::TCPMgr()); - if (io == nullptr) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, - "Couldn't allocate memory for TCPMgr"); - return false; - } - } -#ifdef UDP_ENABLED - else if (protocol == "udp") { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "create udp iomgr. (%s)", - "Url=%s,advertiseUrl=%s", url.c_str(), advertiseUrl.c_str()); - - io.reset(new (std::nothrow) mindspore::UDPMgr()); - if (io == nullptr) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, - "Couldn't allocate memory for UDPMgr"); - return false; - } - } -#endif - else { - - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "unsupported protocol. (%s)", - "%s", protocol.c_str()); - return false; - } -#endif - return true; -} - -void SetThreadCount(int threadCount) { - int tmpThreadCount = LITEBUSTHREADS; - ActorMgr::GetActorMgrRef()->Initialize(tmpThreadCount); -} +void SetThreadCount(int threadCount) { ActorMgr::GetActorMgrRef()->Initialize(threadCount); } class LiteBusExit { public: @@ -141,16 +75,9 @@ int InitializeImp(const std::string &tcpUrl, const std::string &tcpUrlAdv, const ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "litebus starts ......"); signal(SIGPIPE, SIG_IGN); - if (!TimerTools::Initialize()) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "Failed to initialize timer tools"); - return BUS_ERROR; - } - // start actor's thread SetThreadCount(threadCount); - mindspore::Spawn(std::make_shared(SYSMGR_ACTOR_NAME, SYSMGR_TIMER_DURATION)); - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "litebus has started."); return BUS_OK; } @@ -205,7 +132,6 @@ void Finalize() { ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "litebus starts to finalize."); mindspore::ActorMgr::GetActorMgrRef()->Finalize(); - TimerTools::Finalize(); ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "litebus has been finalized."); // flush the log in cache to disk before exiting. diff --git a/mindspore/core/mindrt/src/timer/CMakeLists.txt b/mindspore/core/mindrt/src/timer/CMakeLists.txt deleted file mode 100644 index 1489d44e0f..0000000000 --- a/mindspore/core/mindrt/src/timer/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -target_sources(litebus_obj PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/timer.cc - ${CMAKE_CURRENT_SOURCE_DIR}/timertools.cc - ${CMAKE_CURRENT_SOURCE_DIR}/timewatch.cc -) \ No newline at end of file diff --git a/mindspore/core/mindrt/src/timer/timer.cc b/mindspore/core/mindrt/src/timer/timer.cc deleted file mode 100644 index c61d482f49..0000000000 --- a/mindspore/core/mindrt/src/timer/timer.cc +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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 "timer/timer.h" - -namespace mindspore { - -Timer::Timer() : id(0), t(TimeWatch()), aid(AID()), thunk(&abort) {} - -Timer::~Timer() {} - -bool Timer::operator==(const Timer &that) const { return id == that.id; } - -void Timer::operator()() const { thunk(); } - -TimeWatch Timer::GetTimeWatch() const { return t; } - -AID Timer::GetTimerAID() const { return aid; } - -uint64_t Timer::GetTimerID() const { return id; } - -Timer::Timer(uint64_t timerId, const TimeWatch &timeWatch, const AID &timeAid, const std::function &handler) - : id(timerId), t(timeWatch), aid(timeAid), thunk(handler) {} - -} // namespace mindspore diff --git a/mindspore/core/mindrt/src/timer/timertools.cc b/mindspore/core/mindrt/src/timer/timertools.cc deleted file mode 100644 index 8bdacbc9ea..0000000000 --- a/mindspore/core/mindrt/src/timer/timertools.cc +++ /dev/null @@ -1,347 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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 "timer/timertools.h" -#include -#include -#include -#include -#include "evloop/evloop.h" - -namespace mindspore { -using TimerPoolType = std::map>; -static std::unique_ptr g_timerPool; -static std::unique_ptr g_timerEvLoop; -static Duration g_ticks(0); -static int g_runTimerFD(-1); -static int g_watchTimerFD(-1); -static SpinLock g_timersLock; -std::atomic_bool TimerTools::g_initStatus(false); -constexpr Duration SCAN_TIMERPOOL_DELAY = 30; -constexpr Duration WATCH_INTERVAL = 20; -constexpr unsigned int TIMER_LOG_INTERVAL = 6; -const static std::string TIMER_EVLOOP_THREADNAME = "HARES_LB_TMer"; - -namespace timer { -void ScanTimerPool(int fd, uint32_t events, void *data); -Duration NextTick(const std::map> &timerPool) { - if (!timerPool.empty()) { - Duration first = timerPool.begin()->first; - return first; - } - return 0; -} - -void ExecTimers(const std::list &timers) { - for (const auto &timer : timers) { - timer(); - } -} - -void CreateTimerToLoop(const Duration &delay, const Duration &nextTick) { - if (g_runTimerFD == -1) { - g_runTimerFD = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); - if (g_runTimerFD >= 0) { - int retval = g_timerEvLoop->AddFdEvent(g_runTimerFD, EPOLLIN, ScanTimerPool, nullptr); - if (retval != BUS_OK) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "add run timer event fail]%s", - "ID:%d", g_runTimerFD); - close(g_runTimerFD); - g_runTimerFD = -1; - return; - } - } else { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "create run timer fd fail]%s", - "ID:%d", g_runTimerFD); - g_runTimerFD = -1; - return; - } - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "create run timer fd success]%s", - "ID:%d", g_runTimerFD); - } - - struct itimerspec it; - it.it_interval.tv_sec = 0; - it.it_interval.tv_nsec = 0; - it.it_value.tv_sec = delay / SECTOMILLI; - it.it_value.tv_nsec = (delay % SECTOMILLI) * MILLITOMICR * MICRTONANO; - if (timerfd_settime(g_runTimerFD, 0, &it, nullptr) == -1) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "start run timer fail]%s", "ID:%d", - g_runTimerFD); - close(g_runTimerFD); - g_runTimerFD = -1; - return; - } -} - -void ScheduleTick(const std::map> &timerPool) { - Duration nextTick = NextTick(timerPool); - - if (nextTick != 0) { - // 'tick' scheduled for an earlier time, not schedule current 'tick' - if ((g_ticks == 0) || (nextTick < g_ticks)) { - Duration nowTime = TimeWatch::Now(); - Duration delay = 0; - - if (nextTick > nowTime) { - delay = nextTick - nowTime; - g_ticks = nextTick; - CreateTimerToLoop(delay, nextTick); - } else { - delay = SCAN_TIMERPOOL_DELAY; - g_ticks = delay + nowTime; - CreateTimerToLoop(delay, nextTick); - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_DEBUG, PID_LITEBUS_LOG, - "run timer immediately {nextTick, now time}= %s ", "{%" PRIu64 ", %" PRIu64 "}", nextTick, - nowTime); - } - } - } -} - -// select timeout timers -void ScanTimerPool(int fd, uint32_t events, void *data) { - std::list outTimer; - uint64_t count; - - if ((g_runTimerFD != fd) || !(events & EPOLLIN)) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, - "run timer fd or events err {g_runTimerFD, fd, events}= %s ", "{%d, %d, %u}", g_runTimerFD, fd, - events); - return; - } - - if (read(fd, &count, sizeof(uint64_t)) < 0) { - return; - } - g_timersLock.Lock(); - Duration now = TimeWatch::Now(); - auto it = g_timerPool->begin(); - while (it != g_timerPool->end()) { - if (it->first > now) { - break; - } - outTimer.splice(outTimer.end(), (*g_timerPool)[it->first]); - ++it; - } - // delete timed out timer - (void)g_timerPool->erase(g_timerPool->begin(), g_timerPool->upper_bound(now)); - g_ticks = 0; - ScheduleTick(*g_timerPool); - g_timersLock.Unlock(); - - ExecTimers(outTimer); - outTimer.clear(); -} - -void CheckPassedTimer(int fd, uint32_t events, void *data) { - std::list passTimer; - static unsigned long watchTimes = 0; - uint64_t count; - - if ((g_watchTimerFD != fd) || !(events & EPOLLIN)) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, - "check timer fd or events err {g_watchTimerFD, fd, events}= %s ", "{%d, %d, %u}", - g_watchTimerFD, fd, events); - return; - } - if (read(fd, &count, sizeof(uint64_t)) < 0) { - return; - } - g_timersLock.Lock(); - Duration now = TimeWatch::Now(); - ++watchTimes; - - for (auto it = g_timerPool->begin(); it != g_timerPool->end(); ++it) { - if (it->first > now) { - break; - } - passTimer.splice(passTimer.end(), (*g_timerPool)[it->first]); - } - // delete passed timer - if (passTimer.size() > 0) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_DEBUG, PID_LITEBUS_LOG, - "fire pass timer {pass size, now, g_ticks}= %s ", "{%zd, %" PRIu64 ", %" PRIu64 "}", - passTimer.size(), now, g_ticks); - } - (void)g_timerPool->erase(g_timerPool->begin(), g_timerPool->upper_bound(now)); - if (g_ticks <= now) { - g_ticks = 0; - } - - if (g_timerPool->size() > 0) { - if ((watchTimes % TIMER_LOG_INTERVAL == 0) && (passTimer.size() > 0) && - (now - g_timerPool->begin()->first > SECTOMILLI)) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, - "timer info {pool size, pass size, now, g_ticks, poolTick, watchTimes}= %s ", - "{%zd, %zd, %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %lu}", g_timerPool->size(), - passTimer.size(), now, g_ticks, g_timerPool->begin()->first, watchTimes); - } - } - - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_DEBUG, PID_LITEBUS_LOG, - "timer info {pool size, pass size, now, g_ticks, poolTick, watchTimes}= %s ", - "{%zd, %zd, %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %lu}", g_timerPool->size(), passTimer.size(), - now, g_ticks, g_timerPool->begin()->first, watchTimes); - - ScheduleTick(*g_timerPool); - g_timersLock.Unlock(); - - ExecTimers(passTimer); - passTimer.clear(); -} - -bool StartWatchTimer() { - // create watch timer - g_watchTimerFD = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); - if (g_watchTimerFD >= 0) { - int retval = g_timerEvLoop->AddFdEvent(g_watchTimerFD, EPOLLIN, CheckPassedTimer, nullptr); - if (retval != BUS_OK) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "add watch timer event fail]%s", - "ID:%d", g_watchTimerFD); - close(g_watchTimerFD); - g_watchTimerFD = -1; - return false; - } - } else { - g_watchTimerFD = -1; - return false; - } - - // start watch timer - struct itimerspec it; - it.it_interval.tv_sec = WATCH_INTERVAL; - it.it_interval.tv_nsec = 0; - it.it_value.tv_sec = WATCH_INTERVAL; - it.it_value.tv_nsec = 0; - if (timerfd_settime(g_watchTimerFD, 0, &it, nullptr) == -1) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "start watch timer fail]%s", - "ID:%d", g_watchTimerFD); - close(g_watchTimerFD); - g_watchTimerFD = -1; - return false; - } - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, - "start watch timer success, {id}= %s ", "{%d}", g_watchTimerFD); - return true; -} -} // namespace timer - -bool TimerTools::Initialize() { - bool ret = true; - g_timersLock.Lock(); - - g_timerPool.reset(new (std::nothrow) TimerPoolType()); - if (g_timerPool == nullptr) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "timer pool new failed."); - g_timersLock.Unlock(); - return false; - } - - g_timerEvLoop.reset(new (std::nothrow) EvLoop()); - if (g_timerEvLoop == nullptr) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "ev new failed."); - g_timersLock.Unlock(); - return false; - } - bool ok = g_timerEvLoop->Init(TIMER_EVLOOP_THREADNAME); - if (!ok) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, "ev init failed."); - g_timerEvLoop = nullptr; - g_timersLock.Unlock(); - return false; - } - ret = timer::StartWatchTimer(); - g_timersLock.Unlock(); - g_initStatus.store(true); - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "Timer init succ."); - return ret; -} - -void TimerTools::Finalize() { - if (g_initStatus.load() == false) { - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "no need for Timer Finalize."); - return; - } - g_initStatus.store(false); - - ICTSBASE_LOG0(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "Timer Finalize."); - g_timersLock.Lock(); - if (g_runTimerFD >= 0) { - close(g_runTimerFD); - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "run timer close {ID}=%s", "{%d}", - g_runTimerFD); - g_runTimerFD = -1; - } - if (g_watchTimerFD >= 0) { - close(g_watchTimerFD); - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_INFO, PID_LITEBUS_LOG, "watch timer close {ID}=%s", "{%d}", - g_watchTimerFD); - g_watchTimerFD = -1; - } - g_timersLock.Unlock(); -} - -Timer TimerTools::AddTimer(const Duration &duration, const AID &aid, const std::function &thunk) { - if (g_initStatus.load() == false) { - return Timer(); - } - if (duration == 0) { - thunk(); - return Timer(); - } - static std::atomic id(1); - TimeWatch timeWatch = TimeWatch::In(duration); - Timer timer(id.fetch_add(1), timeWatch, aid, thunk); - - // Add the timer to timerpoll and Schedule it - g_timersLock.Lock(); - - if (g_timerPool->size() == 0 || timer.GetTimeWatch().Time() < g_timerPool->begin()->first) { - (*g_timerPool)[timer.GetTimeWatch().Time()].push_back(timer); - timer::ScheduleTick(*g_timerPool); - } else { - if (!(g_timerPool->size() >= 1)) { - ICTSBASE_LOG_STRING(ICTSBASE_LOG_COMMON_CODE, HLOG_LEVEL_ERROR, PID_LITEBUS_LOG, - "g_timerPool size invalid {size}=%s", "{%zd}", g_timerPool->size()); - } - (*g_timerPool)[timer.GetTimeWatch().Time()].push_back(timer); - } - g_timersLock.Unlock(); - - return timer; -} - -bool TimerTools::Cancel(const Timer &timer) { - if (g_initStatus.load() == false) { - return false; - } - - bool canceled = false; - g_timersLock.Lock(); - Duration duration = timer.GetTimeWatch().Time(); - if (g_timerPool->count(duration) > 0) { - canceled = true; - (*g_timerPool)[duration].remove(timer); - if ((*g_timerPool)[duration].empty()) { - (void)(g_timerPool->erase(duration)); - } - } - g_timersLock.Unlock(); - - return canceled; -} -} // namespace mindspore diff --git a/mindspore/core/mindrt/src/timer/timewatch.cc b/mindspore/core/mindrt/src/timer/timewatch.cc deleted file mode 100644 index 5f8c12f6eb..0000000000 --- a/mindspore/core/mindrt/src/timer/timewatch.cc +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed 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 "timer/timewatch.h" - -namespace mindspore { - -TimeWatch::TimeWatch() : duration(Now()) {} - -TimeWatch::TimeWatch(const Duration &d) : duration(d) {} - -TimeWatch::TimeWatch(const TimeWatch &that) : duration(that.duration) {} - -TimeWatch::~TimeWatch() {} - -Duration TimeWatch::Now() { - struct timespec ts = {0, 0}; - (void)clock_gettime(CLOCK_MONOTONIC, &ts); - Duration duration = ts.tv_sec * SECTOMILLI + (ts.tv_nsec / MICRTONANO) / MILLITOMICR; - return duration; -} - -TimeWatch TimeWatch::In(const Duration &duration) { return TimeWatch(Now() + duration); } - -TimeWatch &TimeWatch::operator=(const TimeWatch &that) { - if (&that != this) { - duration = that.duration; - } - - return *this; -} - -TimeWatch &TimeWatch::operator=(const Duration &d) { - duration = Now() + d; - return *this; -} - -bool TimeWatch::operator==(const TimeWatch &that) const { return duration == that.duration; } - -bool TimeWatch::operator<(const TimeWatch &that) const { return duration < that.duration; } - -bool TimeWatch::operator<=(const TimeWatch &that) const { return duration <= that.duration; } - -Duration TimeWatch::Time() const { return duration; } - -Duration TimeWatch::Remaining() const { - Duration nowTime = Now(); - return duration > nowTime ? (duration - nowTime) : 0; -} - -bool TimeWatch::Expired() const { return duration <= Now(); } - -} // namespace mindspore diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 59c173ca5c..907adc781d 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -26,6 +26,7 @@ option(BUILD_MINDDATA_EXAMPLE "" on) option(ENABLE_VERBOSE "" off) option(ENABLE_SSE "if x86_64 support SSE instruction set" off) option(ENABLE_AVX "if x86_64 support SSE instruction set" off) +#option(ENABLE_MINDRT "if support mindrt" on) set(DIR_PREFIX mindspore-lite) set(MS_VERSION ${MS_VERSION_MAJOR}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION}) @@ -55,6 +56,7 @@ else() set(PROCESS_UNIT cpu) endif() + if(SUPPORT_NPU) set(DDK_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib") if(PLATFORM_ARM64) @@ -115,6 +117,7 @@ include_directories(${CORE_DIR}/ir) include_directories(${CCSRC_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) include_directories(${TOP_DIR}/third_party) include_directories(${CMAKE_BINARY_DIR}) include_directories(${CCSRC_DIR}/minddata/dataset/liteapi) @@ -134,6 +137,11 @@ if(ENABLE_CONVERTER OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL include(${TOP_DIR}/cmake/external_libs/json.cmake) endif() +set(ENABLE_MINDRT "off") +if(PLATFORM_ARM AND NOT SUPPORT_TRAIN) + set(ENABLE_MINDRT "on") +endif() + file(GLOB FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.fbs) ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_src ${CMAKE_BINARY_DIR}/schema "") ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_inner_src ${CMAKE_BINARY_DIR}/schema/inner @@ -200,6 +208,12 @@ if(WIN32) add_compile_definitions(BUILDING_DLL) endif() +if(ENABLE_MINDRT) + include_directories(${CORE_DIR}/mindrt/include) + add_compile_definitions(ENABLE_MINDRT) + add_subdirectory(${CORE_DIR}/mindrt mindspore_mindrt) +endif() + if(ENABLE_CONVERTER) if(PLATFORM_ARM) MESSAGE(FATAL_ERROR "Cannot build converter in arm platform") diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index cd576926fc..23c63879e8 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -106,6 +106,14 @@ if(SUPPORT_TRAIN) ) endif() +if(ENABLE_MINDRT) + set(LITE_SRC + ${LITE_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc + ${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc + ) +endif() + add_subdirectory(ops) add_subdirectory(runtime/kernel/arm) @@ -119,6 +127,12 @@ set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-li set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") + +if(ENABLE_MINDRT) + target_link_libraries(mindspore-lite mindrt_mid) + target_link_libraries(mindspore-lite_static mindrt_mid) +endif() + if(SUPPORT_GPU STREQUAL opencl) add_subdirectory(runtime/kernel/opencl) target_link_libraries(mindspore-lite cpu_kernel_mid opencl_kernel_mid nnacl cpu_ops_mid) diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index 4aeb234432..d21202fa14 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -40,8 +40,8 @@ int Executor::CheckInputs(const std::vector &in_tensors) { return RET_OK; } -int Executor::Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator, const KernelCallBack &before, +int Executor::Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator, const KernelCallBack &before, const KernelCallBack &after) { MS_ASSERT(nullptr != allocator); auto ret = this->CheckInputs(in_tensors); @@ -89,9 +89,9 @@ int Executor::Run(std::vector &in_tensors, std::vector &out_ return RET_OK; } -int CpuExecutor::Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator, const KernelCallBack &before, - const KernelCallBack &after) { +int CpuExecutor::Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator, + const KernelCallBack &before, const KernelCallBack &after) { MS_ASSERT(nullptr != allocator); // not check input for merge. too hard if (kernels.front()->Type() != schema::PrimitiveType_Merge) { diff --git a/mindspore/lite/src/executor.h b/mindspore/lite/src/executor.h index 0fc59bea93..bb0e69b22c 100644 --- a/mindspore/lite/src/executor.h +++ b/mindspore/lite/src/executor.h @@ -30,8 +30,8 @@ class Executor { virtual int Prepare(const std::vector &kernels) { return RET_OK; } - virtual int Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator = nullptr, + virtual int Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); protected: @@ -43,8 +43,8 @@ class CpuExecutor : public Executor { CpuExecutor() = default; virtual ~CpuExecutor() = default; - int Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator = nullptr, + int Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; }; diff --git a/mindspore/lite/src/lite_kernel.cc b/mindspore/lite/src/lite_kernel.cc index cf3e745043..4fb2c18cd5 100644 --- a/mindspore/lite/src/lite_kernel.cc +++ b/mindspore/lite/src/lite_kernel.cc @@ -378,7 +378,7 @@ int LiteKernelUtil::TopologicalSortKernels(std::vector *ke return RET_OK; } -void LiteKernelUtil::InitTensorInitRefCount(std::vector &kernels) { +void LiteKernelUtil::InitTensorInitRefCount(const std::vector &kernels) { for (auto *kernel : kernels) { kernel->InitOutTensorInitRefCount(); } diff --git a/mindspore/lite/src/lite_kernel.h b/mindspore/lite/src/lite_kernel.h index f8bdd298e8..365a40e5e9 100644 --- a/mindspore/lite/src/lite_kernel.h +++ b/mindspore/lite/src/lite_kernel.h @@ -197,7 +197,7 @@ class LiteKernel { std::vector in_kernels_; std::vector out_kernels_; bool train_mode_ = false; - bool trainable_ = false; // paramaters of this Kernel are trained in Train Session + bool trainable_ = false; // parameters of this Kernel are trained in Train Session bool is_model_output_ = false; SubGraphType subgraph_type_ = kNotSubGraph; #ifdef SUPPORT_TRAIN @@ -223,7 +223,7 @@ class LiteKernelUtil { static int TopologicalSortKernels(std::vector *kernels); - static void InitTensorInitRefCount(std::vector &kernels); + static void InitTensorInitRefCount(const std::vector &kernels); static int SetInput(LiteKernel &kernelMod, const std::vector &inputs); }; diff --git a/mindspore/lite/src/lite_mindrt.cc b/mindspore/lite/src/lite_mindrt.cc new file mode 100644 index 0000000000..c88667b8b1 --- /dev/null +++ b/mindspore/lite/src/lite_mindrt.cc @@ -0,0 +1,80 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed 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 "src/lite_mindrt.h" +#include "mindrt/include/litebus.hpp" + +namespace mindspore::lite { +int LiteOpActor::CompileArrow() { + int outTensorSize = static_cast(kernel_->out_tensors().size()); + for (int i = 0; i < outTensorSize; i++) { + for (auto out : kernel_->out_kernels()) { + int inTensorSize = static_cast(out->in_tensors().size()); + int to_input_index = -1; + for (int j = 0; j < inTensorSize; j++) { + if (kernel_->out_tensors()[i] == out->in_tensors()[j]) { + to_input_index = j; + break; + } + } + if (to_input_index == -1) { + break; + } + auto id = out->name() + this->GetAID().Url(); + auto arrow = std::make_shared(i, id, to_input_index); + if (arrow == nullptr) { + MS_LOG(ERROR) << "create OpArrow failed, out kernel: " << out->name(); + return RET_ERROR; + } + output_op_arrow_.emplace_back(std::move(arrow)); + break; + } + } + return RET_OK; +} + +void LiteOpActor::SetOutputData(OpContext *context) { + auto size = context->outputData_->size(); + MS_ASSERT(size == context->results_->size()); + for (size_t i = 0; i < size; i++) { + auto outputData = context->outputData_->at(i); + if (GetAID() == outputData->op_id_) { + outputData->data_ = kernel_->out_tensors()[outputData->index_]; + context->SetResult(i, RET_OK); + } + } +} + +int MindrtInit() { return mindspore::Initialize("tcp://127.0.0.1:8080", "", "", "", 1); } + +std::vector> CreateOpActor(const std::vector &kernels) { + std::vector> actors; + for (auto kernel : kernels) { + auto actor = std::make_shared(kernel); + if (actor == nullptr) { + MS_LOG(ERROR) << "create LiteOpActor failed: " << kernel->name(); + actors.clear(); + return actors; + } + auto aid = mindspore::Spawn(actor); + actors.push_back(actor); + } + + return actors; +} + +} // namespace mindspore::lite diff --git a/mindspore/lite/src/lite_mindrt.h b/mindspore/lite/src/lite_mindrt.h new file mode 100644 index 0000000000..dd52ae91a1 --- /dev/null +++ b/mindspore/lite/src/lite_mindrt.h @@ -0,0 +1,92 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed 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. + */ + +#ifndef MINDSPORE_LITE_SRC_LITE_MINDRT_H_ +#define MINDSPORE_LITE_SRC_LITE_MINDRT_H_ +#include +#include +#include +#include +#include "actor/op_actor.h" +#include "src/lite_kernel.h" +#include "actor/actor.h" +#include "async/uuid_base.h" +#include "async/future.h" + +namespace mindspore { +namespace lite { + +typedef enum { GRAPH, OP_BY_OP } MindRTMode; + +class LiteOpActor : public OpActor { + public: + explicit LiteOpActor(kernel::LiteKernel *kernel) : OpActor(kernel->name()), kernel_(kernel) {} + virtual ~LiteOpActor() = default; + virtual void OpRun(OpDataPtr inputs, OpContext *context = nullptr) { + input_op_datas_[context->sequential_num_].push_back(inputs); + if (input_op_datas_[context->sequential_num_].size() < kernel_->in_tensors().size()) { + return; + } + auto ret = RunKernel(); + if (ret != RET_OK) { + context->SetFailed(ret); + input_op_datas_.erase(context->sequential_num_); + return; + } + SetOutputData(context); + input_op_datas_.erase(context->sequential_num_); + } + void Init() { + auto ret = CompileArrow(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "CompileArrow failed, name: " << kernel_->name(); + // do not support return error + } + } + int CompileArrow(); + int RunKernel() { + int ret; + ret = kernel_->PreProcess(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "PreProcess kernel failed, name: " << kernel_->name(); + return ret; + } + ret = kernel_->Run(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "run kernel failed, name: " << kernel_->name(); + return ret; + } + ret = kernel_->PostProcess(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "PostProcess kernel failed, name: " << kernel_->name(); + return ret; + } + + return ret; + } + + private: + void SetOutputData(OpContext *context); + + kernel::LiteKernel *kernel_; +}; + +int MindrtInit(); +std::vector> CreateOpActor(const std::vector &kernels); + +} // namespace lite +} // namespace mindspore +#endif // MINDSPORE_LITE_SRC_LITE_MINDRT_H_ diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index e8e678631c..9e96562be6 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -28,6 +28,9 @@ #include "src/kernel_registry.h" #include "src/lite_model.h" #include "src/dequant.h" +#ifdef ENABLE_MINDRT +#include "src/mindrt_executor.h" +#endif #if SUPPORT_NPU #include "src/runtime/agent/npu/npu_manager.h" #include "src/runtime/agent/npu/optimizer/npu_pass_manager.h" @@ -419,6 +422,7 @@ int LiteSession::CompileGraph(Model *model) { is_running_.store(false); return ret; } + is_running_.store(false); return RET_OK; } @@ -511,7 +515,15 @@ int LiteSession::Init(const Context *context) { is_running_.store(false); return ret; } +#ifdef ENABLE_MINDRT + if (context_->IsCpuEnabled() && !context_->IsGpuEnabled() && !context_->IsNpuEnabled() && kernels_.size() == 1) { + executor_ = new (std::nothrow) MindrtExecutor(); + } else { + executor_ = new (std::nothrow) Executor(); + } +#else executor_ = new (std::nothrow) Executor(); +#endif if (nullptr == executor_) { MS_LOG(ERROR) << "New Executor failed"; is_running_.store(false); diff --git a/mindspore/lite/src/mindrt_executor.cc b/mindspore/lite/src/mindrt_executor.cc new file mode 100644 index 0000000000..e4660f7a93 --- /dev/null +++ b/mindspore/lite/src/mindrt_executor.cc @@ -0,0 +1,81 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed 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 +#include "src/mindrt_executor.h" +#include "src/lite_mindrt.h" +#include "include/errorcode.h" + +namespace mindspore::lite { + +int MindrtExecutor::Prepare(const std::vector &kernels) { + auto ret = MindrtInit(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "MindrtInit failed"; + return ret; + } + auto kernelSize = kernels.size(); + opActors_ = CreateOpActor(kernels); + if (opActors_.size() != kernelSize) { + MS_LOG(ERROR) << "CreateOpActor failed"; + return RET_ERROR; + } + for (size_t i = 0; i < kernelSize; i++) { + if (kernels[i]->in_kernels().size() == 0) { + auto inTensorSize = kernels[i]->in_tensors().size(); + + for (size_t j = 0; j < inTensorSize; j++) { + auto data = + std::make_shared>(opActors_[i]->GetAID(), kernels[i]->in_tensors()[j], static_cast(j)); + inputData_.emplace_back(data); + } + } + + if (kernels[i]->out_kernels().size() == 0) { + auto outTensorSize = kernels[i]->out_tensors().size(); + + for (size_t j = 0; j < outTensorSize; j++) { + auto data = + std::make_shared>(opActors_[i]->GetAID(), kernels[i]->in_tensors()[j], static_cast(j)); + outputData_.emplace_back(data); + } + } + } + return RET_OK; +} + +int MindrtExecutor::Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator, + const KernelCallBack &before, const KernelCallBack &after) { + MS_ASSERT(nullptr != allocator); + if (kernels.front()->Type() != schema::PrimitiveType_Merge) { + auto ret = this->CheckInputs(in_tensors); + if (RET_OK != ret) { + MS_LOG(ERROR) << "CheckInputs failed"; + return ret; + } + } + // clear ref_count + for (auto *kernel : kernels) { + for (auto *tensor : kernel->in_tensors()) { + tensor->set_ref_count(0); + } + } + + return MindrtRun(inputData_, &outputData_); +} + +} // namespace mindspore::lite diff --git a/mindspore/lite/src/mindrt_executor.h b/mindspore/lite/src/mindrt_executor.h new file mode 100644 index 0000000000..9c22ce969b --- /dev/null +++ b/mindspore/lite/src/mindrt_executor.h @@ -0,0 +1,47 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed 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. + */ + +#ifndef MINDSPORE_LITE_SRC_MINDRT_EXECUTOR_H_ +#define MINDSPORE_LITE_SRC_MINDRT_EXECUTOR_H_ +#include +#include +#include "src/runtime/allocator.h" +#include "src/lite_kernel.h" +#include "src/lite_mindrt.h" +#include "src/executor.h" +#include "include/lite_session.h" + +namespace mindspore::lite { +// class Executor { +class MindrtExecutor : public Executor { + public: + MindrtExecutor() = default; + virtual ~MindrtExecutor() = default; + + virtual int Prepare(const std::vector &kernels); + + virtual int Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator = nullptr, + const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); + + protected: + std::vector> opActors_; + std::vector> inputData_; + std::vector> outputData_; +}; + +} // namespace mindspore::lite +#endif diff --git a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc index 9399ae1a0a..70c4447554 100644 --- a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc +++ b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc @@ -21,9 +21,9 @@ namespace mindspore::lite::opencl { -int OpenCLExecutor::Run(std::vector &inputs, std::vector &outputs, - std::vector &kernels, Allocator *allocator, const KernelCallBack &before, - const KernelCallBack &after) { +int OpenCLExecutor::Run(const std::vector &inputs, const std::vector &outputs, + const std::vector &kernels, Allocator *allocator, + const KernelCallBack &before, const KernelCallBack &after) { return RunOrTune(inputs, outputs, kernels, allocator, before, after, false); } diff --git a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h index 484dd0fafd..fa40750450 100644 --- a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h +++ b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h @@ -31,9 +31,9 @@ class OpenCLExecutor : public Executor { int Prepare(const std::vector &kernels) override { return RET_OK; } - int Run(std::vector &inputs, std::vector &outputs, std::vector &kernels, - Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, - const KernelCallBack &after = nullptr) override; + int Run(const std::vector &inputs, const std::vector &outputs, + const std::vector &kernels, Allocator *allocator = nullptr, + const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; int RunOrTune(const std::vector &inputs, const std::vector &outputs, const std::vector &kernels, Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr, bool is_tune = false); diff --git a/mindspore/lite/src/runtime/parallel_executor.cc b/mindspore/lite/src/runtime/parallel_executor.cc index 056005f48d..18cc0860b1 100644 --- a/mindspore/lite/src/runtime/parallel_executor.cc +++ b/mindspore/lite/src/runtime/parallel_executor.cc @@ -48,8 +48,8 @@ static int RunKernel(void *data, int index) { return 0; } -int ParallelExecutor::Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator, +int ParallelExecutor::Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator, const KernelCallBack &before, const KernelCallBack &after) { MS_ASSERT(nullptr != allocator); for (auto &inTensor : in_tensors) { diff --git a/mindspore/lite/src/runtime/parallel_executor.h b/mindspore/lite/src/runtime/parallel_executor.h index 916a95fd4d..cc428dd699 100644 --- a/mindspore/lite/src/runtime/parallel_executor.h +++ b/mindspore/lite/src/runtime/parallel_executor.h @@ -32,8 +32,8 @@ class ParallelExecutor : public Executor { int Prepare(const std::vector &kernels) override; - int Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator = nullptr, + int Run(const std::vector &in_tensors, const std::vector &out_tensors, + const std::vector &kernels, Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; inline kernel::LiteKernel *GetReadyKernel(const int index) const { return readyKernels.at(index); } inline void SetResult(const int index, const int result) { results.at(index) = result; } diff --git a/mindspore/lite/src/sub_graph_kernel.h b/mindspore/lite/src/sub_graph_kernel.h index 2375be879c..a303c7ce37 100644 --- a/mindspore/lite/src/sub_graph_kernel.h +++ b/mindspore/lite/src/sub_graph_kernel.h @@ -17,6 +17,7 @@ #ifndef MINDSPORE_LITE_SRC_SUB_GRAPH_H #define MINDSPORE_LITE_SRC_SUB_GRAPH_H +#include #include #include #include @@ -145,7 +146,8 @@ class CpuFp32SubGraph : public CpuSubGraph { std::vector nodes, const lite::InnerContext *ctx) : CpuSubGraph(inputs, outputs, std::move(in_kernels), std::move(out_kernels), std::move(nodes), ctx) { subgraph_type_ = kCpuFP32SubGraph; - this->name_ = "CpuFP32SubGraph"; + static std::atomic_int index = 0; + this->name_ = "CpuFP32SubGraph" + std::to_string(index++); } ~CpuFp32SubGraph() override = default; @@ -166,7 +168,8 @@ class CpuFp16SubGraph : public CpuSubGraph { std::vector nodes, const lite::InnerContext *ctx) : CpuSubGraph(inputs, outputs, std::move(in_kernels), std::move(out_kernels), std::move(nodes), ctx) { subgraph_type_ = kCpuFP16SubGraph; - this->name_ = "CpuFP16SubGraph"; + static std::atomic_int index = 0; + this->name_ = "CpuFP16SubGraph" + std::to_string(index++); } ~CpuFp16SubGraph() override = default; diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 3ba3378cd2..8144da213e 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -180,6 +180,17 @@ if(SUPPORT_GPU STREQUAL vulkan) ${VULKAN_RUNTIME_SRC} ) endif() + +if(ENABLE_MINDRT) + set(TEST_LITE_SRC + ${TEST_LITE_SRC} + ${LITE_DIR}/src/lite_mindrt.cc + ${LITE_DIR}/src/mindrt_executor.cc + ) + include_directories(${TOP_DIR}/mindspore/core/mindrt/include) +endif() + + ### converter if(ENABLE_CONVERTER) add_definitions(-DPRIMITIVE_WRITEABLE) @@ -331,10 +342,15 @@ endif() add_executable(lite-test ${TEST_SRC}) add_dependencies(lite-test fbs_src) + target_link_libraries(lite-test dl mindspore::gtest) + if(SUPPORT_TRAIN) target_link_libraries(lite-test minddata-lite) endif() +if(ENABLE_MINDRT) + target_link_libraries(lite-test mindrt_mid) +endif() if(PLATFORM_ARM64 AND ENABLE_FP16) target_link_libraries(lite-test nnacl_fp16_mid nnacl_optimize_mid) diff --git a/mindspore/lite/tools/benchmark/CMakeLists.txt b/mindspore/lite/tools/benchmark/CMakeLists.txt index 0972bfd994..425490c891 100644 --- a/mindspore/lite/tools/benchmark/CMakeLists.txt +++ b/mindspore/lite/tools/benchmark/CMakeLists.txt @@ -4,7 +4,6 @@ set(COMMON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/file_utils.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils.cc ) - add_executable(benchmark ${CMAKE_CURRENT_SOURCE_DIR}/main.cc ${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cc diff --git a/mindspore/lite/tools/cropper/CMakeLists.txt b/mindspore/lite/tools/cropper/CMakeLists.txt index 0c3db33a1c..b9082816dd 100644 --- a/mindspore/lite/tools/cropper/CMakeLists.txt +++ b/mindspore/lite/tools/cropper/CMakeLists.txt @@ -3,6 +3,8 @@ set(COMMON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../common/flag_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/file_utils.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/log_adapter.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/errorcode.cc ) add_executable(cropper @@ -14,7 +16,7 @@ add_executable(cropper add_dependencies(cropper fbs_src) -target_link_libraries(cropper mindspore-lite_static) +target_link_libraries(cropper) add_custom_command(TARGET cropper POST_BUILD COMMAND bash build_cropper_config.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/mindspore/lite/tools/schema_gen/CMakeLists.txt b/mindspore/lite/tools/schema_gen/CMakeLists.txt index c6d7dfa948..5f0832705a 100644 --- a/mindspore/lite/tools/schema_gen/CMakeLists.txt +++ b/mindspore/lite/tools/schema_gen/CMakeLists.txt @@ -5,6 +5,7 @@ set(COMMON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../common/flag_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/file_utils.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/log_adapter.cc ) add_executable(schema_gen ${CMAKE_CURRENT_SOURCE_DIR}/main.cc