From 37f936ae2ed26072cce777d1214fe061c42ae0b1 Mon Sep 17 00:00:00 2001 From: minmingzhu Date: Tue, 15 Oct 2024 17:44:52 +0800 Subject: [PATCH] update --- .../src/main/native/CCLInitSingleton.hpp | 41 +++++++------ mllib-dal/src/main/native/Communicator.hpp | 59 +++++++++---------- mllib-dal/src/main/native/Profile.hpp | 12 ++-- mllib-dal/src/main/native/Singleton.hpp | 45 +++++++------- 4 files changed, 76 insertions(+), 81 deletions(-) diff --git a/mllib-dal/src/main/native/CCLInitSingleton.hpp b/mllib-dal/src/main/native/CCLInitSingleton.hpp index eae728982..2805f8e3f 100644 --- a/mllib-dal/src/main/native/CCLInitSingleton.hpp +++ b/mllib-dal/src/main/native/CCLInitSingleton.hpp @@ -1,18 +1,18 @@ /******************************************************************************* - * Copyright 2020 Intel Corporation - * - * 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. - *******************************************************************************/ +* Copyright 2020 Intel Corporation +* +* 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. +*******************************************************************************/ #pragma once #include @@ -21,10 +21,10 @@ #include "Logger.h" class CCLInitSingleton { - public: +public: ccl::shared_ptr_class kvs; - static CCLInitSingleton &get(int size, int rank, ccl::string ccl_ip_port) { + static CCLInitSingleton& get(int size, int rank, ccl::string ccl_ip_port) { static std::once_flag flag; static CCLInitSingleton instance; std::call_once(flag, [size, rank, ccl_ip_port] { @@ -33,8 +33,9 @@ class CCLInitSingleton { return instance; } - private: - CCLInitSingleton() {} +private: + CCLInitSingleton() { + } CCLInitSingleton(int size, int rank, ccl::string ccl_ip_port) { auto t1 = std::chrono::high_resolution_clock::now(); @@ -48,9 +49,7 @@ class CCLInitSingleton { auto t2 = std::chrono::high_resolution_clock::now(); auto duration = - (float)std::chrono::duration_cast(t2 - - t1) - .count(); + (float)std::chrono::duration_cast(t2 - t1).count(); logger::println(logger::INFO, "OneCCL singleton init took %f secs", duration / 1000); diff --git a/mllib-dal/src/main/native/Communicator.hpp b/mllib-dal/src/main/native/Communicator.hpp index 6a2699e0b..bdd5072c9 100644 --- a/mllib-dal/src/main/native/Communicator.hpp +++ b/mllib-dal/src/main/native/Communicator.hpp @@ -1,27 +1,27 @@ /******************************************************************************* - * Copyright 2021 Intel Corporation - * - * 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. - *******************************************************************************/ +* Copyright 2021 Intel Corporation +* +* 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. +*******************************************************************************/ #pragma once -// cpp ccl host communicator +//cpp ccl host communicator #ifdef ONEDAL_DATA_PARALLEL -#include "Singleton.hpp" #include "oneapi/ccl.hpp" #include "oneapi/dal/detail/ccl/communicator.hpp" +#include "Singleton.hpp" namespace de = oneapi::dal::detail; namespace oneapi::dal::preview::spmd { @@ -32,38 +32,37 @@ struct ccl {}; class ccl_info { friend class de::singleton; - private: +private: ccl_info(int size, int rankId, ccl::shared_ptr_class keyvs) { rank = rankId; rank_count = size; kvs = keyvs; } - public: +public: ccl::shared_ptr_class kvs; int rank; int rank_count; }; template -communicator -make_communicator(int size, int rank, - const ccl::shared_ptr_class kvs) { - auto &info = de::singleton::get(size, rank, kvs); +communicator make_communicator(int size, int rank, const ccl::shared_ptr_class kvs) { + auto& info = de::singleton::get(size, rank, kvs); // integral cast - return oneapi::dal::detail::ccl_communicator{ - info.kvs, info.rank, info.rank_count}; + return oneapi::dal::detail::ccl_communicator{ info.kvs, + info.rank, + info.rank_count }; } template -communicator -make_communicator(sycl::queue &queue, int size, int rank, - const ccl::shared_ptr_class kvs) { - auto &info = de::singleton::get(size, rank, kvs); +communicator make_communicator(sycl::queue& queue, int size, int rank, const ccl::shared_ptr_class kvs) { + auto& info = de::singleton::get(size, rank, kvs); return oneapi::dal::detail::ccl_communicator{ - queue, info.kvs, + queue, + info.kvs, oneapi::dal::detail::integral_cast(info.rank), - oneapi::dal::detail::integral_cast(info.rank_count)}; + oneapi::dal::detail::integral_cast(info.rank_count) + }; } } // namespace oneapi::dal::preview::spmd diff --git a/mllib-dal/src/main/native/Profile.hpp b/mllib-dal/src/main/native/Profile.hpp index 54d15d5fd..429e65b65 100644 --- a/mllib-dal/src/main/native/Profile.hpp +++ b/mllib-dal/src/main/native/Profile.hpp @@ -1,9 +1,9 @@ #pragma once -#include "Logger.h" #include #include #include +#include "Logger.h" class Profiler { public: @@ -11,8 +11,7 @@ class Profiler { void startProfile(std::string s = "") { action = s; - logger::println(logger::INFO, "%s (native): start %s", subject.c_str(), - action.c_str()); + logger::println(logger::INFO, "%s (native): start %s", subject.c_str(), action.c_str()); startTime = std::chrono::high_resolution_clock::now(); } @@ -21,14 +20,11 @@ class Profiler { auto duration = std::chrono::duration_cast( end_time - startTime) .count(); - logger::println(logger::INFO, "%s (native): start %s took %f secs", - subject.c_str(), action.c_str(), - (float)duration / 1000); + logger::println(logger::INFO, "%s (native): start %s took %f secs", subject.c_str(), action.c_str(), (float)duration / 1000); } void println(std::string msg) { - logger::println(logger::INFO, "%s (native): %s", subject.c_str(), - msg.c_str()); + logger::println(logger::INFO, "%s (native): %s", subject.c_str(), msg.c_str()); } private: diff --git a/mllib-dal/src/main/native/Singleton.hpp b/mllib-dal/src/main/native/Singleton.hpp index 92f1b71a3..1169feac4 100644 --- a/mllib-dal/src/main/native/Singleton.hpp +++ b/mllib-dal/src/main/native/Singleton.hpp @@ -1,18 +1,18 @@ /******************************************************************************* - * Copyright 2020 Intel Corporation - * - * 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. - *******************************************************************************/ +* Copyright 2020 Intel Corporation +* +* 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. +*******************************************************************************/ #pragma once @@ -20,18 +20,19 @@ namespace oneapi::dal::detail { namespace v1 { -template class singleton { - public: - static T &get(int size, int rank, ccl::shared_ptr_class kvs) { +template +class singleton { +public: + static T& get(int size, int rank, ccl::shared_ptr_class kvs) { static std::once_flag flag; - std::call_once(flag, - [size, rank, kvs] { get_instance(size, rank, kvs); }); + std::call_once(flag, [size, rank, kvs] { + get_instance(size, rank, kvs); + }); return get_instance(size, rank, kvs); } - private: - static T &get_instance(int size, int rank, - ccl::shared_ptr_class kvs) { +private: + static T& get_instance(int size, int rank, ccl::shared_ptr_class kvs) { static T instance{size, rank, kvs}; return instance; }