diff --git a/mllib-dal/src/main/native/CCLInitSingleton.hpp b/mllib-dal/src/main/native/CCLInitSingleton.hpp index 2805f8e3f..eae728982 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,9 +33,8 @@ 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(); @@ -49,7 +48,9 @@ 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/Common.hpp b/mllib-dal/src/main/native/Common.hpp index 5ead8c8c1..f6606f225 100644 --- a/mllib-dal/src/main/native/Common.hpp +++ b/mllib-dal/src/main/native/Common.hpp @@ -21,5 +21,4 @@ #endif #include "GPU.h" -#include "Communicator.hpp" #include "oneapi/dal/table/homogen.hpp" diff --git a/mllib-dal/src/main/native/Communicator.hpp b/mllib-dal/src/main/native/Communicator.hpp index bdd5072c9..6a2699e0b 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,37 +32,38 @@ 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/GPU.h b/mllib-dal/src/main/native/GPU.h index f704c6a69..ee4c7effb 100644 --- a/mllib-dal/src/main/native/GPU.h +++ b/mllib-dal/src/main/native/GPU.h @@ -3,9 +3,9 @@ #include "service.h" #include #include -#include #include #include + #include "Communicator.hpp" sycl::queue getAssignedGPU(const ComputeDevice device, jint *gpu_indices); diff --git a/mllib-dal/src/main/native/Profile.hpp b/mllib-dal/src/main/native/Profile.hpp index 429e65b65..54d15d5fd 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,7 +11,8 @@ 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(); } @@ -20,11 +21,14 @@ 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 1169feac4..92f1b71a3 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,19 +20,18 @@ 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; } diff --git a/mllib-dal/src/main/native/service.h b/mllib-dal/src/main/native/service.h index f208b8389..ca7db0345 100644 --- a/mllib-dal/src/main/native/service.h +++ b/mllib-dal/src/main/native/service.h @@ -54,13 +54,7 @@ using namespace daal::data_management; #endif #include "oneapi/dal/table/homogen.hpp" -using namespace oneapi::dal; -using namespace oneapi::dal::detail; - -typedef float GpuAlgorithmFPType; /* Algorithm floating-point type */ -typedef double CpuAlgorithmFPType; /* Algorithm floating-point type */ typedef std::vector ByteBuffer; -typedef std::shared_ptr CSRTablePtr; enum class ComputeDevice { host, cpu, gpu, uninitialized }; const std::string ComputeDeviceString[] = {"HOST", "CPU", "GPU"}; @@ -70,20 +64,25 @@ void printNumericTable(const NumericTablePtr &dataTable, size_t nPrintedCols = 0, size_t interval = 10); size_t serializeDAALObject(SerializationIface *pData, ByteBuffer &buffer); SerializationIfacePtr deserializeDAALObject(daal::byte *buff, size_t length); -CSRNumericTable *createFloatSparseTable(const std::string &datasetFileName); ComputeDevice getComputeDeviceByOrdinal(size_t computeDeviceOrdinal); -void saveCSRTablePtrToVector(const CSRTablePtr &ptr); #ifdef CPU_GPU_PROFILE -#include "oneapi/dal/table/common.hpp" #include "oneapi/dal/table/row_accessor.hpp" +using namespace oneapi::dal; +using namespace oneapi::dal::detail; +typedef float GpuAlgorithmFPType; /* Algorithm floating-point type */ +typedef double CpuAlgorithmFPType; /* Algorithm floating-point type */ typedef std::shared_ptr HomogenTablePtr; +typedef std::shared_ptr CSRTablePtr; void saveHomogenTablePtrToVector(const HomogenTablePtr &ptr); HomogenTablePtr createHomogenTableWithArrayPtr(size_t pNumTabData, size_t numRows, size_t numClos, sycl::queue queue); +CSRNumericTable *createFloatSparseTable(const std::string &datasetFileName); +void saveCSRTablePtrToVector(const CSRTablePtr &ptr); + NumericTablePtr homegenToSyclHomogen(NumericTablePtr ntHomogen); inline void printHomegenTable(const oneapi::dal::table &table) { auto arr = oneapi::dal::row_accessor(table).pull();