Skip to content

Commit 7906c18

Browse files
mcr229facebook-github-bot
authored andcommitted
Cast long inputs to float32 before feeding to xnnpack graph runtime (#553)
Summary: Pull Request resolved: #553 In DeepLab v3, we saw that some inputs are int64, (this is largely from interpolation decomposition). XNNPACK can not handle int64, which means that the int64 inputs would wrongly be interpreted as float32. In order to correctly feed the right inputs to XNNPACK, we must cast the int64 data to float32. We do something similar when casting int32 data to int64 when we are returning indicies from argmax pooling. Reviewed By: digantdesai Differential Revision: D49797819 fbshipit-source-id: 1f4f6ab38c4c8e36ba0a7017300f5e3a3ccbf810
1 parent 83af3a4 commit 7906c18

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

backends/xnnpack/runtime/XNNExecutor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) {
6868
return Error::NotSupported;
6969
#endif
7070
} else {
71+
// TODO(T165403530): Test insure accuracy for int64 --> float32 conversion
72+
if (input->scalar_type() == ScalarType::Long) {
73+
// Input data type is int64. However, XNNPACK doesn't support
74+
// int64. This means that the data needs to be casted to float
75+
// In order for XNNPACK to properly use it.
76+
const int64_t* data_64 = input->const_data_ptr<int64_t>();
77+
float* data_f32 = input->mutable_data_ptr<float>();
78+
for (int j = 0; j < input->numel(); j++) {
79+
data_f32[j] = data_64[j];
80+
}
81+
}
7182
externals_.emplace_back(xnn_external_value{id, input->mutable_data_ptr()});
7283
}
7384
return Error::Ok;

0 commit comments

Comments
 (0)