Skip to content

Commit

Permalink
improve communicator code
Browse files Browse the repository at this point in the history
  • Loading branch information
minmingzhu committed Nov 1, 2024
1 parent 1cc7cba commit be13be9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 88 deletions.
69 changes: 25 additions & 44 deletions mllib-dal/src/main/native/Communicator.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
/*******************************************************************************
* 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"

Expand All @@ -29,41 +28,23 @@ namespace oneapi::dal::preview::spmd {
namespace backend {
struct ccl {};
} // namespace backend
class ccl_info {
friend class de::singleton<ccl_info>;

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

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) {
// 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>{ kvs,
rank,
size };
}

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) {
return oneapi::dal::detail::ccl_communicator<device_memory_access::usm>{
queue, info.kvs,
oneapi::dal::detail::integral_cast<std::int64_t>(info.rank),
oneapi::dal::detail::integral_cast<std::int64_t>(info.rank_count)};
queue,
kvs,
oneapi::dal::detail::integral_cast<std::int64_t>(rank),
oneapi::dal::detail::integral_cast<std::int64_t>(size)
};
}

} // namespace oneapi::dal::preview::spmd
Expand Down
44 changes: 0 additions & 44 deletions mllib-dal/src/main/native/Singleton.hpp

This file was deleted.

0 comments on commit be13be9

Please sign in to comment.