Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
minmingzhu committed Oct 16, 2024
1 parent eedd941 commit 37f936a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 81 deletions.
41 changes: 20 additions & 21 deletions mllib-dal/src/main/native/CCLInitSingleton.hpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>
Expand All @@ -21,10 +21,10 @@
#include "Logger.h"

class CCLInitSingleton {
public:
public:
ccl::shared_ptr_class<ccl::kvs> 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] {
Expand All @@ -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();
Expand All @@ -48,9 +49,7 @@ class CCLInitSingleton {

auto t2 = std::chrono::high_resolution_clock::now();
auto duration =
(float)std::chrono::duration_cast<std::chrono::milliseconds>(t2 -
t1)
.count();
(float)std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();

logger::println(logger::INFO, "OneCCL singleton init took %f secs",
duration / 1000);
Expand Down
59 changes: 29 additions & 30 deletions mllib-dal/src/main/native/Communicator.hpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -32,38 +32,37 @@ struct ccl {};
class ccl_info {
friend class de::singleton<ccl_info>;

private:
private:
ccl_info(int size, int rankId, ccl::shared_ptr_class<ccl::kvs> keyvs) {
rank = rankId;
rank_count = size;
kvs = keyvs;
}

public:
public:
ccl::shared_ptr_class<ccl::kvs> kvs;
int rank;
int rank_count;
};

template <typename Backend>
communicator<device_memory_access::none>
make_communicator(int size, int rank,
const ccl::shared_ptr_class<ccl::kvs> kvs) {
auto &info = de::singleton<ccl_info>::get(size, rank, kvs);
communicator<device_memory_access::none> make_communicator(int size, int rank, const ccl::shared_ptr_class<ccl::kvs> kvs) {
auto& info = de::singleton<ccl_info>::get(size, rank, kvs);
// integral cast
return oneapi::dal::detail::ccl_communicator<device_memory_access::none>{
info.kvs, info.rank, info.rank_count};
return oneapi::dal::detail::ccl_communicator<device_memory_access::none>{ info.kvs,
info.rank,
info.rank_count };
}

template <typename Backend>
communicator<device_memory_access::usm>
make_communicator(sycl::queue &queue, int size, int rank,
const ccl::shared_ptr_class<ccl::kvs> kvs) {
auto &info = de::singleton<ccl_info>::get(size, rank, kvs);
communicator<device_memory_access::usm> make_communicator(sycl::queue& queue, int size, int rank, const ccl::shared_ptr_class<ccl::kvs> kvs) {
auto& info = de::singleton<ccl_info>::get(size, rank, kvs);
return oneapi::dal::detail::ccl_communicator<device_memory_access::usm>{
queue, info.kvs,
queue,
info.kvs,
oneapi::dal::detail::integral_cast<std::int64_t>(info.rank),
oneapi::dal::detail::integral_cast<std::int64_t>(info.rank_count)};
oneapi::dal::detail::integral_cast<std::int64_t>(info.rank_count)
};
}

} // namespace oneapi::dal::preview::spmd
Expand Down
12 changes: 4 additions & 8 deletions mllib-dal/src/main/native/Profile.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#pragma once

#include "Logger.h"
#include <chrono>
#include <iostream>
#include <string>
#include "Logger.h"

class Profiler {
public:
Profiler(const std::string &s) : subject(s) {}

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();
}

Expand All @@ -21,14 +20,11 @@ class Profiler {
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
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:
Expand Down
45 changes: 23 additions & 22 deletions mllib-dal/src/main/native/Singleton.hpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
/*******************************************************************************
* 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

namespace oneapi::dal::detail {

namespace v1 {

template <class T> class singleton {
public:
static T &get(int size, int rank, ccl::shared_ptr_class<ccl::kvs> kvs) {
template <class T>
class singleton {
public:
static T& get(int size, int rank, ccl::shared_ptr_class<ccl::kvs> 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<ccl::kvs> kvs) {
private:
static T& get_instance(int size, int rank, ccl::shared_ptr_class<ccl::kvs> kvs) {
static T instance{size, rank, kvs};
return instance;
}
Expand Down

0 comments on commit 37f936a

Please sign in to comment.