Skip to content

Commit

Permalink
format code style
Browse files Browse the repository at this point in the history
  • Loading branch information
minmingzhu committed Sep 10, 2024
1 parent ea585f0 commit 62c0cc5
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 87 deletions.
41 changes: 21 additions & 20 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,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();
Expand All @@ -49,7 +48,9 @@ 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
1 change: 0 additions & 1 deletion mllib-dal/src/main/native/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
#endif

#include "GPU.h"
#include "Communicator.hpp"
#include "oneapi/dal/table/homogen.hpp"
59 changes: 30 additions & 29 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,37 +32,38 @@ 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
2 changes: 1 addition & 1 deletion mllib-dal/src/main/native/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "service.h"
#include <CL/cl.h>
#include <CL/sycl.hpp>
#include <daal_sycl.h>
#include <jni.h>
#include <oneapi/ccl.hpp>

#include "Communicator.hpp"

sycl::queue getAssignedGPU(const ComputeDevice device, jint *gpu_indices);
Expand Down
12 changes: 8 additions & 4 deletions mllib-dal/src/main/native/Profile.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#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 @@ -20,11 +21,14 @@ 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: 22 additions & 23 deletions mllib-dal/src/main/native/Singleton.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
/*******************************************************************************
* 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
17 changes: 8 additions & 9 deletions mllib-dal/src/main/native/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<daal::byte> ByteBuffer;
typedef std::shared_ptr<csr_table> CSRTablePtr;

enum class ComputeDevice { host, cpu, gpu, uninitialized };
const std::string ComputeDeviceString[] = {"HOST", "CPU", "GPU"};
Expand All @@ -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<homogen_table> HomogenTablePtr;
typedef std::shared_ptr<csr_table> 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<const float>(table).pull();
Expand Down

0 comments on commit 62c0cc5

Please sign in to comment.