Skip to content

Commit a34eab5

Browse files
authored
disable isa xcr check. (#1512) (#1513)
* disable isa xcr check.
1 parent f7bc3f5 commit a34eab5

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

csrc/cpu/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ set(IPEX_CPU_CPP_SRCS ${IPEX_CPU_CPP_DYNDISP_SRCS} ${IPEX_CPU_CPP_ISA_SRCS_GEN}
7373

7474
list(REMOVE_ITEM IPEX_CPU_CPP_SRCS ${IPEX_CPU_CPP_ISA_SRCS_ORIGIN})
7575

76+
# Disable XCR check to support Virtual Machines. Some hypervisor can't simulate XCR0 correctly.
77+
# add_definitions (-DENABLE_XCR_CHECK)
78+
7679
add_library(${PLUGIN_NAME_CPU} SHARED ${IPEX_CPU_CPP_SRCS})
7780

7881
set_target_properties(${PLUGIN_NAME_CPU} PROPERTIES ONEDNN_INCLUDE_DIR "${IPEX_CPU_CPP_THIRD_PARTY_ROOT}/ideep/mkl-dnn/include")

csrc/cpu/isa/cpu_feature.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ bool CPUFeature::os_avx() {
133133
return false;
134134
}
135135

136+
#ifdef ENABLE_XCR_CHECK
136137
uint64_t xcrFeatureMask = 0;
137138
bool ret = read_xcr(_XCR_XFEATURE_ENABLED_MASK, &xcrFeatureMask);
138139
if (!ret) {
@@ -155,11 +156,12 @@ bool CPUFeature::os_avx() {
155156
Intel® Advanced Vector Extensions (AVX state). See Section 13.5.3
156157
*/
157158
uint32_t avx_feature_bits = BIT_M_TO_N_64(xcrFeatureMask, 1, 2);
158-
if (avx_feature_bits == 0b11) {
159-
return true;
159+
if (avx_feature_bits != 0b11) {
160+
return false;
160161
}
162+
#endif
161163

162-
return false;
164+
return true;
163165
}
164166

165167
bool CPUFeature::os_avx2() {
@@ -182,6 +184,7 @@ bool CPUFeature::os_avx2() {
182184
return false;
183185
}
184186

187+
#ifdef ENABLE_XCR_CHECK
185188
uint64_t xcrFeatureMask = 0;
186189
bool ret = read_xcr(_XCR_XFEATURE_ENABLED_MASK, &xcrFeatureMask);
187190
if (!ret) {
@@ -204,14 +207,16 @@ bool CPUFeature::os_avx2() {
204207
Intel® Advanced Vector Extensions (AVX state). See Section 13.5.3
205208
*/
206209
uint32_t avx_feature_bits = BIT_M_TO_N_64(xcrFeatureMask, 1, 2);
207-
if (avx_feature_bits == 0b11) {
208-
return true;
210+
if (avx_feature_bits != 0b11) {
211+
return false;
209212
}
213+
#endif
210214

211-
return false;
215+
return true;
212216
}
213217

214218
bool CPUFeature::os_avx512() {
219+
#ifdef ENABLE_XCR_CHECK
215220
uint64_t xcrFeatureMask = 0;
216221
bool ret = read_xcr(_XCR_XFEATURE_ENABLED_MASK, &xcrFeatureMask);
217222
if (!ret) {
@@ -237,14 +242,16 @@ bool CPUFeature::os_avx512() {
237242
component 7 is used for the 16 512-bit registers ZMM16–ZMM31 (Hi16_ZMM state).
238243
*/
239244
uint32_t avx512_feature_bits = BIT_M_TO_N_64(xcrFeatureMask, 5, 7);
240-
if (avx512_feature_bits == 0b111) {
241-
return true;
245+
if (avx512_feature_bits != 0b111) {
246+
return false;
242247
}
248+
#endif
243249

244-
return false;
250+
return true;
245251
}
246252

247253
bool CPUFeature::os_amx() {
254+
#ifdef ENABLE_XCR_CHECK
248255
uint64_t xcrFeatureMask = 0;
249256
bool ret = read_xcr(_XCR_XFEATURE_ENABLED_MASK, &xcrFeatureMask);
250257
if (!ret) {
@@ -275,11 +282,12 @@ bool CPUFeature::os_amx() {
275282
tile data (XTILEDATA state).
276283
*/
277284
uint32_t avx512_feature_bits = BIT_M_TO_N_64(xcrFeatureMask, 17, 18);
278-
if (avx512_feature_bits == 0b11) {
279-
return true;
285+
if (avx512_feature_bits != 0b11) {
286+
return false;
280287
}
288+
#endif
281289

282-
return false;
290+
return true;
283291
}
284292

285293
#ifdef __linux__

tests/cpu/isa/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ set(IPEX_PROJECT_TOP_DIR "${PROJECT_SOURCE_DIR}/../../../")
1111
set(CPU_FEATURE_SRC "${IPEX_PROJECT_TOP_DIR}/csrc/cpu/isa/")
1212

1313
add_definitions (-DCPU_FEATURE_EXEC)
14+
add_definitions (-DENABLE_XCR_CHECK)
1415
add_executable (cpu_features ${CPU_FEATURE_SRC}/cpu_feature.cpp ${CPU_FEATURE_SRC}/cpu_feature_main.cpp)

0 commit comments

Comments
 (0)