Skip to content

Commit 0148a3d

Browse files
[NPU] fix conv2d question & ut. (#1339)
1 parent 83e8fdd commit 0148a3d

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

backends/npu/kernels/conv2d_kernel.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "acl/acl_op_compiler.h"
1516
#include "kernels/funcs/conv_util.h"
1617
#include "kernels/funcs/npu_funcs.h"
1718
#include "kernels/funcs/npu_op_runner.h"
@@ -95,6 +96,10 @@ void Conv2dKernel(const Context& dev_ctx,
9596
int groups,
9697
const std::string& data_format,
9798
phi::DenseTensor* output) {
99+
if (FLAGS_npu_jit_compile) {
100+
aclSetCompileopt(ACL_OP_JIT_COMPILE, "disable");
101+
}
102+
98103
auto strides = strides_t;
99104
auto paddings = paddings_t;
100105
auto dilations = dilations_t;
@@ -217,6 +222,10 @@ void Conv2dKernel(const Context& dev_ctx,
217222
groups_,
218223
output_tensor,
219224
cubeMathType);
225+
226+
if (FLAGS_npu_jit_compile) {
227+
aclSetCompileopt(ACL_OP_JIT_COMPILE, "enable");
228+
}
220229
}
221230

222231
template <typename T, typename Context>
@@ -319,6 +328,10 @@ void Conv2DGradKernel(const Context& dev_ctx,
319328
const std::string& data_format,
320329
phi::DenseTensor* input_grad,
321330
phi::DenseTensor* filter_grad) {
331+
if (FLAGS_npu_jit_compile) {
332+
aclSetCompileopt(ACL_OP_JIT_COMPILE, "disable");
333+
}
334+
322335
auto strides = strides_t;
323336
auto paddings = paddings_t;
324337
auto dilations = dilations_t;
@@ -417,6 +430,10 @@ void Conv2DGradKernel(const Context& dev_ctx,
417430
if (filter_grad) {
418431
dev_ctx.template Alloc<T>(filter_grad);
419432
filter_grad_tensor = phi::DenseTensor(*filter_grad);
433+
} else {
434+
phi::DenseTensorMeta filter_grad_meta = {input.dtype(), input.dims()};
435+
filter_grad_tensor.set_meta(filter_grad_meta);
436+
dev_ctx.template Alloc<T>(&filter_grad_tensor);
420437
}
421438

422439
if (input_grad) {
@@ -462,6 +479,10 @@ void Conv2DGradKernel(const Context& dev_ctx,
462479
input_grad_tensor,
463480
filter_grad_tensor,
464481
bias_grad_tensor);
482+
483+
if (FLAGS_npu_jit_compile) {
484+
aclSetCompileopt(ACL_OP_JIT_COMPILE, "enable");
485+
}
465486
}
466487

467488
} // namespace custom_kernel

backends/npu/kernels/conv_kernel.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ void DepthwiseConv2dGradKernel(const Context& dev_ctx,
415415
if (filter_grad) {
416416
dev_ctx.template Alloc<T>(filter_grad);
417417
filter_grad_tensor = phi::DenseTensor(*filter_grad);
418+
} else {
419+
phi::DenseTensorMeta filter_grad_meta = {input.dtype(), input.dims()};
420+
filter_grad_tensor.set_meta(filter_grad_meta);
421+
dev_ctx.template Alloc<T>(&filter_grad_tensor);
418422
}
419423

420424
if (input_grad) {

backends/npu/kernels/funcs/npu_op_prepare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DECLARE_bool(npu_storage_format);
2929
DECLARE_bool(npu_scale_aclnn);
3030
DECLARE_bool(npu_split_aclnn);
31+
DECLARE_bool(npu_jit_compile);
3132

3233
namespace custom_kernel {
3334

backends/npu/tools/disable_ut_npu_910b

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
disable_ut_npu
22
test_batch_norm_op_npu
33
test_check_nan_inf_op_npu
4-
test_conv2d_op_npu
54
test_conv3d_op_npu
65
test_contiguous_op_npu
76
test_einsum_op_npu

0 commit comments

Comments
 (0)