华为计算微信公众号
昇腾AI开发者公众号
华为计算微博
华为计算今日头条
我目前在写了自定义算子工程,通过测试在二维数据(如[8, 1024])的情况下数据都是正常的,输出结果也正确。
但是当我测试四维数据的时候如[3, 4, 224, 224]时会出现 [ERROR] Execute Operator failed. error code is 361001
我是参考官方文档中的动态tiling策略实现的想问下这块可能的原因,以及针对四维数据需要怎么进行tiling策略
GeluTilingData tiling; uint32_t totalLength = context->GetInputTensor(0)->GetShapeSize(); // 设置数据类型 auto dataType = context->GetInputTensor(0)->GetDataType(); uint32_t sizeofDataType = 0; if (dataType == 0) { std::cout << "Input Tensor DataType: Float32" << std::endl; sizeofDataType = 4; } else { std::cout << "Input Tensor DataType: Float16" << std::endl; sizeofDataType = 2; } uint32_t ALIGN_NUM = BLOCK_SIZE / sizeofDataType; uint32_t totalLengthAligned = 0; // 输入向量是否满足32字节对齐 if (totalLength % ALIGN_NUM != 0) { std::cout << "totalLength = " << totalLength << " is not 32 bytes aligned! " << std::endl; // 使输入向上对齐 totalLengthAligned = ((totalLength + ALIGN_NUM - 1) / ALIGN_NUM) * ALIGN_NUM; std::cout << "After aligned, totalLengthAligned = " << totalLengthAligned << std::endl; } else { std::cout << "totalLength = " << totalLength << " is 32 bytes aligned! " << std::endl; totalLengthAligned = totalLength; } // 计算整块和尾块个数 uint32_t formerNum = (totalLengthAligned / ALIGN_NUM) % BLOCK_DIM; uint32_t tailNum = BLOCK_DIM - formerNum; // 计算整块和尾块的元素个数 uint32_t formerLength = ((totalLengthAligned / BLOCK_DIM + ALIGN_NUM - 1) / ALIGN_NUM) * ALIGN_NUM; uint32_t tailLength = (totalLengthAligned / BLOCK_DIM / ALIGN_NUM) * ALIGN_NUM; // 设置tiling参数 tiling.set_formerNum(formerNum); tiling.set_tailNum(tailNum); tiling.set_formerLength(formerLength); tiling.set_tailLength(tailLength); tiling.set_alignNum(ALIGN_NUM);
我要发帖子
我目前在写了自定义算子工程,通过测试在二维数据(如[8, 1024])的情况下数据都是正常的,输出结果也正确。
但是当我测试四维数据的时候如[3, 4, 224, 224]时会出现 [ERROR] Execute Operator failed. error code is 361001
我是参考官方文档中的动态tiling策略实现的想问下这块可能的原因,以及针对四维数据需要怎么进行tiling策略
GeluTilingData tiling; uint32_t totalLength = context->GetInputTensor(0)->GetShapeSize(); // 设置数据类型 auto dataType = context->GetInputTensor(0)->GetDataType(); uint32_t sizeofDataType = 0; if (dataType == 0) { std::cout << "Input Tensor DataType: Float32" << std::endl; sizeofDataType = 4; } else { std::cout << "Input Tensor DataType: Float16" << std::endl; sizeofDataType = 2; } uint32_t ALIGN_NUM = BLOCK_SIZE / sizeofDataType; uint32_t totalLengthAligned = 0; // 输入向量是否满足32字节对齐 if (totalLength % ALIGN_NUM != 0) { std::cout << "totalLength = " << totalLength << " is not 32 bytes aligned! " << std::endl; // 使输入向上对齐 totalLengthAligned = ((totalLength + ALIGN_NUM - 1) / ALIGN_NUM) * ALIGN_NUM; std::cout << "After aligned, totalLengthAligned = " << totalLengthAligned << std::endl; } else { std::cout << "totalLength = " << totalLength << " is 32 bytes aligned! " << std::endl; totalLengthAligned = totalLength; } // 计算整块和尾块个数 uint32_t formerNum = (totalLengthAligned / ALIGN_NUM) % BLOCK_DIM; uint32_t tailNum = BLOCK_DIM - formerNum; // 计算整块和尾块的元素个数 uint32_t formerLength = ((totalLengthAligned / BLOCK_DIM + ALIGN_NUM - 1) / ALIGN_NUM) * ALIGN_NUM; uint32_t tailLength = (totalLengthAligned / BLOCK_DIM / ALIGN_NUM) * ALIGN_NUM; // 设置tiling参数 tiling.set_formerNum(formerNum); tiling.set_tailNum(tailNum); tiling.set_formerLength(formerLength); tiling.set_tailLength(tailLength); tiling.set_alignNum(ALIGN_NUM);