Skip to content

Commit 1cef027

Browse files
author
zhangyue
committed
style(ascend): rename free-function helpers from camelCase to PascalCase
Per Google C++ Style Guide §Function Names: ordinary non-accessor functions are PascalCase. Accessors/mutators (get/set on class members) are snake_case. These 7 are standalone helpers / converters / predicates — not member accessors — so they need PascalCase. threadLocalAtbContext → ThreadLocalAtbContext getAtbContext → GetAtbContext toAtbTensor (×2) → ToAtbTensor isAclRuntimeAlive → IsAclRuntimeAlive buildAclTensor → BuildAclTensor toAclDtype → ToAclDtype isIntegerDtype → IsIntegerDtype CANN APIs (`aclrtGetDevice`, `aclCreateTensor`, …), STL/PyTorch interop methods (`begin`/`end`/`size`/`data`/…), and class accessors (`get_<field>`/`set_<field>`) are all kept as-is — they either belong to another vendor or match the "looks like a variable" exception. Callers on the three category branches (op-simple / op-norm-rope / op-cache-attn) will pick up the new names automatically on rebase.
1 parent faf54b1 commit 1cef027

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/ascend/atb_common_.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ namespace infini::ops::ascend {
2323
// expensive (internal tiling buffer allocation), so we cache one per thread.
2424
// `SetExecuteStream` is called before every `Execute` to match the caller's
2525
// stream.
26-
inline atb::Context*& threadLocalAtbContext() {
26+
inline atb::Context*& ThreadLocalAtbContext() {
2727
thread_local atb::Context* ctx = nullptr;
2828

2929
return ctx;
3030
}
3131

32-
inline atb::Context* getAtbContext(aclrtStream stream) {
33-
auto*& ctx = threadLocalAtbContext();
32+
inline atb::Context* GetAtbContext(aclrtStream stream) {
33+
auto*& ctx = ThreadLocalAtbContext();
3434

3535
if (!ctx) {
3636
atb::Status s = atb::CreateContext(&ctx);
@@ -48,9 +48,9 @@ inline atb::Context* getAtbContext(aclrtStream stream) {
4848
// Sets dtype, ND format, shape dimensions, and the device data pointer.
4949
// The caller must keep the InfiniOps Tensor alive for the duration of the
5050
// ATB operation.
51-
inline atb::Tensor toAtbTensor(const Tensor& t) {
51+
inline atb::Tensor ToAtbTensor(const Tensor& t) {
5252
atb::Tensor out;
53-
out.desc.dtype = toAclDtype(t.dtype());
53+
out.desc.dtype = ToAclDtype(t.dtype());
5454
out.desc.format = ACL_FORMAT_ND;
5555
out.desc.shape.dimNum = t.ndim();
5656
assert(t.ndim() <= atb::MAX_DIM);
@@ -69,7 +69,7 @@ inline atb::Tensor toAtbTensor(const Tensor& t) {
6969
//
7070
// Useful for sub-views of a larger buffer (e.g. K-cache and V-cache halves
7171
// of a fused KV cache tensor).
72-
inline atb::Tensor toAtbTensor(const std::vector<int64_t>& shape,
72+
inline atb::Tensor ToAtbTensor(const std::vector<int64_t>& shape,
7373
aclDataType dtype, void* data,
7474
uint64_t data_size) {
7575
atb::Tensor out;

src/ascend/common.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace infini::ops::ascend {
1717
// static destructors run. Calling `aclrtGetDevice` is the cheapest
1818
// probe — it fails once the runtime is gone. Destructors that call
1919
// ACL/ATB APIs must guard with this to avoid use-after-finalize crashes.
20-
inline bool isAclRuntimeAlive() {
20+
inline bool IsAclRuntimeAlive() {
2121
int32_t dev_id = -1;
2222

2323
return aclrtGetDevice(&dev_id) == ACL_SUCCESS;
@@ -28,7 +28,7 @@ inline bool isAclRuntimeAlive() {
2828
// When `transpose_last2` is true the last two dimensions are swapped in the
2929
// descriptor (shape and strides) without copying data. This is used by GEMM
3030
// and Matmul to express a transpose via the view.
31-
inline aclTensor* buildAclTensor(const Tensor& t,
31+
inline aclTensor* BuildAclTensor(const Tensor& t,
3232
bool transpose_last2 = false) {
3333
std::vector<int64_t> shape(t.shape().begin(), t.shape().end());
3434
std::vector<int64_t> strides(t.strides().begin(), t.strides().end());
@@ -57,7 +57,7 @@ inline aclTensor* buildAclTensor(const Tensor& t,
5757
std::vector<int64_t> storage_shape = {storage_elems};
5858

5959
return aclCreateTensor(
60-
shape.data(), static_cast<int64_t>(shape.size()), toAclDtype(t.dtype()),
60+
shape.data(), static_cast<int64_t>(shape.size()), ToAclDtype(t.dtype()),
6161
strides.data(),
6262
/*storageOffset=*/0, ACL_FORMAT_ND, storage_shape.data(),
6363
static_cast<int64_t>(storage_shape.size()), const_cast<void*>(t.data()));
@@ -95,7 +95,7 @@ class AclTensorCache {
9595
}
9696

9797
explicit AclTensorCache(const Tensor& t, bool transpose_last2 = false)
98-
: dtype_{toAclDtype(t.dtype())} {
98+
: dtype_{ToAclDtype(t.dtype())} {
9999
shape_.assign(t.shape().begin(), t.shape().end());
100100
strides_.assign(t.strides().begin(), t.strides().end());
101101

@@ -119,7 +119,7 @@ class AclTensorCache {
119119
}
120120

121121
~AclTensorCache() {
122-
if (tensor_ && isAclRuntimeAlive()) {
122+
if (tensor_ && IsAclRuntimeAlive()) {
123123
aclDestroyTensor(tensor_);
124124
}
125125
}
@@ -158,7 +158,7 @@ class AclTensorCache {
158158
// referenced by a Repeatable `aclOpExecutor` which would be destroyed
159159
// alongside the tensor, and per CANN 8.5 docs that destruction is our
160160
// responsibility. In practice `aclDestroyAclOpExecutor` during process
161-
// shutdown crashes even with `isAclRuntimeAlive()` true — see `64c367c` —
161+
// shutdown crashes even with `IsAclRuntimeAlive()` true — see `64c367c` —
162162
// so operators leak the executor at shutdown; skipping `aclDestroyTensor`
163163
// here keeps `~AclTensorCache` from double-freeing a descriptor the
164164
// executor still holds.

src/ascend/data_type_.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace infini::ops::ascend {
1111

12-
inline aclDataType toAclDtype(DataType dt) {
12+
inline aclDataType ToAclDtype(DataType dt) {
1313
switch (dt) {
1414
case DataType::kFloat16:
1515
return ACL_FLOAT16;
@@ -40,7 +40,7 @@ inline aclDataType toAclDtype(DataType dt) {
4040
}
4141

4242
// Returns true for integer (signed or unsigned) DataType values.
43-
inline bool isIntegerDtype(DataType dt) {
43+
inline bool IsIntegerDtype(DataType dt) {
4444
switch (dt) {
4545
case DataType::kInt8:
4646
case DataType::kInt16:

src/ascend/gemm/kernel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class Operator<Gemm, Device::Type::kAscend> : public Gemm {
3636
std::optional<int> trans_b, Tensor c) const override {
3737
auto stream = static_cast<aclrtStream>(stream_);
3838

39-
auto t_self = ascend::buildAclTensor(c);
40-
auto t_a = ascend::buildAclTensor(a, trans_a_);
41-
auto t_b = ascend::buildAclTensor(b, trans_b_);
42-
auto t_out = ascend::buildAclTensor(c);
39+
auto t_self = ascend::BuildAclTensor(c);
40+
auto t_a = ascend::BuildAclTensor(a, trans_a_);
41+
auto t_b = ascend::BuildAclTensor(b, trans_b_);
42+
auto t_out = ascend::BuildAclTensor(c);
4343

4444
uint64_t ws_needed = 0;
4545
aclOpExecutor* executor = nullptr;

0 commit comments

Comments
 (0)