已关闭
[Bug-Report|缺陷反馈]: image/upsample_bicubic2d_grad 示例代码风格不一致与可读性问题 #579
cuijie创建于  6月29日关闭于  6月29日
cuijie成员
6月29日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

image/upsample_bicubic2d_grad 算子的示例代码与文档存在代码风格不一致及可读性问题:

  1. 魔法数字问题:在调用 aclnnUpsampleBicubic2dBackwardGetWorkspaceSize 时,scalesH 与 scalesW 直接使用字面量 1.1,未提取为具名常量,可读性较差,且不便于后续维护修改。
  2. 指针/引用符号风格不统一:示例代码中指针符号 * 与引用符号 & 的位置不一致,部分紧贴变量名(如 int *stream、const std::vector<T> &hostData、void *selfDeviceAddr、aclTensor *self),部分紧贴类型名(如 aclOpExecutor* executor),不符合统一的代码风格规范。
  3. 函数调用格式松散:部分多行函数调用(如 aclCreateTensor、aclrtMemcpy、aclnnUpsampleBicubic2dBackwardGetWorkspaceSize)参数被拆分到多行,格式不够紧凑,影响代码可读性。

Environment / 环境信息 (Mandatory / 必填)

  • 仓库:cann/ops-cv
  • 算子路径:image/upsample_bicubic2d_grad
  • 涉及文件:
    • docs/aclnnUpsampleBicubic2dBackward.md
    • examples/test_aclnn_upsample_bicubic2d_grad.cpp
  • 问题类型:示例代码与文档的代码风格问题(与硬件/软件运行环境无关)

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 进入仓库 cann/ops-cv。
  2. 打开文件 image/upsample_bicubic2d_grad/docs/aclnnUpsampleBicubic2dBackward.md,定位到示例代码段(约 362~480 行)。
  3. 打开文件 image/upsample_bicubic2d_grad/examples/test_aclnn_upsample_bicubic2d_grad.cpp,定位到 aclnnUpsampleBicubic2dBackwardGetWorkspaceSize 调用处(约 108~115 行)。
  4. 观察到:
    • aclnnUpsampleBicubic2dBackwardGetWorkspaceSize 调用中 scalesH/scalesW 使用字面量 1.1;
    • 指针/引用符号 *、& 位置不一致;
    • 多处函数调用参数被拆分到多行。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

  1. 将 aclnnUpsampleBicubic2dBackwardGetWorkspaceSize 调用中的 1.1 提取为具名常量 scalesH 与 scalesW。
  2. 统一指针/引用符号风格,将 * 和 & 紧贴类型名(如 int*、const std::vector<T>&、void*、aclTensor*、aclIntArray*、aclOpExecutor*)。
  3. 将过长的多行函数调用合并为更紧凑的格式,提升可读性。

涉及代码片段(修改前):

int Init(int32_t deviceId, aclrtStream *stream)
...
int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr,
    aclDataType dataType, aclTensor **tensor)
...
void *selfDeviceAddr = nullptr;
void *outDeviceAddr = nullptr;
aclTensor *self = nullptr;
aclTensor *out = nullptr;
...
const aclIntArray *outputSize = aclCreateIntArray(outArraySize.data(), outArraySize.size());
const aclIntArray *inputSize = aclCreateIntArray(inputArraySize.data(), inputArraySize.size());
...
aclOpExecutor *executor;
ret = aclnnUpsampleBicubic2dBackwardGetWorkspaceSize(
    self, outputSize, inputSize, 1, 1.1, 1.1, out, &workspaceSize, &executor);
...
*tensor = aclCreateTensor(shape.data(),
    shape.size(),
    dataType,
    strides.data(),
    0,
    aclFormat::ACL_FORMAT_NCHW,
    shape.data(),
    shape.size(),
    *deviceAddr);
...
ret = aclrtMemcpy(resultData.data(),
    resultData.size() * sizeof(resultData[0]),
    outDeviceAddr,
    size * sizeof(resultData[0]),
    ACL_MEMCPY_DEVICE_TO_HOST);

Special notes for this issue/备注 (Optional / 选填)

关联 PR:https://gitcode.com/cann/ops-cv/pulls/1064

该 PR 已对上述问题进行修复,本 Issue 用于记录对应的问题单。

likedislike
Ccuijie成员
6月29日 添加了label:bug-report
Ccuijie成员
6月29日 将 cuijie25 设为负责人
CANN-robotCANN-robot成员
6月29日 关闭了 issue
CANN-robotCANN-robot成员
6月29日 添加了label:resolved