Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backends/npu/kernels/conv2d_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ void Conv2dKernel(const Context& dev_ctx,
int groups,
const std::string& data_format,
phi::DenseTensor* output) {
std::once_flag npu_jit_compile_flag;
std::call_once(npu_jit_compile_flag,
UpdateBoolFlag,
"FLAGS_npu_jit_compile",
&FLAGS_npu_jit_compile);
if (FLAGS_npu_jit_compile) {
aclSetCompileopt(ACL_OP_JIT_COMPILE, "disable");
}
Expand Down Expand Up @@ -328,6 +333,11 @@ void Conv2DGradKernel(const Context& dev_ctx,
const std::string& data_format,
phi::DenseTensor* input_grad,
phi::DenseTensor* filter_grad) {
std::once_flag npu_jit_compile_flag;
std::call_once(npu_jit_compile_flag,
UpdateBoolFlag,
"FLAGS_npu_jit_compile",
&FLAGS_npu_jit_compile);
if (FLAGS_npu_jit_compile) {
aclSetCompileopt(ACL_OP_JIT_COMPILE, "disable");
}
Expand Down
1 change: 1 addition & 0 deletions backends/npu/kernels/funcs/npu_op_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ void NpuOpRunner::Run(aclrtStream stream, bool sync) const {

static std::once_flag jit_compile_flag;
std::call_once(jit_compile_flag, [&]() {
UpdateBoolFlag("FLAGS_npu_jit_compile", &FLAGS_npu_jit_compile);
if (FLAGS_npu_jit_compile) {
aclSetCompileopt(ACL_OP_JIT_COMPILE, "enable");
} else {
Expand Down
5 changes: 5 additions & 0 deletions backends/npu/kernels/pool2d_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ void AclopPool2dGradKernel(const Context& dev_ctx,
cast_out_tensor = out_tensor;
}

std::once_flag npu_jit_compile_flag;
std::call_once(npu_jit_compile_flag,
UpdateBoolFlag,
"FLAGS_npu_jit_compile",
&FLAGS_npu_jit_compile);
if (!FLAGS_npu_jit_compile) {
aclSetCompileopt(ACL_OP_JIT_COMPILE, "enable");
}
Expand Down
6 changes: 6 additions & 0 deletions backends/npu/runtime/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#ifndef BACKENDS_NPU_RUNTIME_FLAGS_H_
#define BACKENDS_NPU_RUNTIME_FLAGS_H_

#include <cstring>
#include <string>

#include "gflags/gflags.h"

#define FLAGS_DEFINE_bool(name, value, meaning) \
Expand Down Expand Up @@ -77,4 +80,7 @@
#define EnvToUInt(envname, dflt) \
(!getenv(envname) ? (dflt) : strtoul(getenv(envname), NULL, 10))

inline void UpdateBoolFlag(const std::string& envname, bool* flag) {
*flag = EnvToBool(envname.c_str(), *flag);
}
#endif // BACKENDS_NPU_RUNTIME_FLAGS_H_