Closed
[Documentation|文档反馈]: aclnnBitwiseOrScalar 资料 out 数据类型列声明支持 BOOL,实测仅 other 也是 BOOL 时可用 #4001
liuhanwen8Add on 12 days agoClosed at 9 days ago
12 days ago Added label: documentation
xujiachen8
12 days ago Comments:
12 days ago Comments:
您好,感谢反馈!
在您报告的 Ascend 910B2、CANN 9.2.0 场景,BOOL out 需要推导出的计算类型也是 BOOL;self、other 都为 BOOL 时满足这一条件,整型结果不能隐式转换为 BOOL。核对 cann/ops-math 提交 5f717513abcb6a6b94a4ae61a8151e4ba65e9eb3,入口先推导类型,再检查结果能否转为 out;BOOL 计算走 LogicalOr,其他整型计算走 BitwiseOr。当前公共转换说明也没有开放整数到 BOOL 的转换。类型推导与检查、计算分支、转换关系
参数表的 out 列列出 BOOL,是候选输出类型的集合,并不表示它能与所有输入类型任意组合;错误码表已有“推导类型不能转换为 out”时返回 161002 的说明。可考虑在 out 使用说明中直接补充上述 BOOL 条件及正反例,减少跨表查阅。允许整数按“非零即真”转换则属于接口语义扩展,需要独立评估,不能作为文档说明的直接替换。本轮未重新上板实测,我们会继续评估这处说明的清晰度。


12 days ago Assign chen_0715 as responsible person
12 days ago Added label: pending-confirmation
12 days ago Removed label: pending-confirmation
10 days ago Assign BoyangZhang as responsible person
10 days ago Removed responsible person BoyangZhang
10 days ago Removed responsible person chen_0715
10 days ago Assign BoyangZhang as responsible person
9 days ago Associated pull request
9 days ago Close issue
8 days ago Added label: resolved
现象
资料
out参数「数据类型」列列出了BOOL,但实测只有 self 与 other 都是 BOOL 时 out=BOOL 才能算;self 为整型、other 为整型标量时 out=BOOL 一律返回 161002。
plog 原文:
Result type DT_INT32 can't be cast to the desired output type DT_BOOL.同仓
docs/zh/context/conversion_relationship.md「互转换关系」只声明「BOOL 支持往整数、浮点、复数类型转换」,没有声明整数可转换为 BOOL。
期望
资料与实现一致:要么在 out 数据类型列注明「BOOL 仅在 self 与 other 均为 BOOL 时支持」,
要么实现允许整数结果转换为 BOOL(非零即真)。
环境
$ASCEND_HOME_PATH/aarch64-linux/lib64master,git fetch后最新提交5eaca232;910B 上该算子由 CANN 内置 ops_legacy 二进制承载复现步骤
repro.cpp存成文件(与 build.sh 同目录);bash build.sh编译;bash run.sh 0(参数是 device id);复现脚本
g++ -std=c++17 -O2 -o repro repro.cpp -I"$ASCEND_HOME_PATH/include" -I"$ASCEND_HOME_PATH/include/aclnnop" -L"$ASCEND_HOME_PATH/aarch64-linux/lib64" -lopapi_math -lopapi_nn -lopapi -lnnopbase -lascendcl -lpthread -ldl#include <cstdio> #include <cstdint> #include <cstring> #include <cstdlib> #include <vector> #include <unistd.h> #include "acl/acl.h" #include "aclnnop/aclnn_bitwise_or_scalar.h" static aclTensor* Mk(const std::vector<int64_t>& sh, aclDataType dt, void* p) { std::vector<int64_t> st(sh.size(), 1); for (int i = (int)sh.size() - 2; i >= 0; --i) st[i] = sh[i + 1] * st[i + 1]; return aclCreateTensor(sh.data(), sh.size(), dt, st.data(), 0, ACL_FORMAT_ND, sh.data(), sh.size(), p); } static void Run(const char* tag, aclDataType sdt, aclDataType odt, aclDataType scdt, int64_t other, int64_t self0) { std::vector<int64_t> sh = {1}; void* sd = nullptr; void* od = nullptr; aclrtMalloc(&sd, 8, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&od, 8, ACL_MEM_MALLOC_HUGE_FIRST); unsigned char sb[8] = {0}; memcpy(sb, &self0, 8); unsigned char ob[8] = {0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A}; aclrtMemcpy(sd, 8, sb, 8, ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(od, 8, ob, 8, ACL_MEMCPY_HOST_TO_DEVICE); aclTensor* self = Mk(sh, sdt, sd); aclTensor* out = Mk(sh, odt, od); int64_t ov = other; aclScalar* sc = aclCreateScalar(&ov, scdt); uint64_t ws = 0; aclOpExecutor* ex = nullptr; aclnnStatus r1 = aclnnBitwiseOrScalarGetWorkspaceSize(self, sc, out, &ws, &ex); printf("[%s] GetWorkspaceSize = %d\n", tag, (int)r1); int rc = (int)r1; if (r1 == ACL_SUCCESS) { void* w = nullptr; if (ws > 0) aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST); rc = (int)aclnnBitwiseOrScalar(w, ws, ex, nullptr); aclrtSynchronizeDevice(); printf("[%s] aclnnBitwiseOrScalar = %d\n", tag, rc); unsigned char rb[4] = {0}; aclrtMemcpy(rb, 4, od, 4, ACL_MEMCPY_DEVICE_TO_HOST); if (odt == ACL_INT8) { int8_t v; memcpy(&v, rb, 1); printf("[%s] out[0] = %d\n", tag, (int)v); } if (odt == ACL_INT16) { int16_t v; memcpy(&v, rb, 2); printf("[%s] out[0] = %d\n", tag, (int)v); } if (odt == ACL_UINT16) { uint16_t v; memcpy(&v, rb, 2); printf("[%s] out[0] = 0x%04x\n", tag, v); } if (ws > 0) aclrtFree(w); } printf("[%s] return code = %d\n", tag, rc); aclDestroyTensor(self); aclDestroyTensor(out); aclDestroyScalar(sc); aclrtFree(sd); aclrtFree(od); } int main(int argc, char** argv) { setvbuf(stdout, nullptr, _IONBF, 0); int dev = argc > 1 ? atoi(argv[1]) : 0; aclInit(nullptr); aclrtSetDevice(dev); Run("对照组 CTRL", ACL_BOOL, ACL_BOOL, ACL_BOOL, 1, 1); Run("缺陷组 DEFECT", ACL_INT32, ACL_BOOL, ACL_INT64, 1, 0); fflush(stdout); _exit(0); }实测输出(对照组 bool|bool 返回 0,缺陷组 int32|1 返回 161002):
影响
按资料构造「int32 输入 + BOOL 出参」的调用方必然拿到 161002,需要额外试错才能定位;
文档表格是接口支持面的唯一合同源,这一列的可信度会被拉低。
建议
在
out数据类型列的 BOOL 后补注「仅当 self 与 other 均为 BOOL 时支持」,并同步
aclnnInplaceBitwiseOrScalar小节(该接口的 selfRef 列没有 BOOL 出参问题,但表述应一致)。