Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dipu): move some env vars to environs.hpp #911

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions dipu/torch_dipu/csrc_dipu/base/environ.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024, DeepLink.

Check notice on line 1 in dipu/torch_dipu/csrc_dipu/base/environ.hpp

View workflow job for this annotation

GitHub Actions / clang-format

Run clang-format on dipu/torch_dipu/csrc_dipu/base/environ.hpp

File dipu/torch_dipu/csrc_dipu/base/environ.hpp does not conform to Custom style guidelines. (lines 89, 96, 98, 101, 102, 104, 105, 106, 107)
//
// dipu::environ contains all DIPU configurations set via environment variables.
//
Expand Down Expand Up @@ -86,11 +86,27 @@
// applyDelayedRegister() is called.
DIPU_ENV_VAR(immediateRegisterOp, "DIPU_IMMEDIATE_REGISTER_OP", bool, false);
inline const std::string kTorchAllocatorName = "TORCH";
// Determine the name of the host memory cache algorithm
// based on the current environment configuration.
DIPU_ENV_VAR(hostMemCachingAlgorithm, "DIPU_HOST_MEMCACHING_ALGORITHM",
std::string, kTorchAllocatorName);
// Used to specify the name of the device memory cache algorithm.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Used to specify the name of the device memory cache algorithm.
// Devices' memory caching algorithm.
// Candidates: TORCH, BF, BS, RAW

DIPU_ENV_VAR(deviceMemCachingAlgorithm, "DIPU_DEVICE_MEMCACHING_ALGORITHM",
std::string, kTorchAllocatorName);
// Used to configure and initialize an instance of an object "CachingAllocatorConfig".
DIPU_ENV_VAR(torchAllocatorConf, "DIPU_TORCH_ALLOCATOR_CONF", std::string, "");
// maxExtendSize is used to limit the maximum size of an extension
// in the memory allocation in function of "extend()".
DIPU_ENV_VAR(maxExtendSize, "DIPU_MAX_EXTEND_SIZE", std::size_t, 1024);
// Configure a value to limit the maximum length of the asynchronous resource pool
// to avoid resource leakage and optimize resource management.
inline const std::size_t kDefaultMaxAsyncResourcePoolLength = 96;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inline const std::size_t kDefaultMaxAsyncResourcePoolLength = 96;
constexpr std::size_t kDefaultMaxAsyncResourcePoolLength = 96;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有些地方定义了常量,有些地方直接写了默认值,建议统一起来

DIPU_ENV_VAR(maxAsyncResourcePoolLength, "DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH", std::size_t, kDefaultMaxAsyncResourcePoolLength);
// Control whether to force the use of back-off mode for P2P copy operation between Ascend chips.
DIPU_ENV_VAR(forceFallbackP2pCopybetweenascends, "DIPU_FORCE_FALLBACK_ASCEND_P2P_COPY", bool, false);
// Configure a numerical value to control the device 's affinity settings
// on the CPU to optimize thread scheduling during concurrent execution.
DIPU_ENV_VAR(affinityCpuAffinit, "DIPU_CPU_AFFINITY", std::size_t, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DIPU_ENV_VAR(affinityCpuAffinit, "DIPU_CPU_AFFINITY", std::size_t, 0);
DIPU_ENV_VAR(cpuAffinity, "DIPU_CPU_AFFINITY", std::size_t, 0);


#undef DIPU_ENV_VAR

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, DeepLink.

Check notice on line 1 in dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp

View workflow job for this annotation

GitHub Actions / clang-format

Run clang-format on dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp

File dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp does not conform to Custom style guidelines. (lines 3)

#include <functional>
#include <memory>
Expand All @@ -12,11 +12,12 @@
#include "DIPUCachingAllocator.h"
#include "DIPUSpinMutex.h"

#include "csrc_dipu/base/environ.hpp"

namespace dipu {

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
const size_t kMaxExtendSize = get_env_or_default("DIPU_MAX_EXTEND_SIZE", 1024)
<< 20U;
const size_t kMaxExtendSize = environ::maxExtendSize() << 20U;

class BFCachingAllocatorImpl {
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, DeepLink.

Check notice on line 1 in dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp

View workflow job for this annotation

GitHub Actions / clang-format

Run clang-format on dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp

File dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp does not conform to Custom style guidelines. (lines 3, 31)

#include "DIPUCachingAllocator.h"

Expand All @@ -20,15 +20,15 @@
#include "DIPUCachingDeviceAllocator.h"
#include "DIPUCachingHostAllocator.h"

#include "csrc_dipu/base/environ.hpp"

namespace dipu {

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::mutex DIPURawDeviceAllocator::mutex_;

constexpr size_t kDefaultMaxAsyncResourcePoolLength = 96;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
const size_t kMaxAsyncResourcePoolLength = get_env_or_default(
"DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH", kDefaultMaxAsyncResourcePoolLength);
const size_t kMaxAsyncResourcePoolLength = environ::maxAsyncResourcePoolLength();

namespace {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ deviceId_t current_device() {
}

void setCpuAffinity(const int device) {
static int affinity = get_env_or_default("DIPU_CPU_AFFINITY", 0);
static int affinity = environ::affinityCpuAffinit();

if (affinity < 0) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, DeepLink.

Check notice on line 1 in dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp

View workflow job for this annotation

GitHub Actions / clang-format

Run clang-format on dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp

File dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp does not conform to Custom style guidelines. (lines 2)
#include <acl/acl.h>
#include <acl/acl_op.h>
#include <acl/acl_op_compiler.h>
Expand All @@ -18,6 +18,8 @@

#include "basecommimpl.hpp"

#include "csrc_dipu/base/environ.hpp"

namespace dipu {

namespace devapis {
Expand All @@ -30,8 +32,7 @@

namespace {

const bool forceFallbackP2PCopy =
get_env_or_default("DIPU_FORCE_FALLBACK_ASCEND_P2P_COPY", false);
const bool forceFallbackP2PCopy = environ::forceFallbackP2pCopybetweenascends();

class NpuP2PInfo {
enum class P2pStatus : int8_t {
Expand Down
Loading