Skip to content

Commit be6be16

Browse files
authored
[Python API] Use env var to auto call itex ops override (#1953)
1 parent 2ac386d commit be6be16

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

itex/core/kernels/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ itex_xpu_library(
99
":libitex_common",
1010
"//itex/core/devices:device_backend_util_hdr",
1111
"//itex/core/kernels/common:no_ops",
12+
"@local_config_python//:python_headers",
1213
"@local_config_tf//:tf_header_lib",
1314
] + select({
1415
"@local_config_dpcpp//dpcpp:using_dpcpp": [

itex/core/kernels/xpu_kernel.cc

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515

1616
#include <string>
1717

18+
#include "Python.h"
1819
#include "itex/core/devices/device_backend_util.h"
1920
#include "itex/core/devices/xpu_device_util.h"
2021
#include "itex/core/kernels/common.h"
@@ -52,4 +53,11 @@ void TF_InitKernel() {
5253
// Register generic CPU kernels.
5354
RegisterCPUKernels(itex::DEVICE_CPU);
5455
#endif
56+
bool ops_override = false;
57+
ITEX_CHECK_OK(
58+
itex::ReadBoolFromEnvVar("ITEX_OPS_OVERRIDE", false, &ops_override));
59+
if (ops_override) {
60+
PyRun_SimpleString("import intel_extension_for_tensorflow as itex;\n");
61+
PyRun_SimpleString("itex.experimental_ops_override();\n");
62+
}
5563
}

0 commit comments

Comments
 (0)