Skip to content

Commit 1f09bc3

Browse files
authored
Support data type int8_t . (#12841)
* Support int8 type.
1 parent 3e1050a commit 1f09bc3

File tree

12 files changed

+43
-8
lines changed

12 files changed

+43
-8
lines changed

paddle/fluid/API.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ paddle.fluid.LoDTensor.__init__ 1. __init__(self: paddle.fluid.core.LoDTensor, a
378378
paddle.fluid.LoDTensor.has_valid_recursive_sequence_lengths has_valid_recursive_sequence_lengths(self: paddle.fluid.core.LoDTensor) -> bool
379379
paddle.fluid.LoDTensor.lod lod(self: paddle.fluid.core.LoDTensor) -> List[List[int]]
380380
paddle.fluid.LoDTensor.recursive_sequence_lengths recursive_sequence_lengths(self: paddle.fluid.core.LoDTensor) -> List[List[int]]
381-
paddle.fluid.LoDTensor.set 1. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float32], arg1: paddle::platform::CPUPlace) -> None 2. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int32], arg1: paddle::platform::CPUPlace) -> None 3. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float64], arg1: paddle::platform::CPUPlace) -> None 4. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int64], arg1: paddle::platform::CPUPlace) -> None 5. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[bool], arg1: paddle::platform::CPUPlace) -> None 6. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint16], arg1: paddle::platform::CPUPlace) -> None 7. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint8], arg1: paddle::platform::CPUPlace) -> None 8. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float32], arg1: paddle::platform::CUDAPlace) -> None 9. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int32], arg1: paddle::platform::CUDAPlace) -> None 10. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float64], arg1: paddle::platform::CUDAPlace) -> None 11. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int64], arg1: paddle::platform::CUDAPlace) -> None 12. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[bool], arg1: paddle::platform::CUDAPlace) -> None 13. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint16], arg1: paddle::platform::CUDAPlace) -> None 14. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint8], arg1: paddle::platform::CUDAPlace) -> None 15. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float32], arg1: paddle::platform::CUDAPinnedPlace) -> None 16. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int32], arg1: paddle::platform::CUDAPinnedPlace) -> None 17. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float64], arg1: paddle::platform::CUDAPinnedPlace) -> None 18. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int64], arg1: paddle::platform::CUDAPinnedPlace) -> None 19. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[bool], arg1: paddle::platform::CUDAPinnedPlace) -> None 20. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint16], arg1: paddle::platform::CUDAPinnedPlace) -> None 21. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint8], arg1: paddle::platform::CUDAPinnedPlace) -> None
381+
paddle.fluid.LoDTensor.set 1. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float32], arg1: paddle::platform::CPUPlace) -> None 2. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int32], arg1: paddle::platform::CPUPlace) -> None 3. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float64], arg1: paddle::platform::CPUPlace) -> None 4. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int64], arg1: paddle::platform::CPUPlace) -> None 5. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[bool], arg1: paddle::platform::CPUPlace) -> None 6. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint16], arg1: paddle::platform::CPUPlace) -> None 7. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint8], arg1: paddle::platform::CPUPlace) -> None 8. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int8], arg1: paddle::platform::CPUPlace) -> None 9. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float32], arg1: paddle::platform::CUDAPlace) -> None 10. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int32], arg1: paddle::platform::CUDAPlace) -> None 11. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float64], arg1: paddle::platform::CUDAPlace) -> None 12. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int64], arg1: paddle::platform::CUDAPlace) -> None 13. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[bool], arg1: paddle::platform::CUDAPlace) -> None 14. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint16], arg1: paddle::platform::CUDAPlace) -> None 15. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint8], arg1: paddle::platform::CUDAPlace) -> None 16. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int8], arg1: paddle::platform::CUDAPlace) -> None 17. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float32], arg1: paddle::platform::CUDAPinnedPlace) -> None 18. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int32], arg1: paddle::platform::CUDAPinnedPlace) -> None 19. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[float64], arg1: paddle::platform::CUDAPinnedPlace) -> None 20. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int64], arg1: paddle::platform::CUDAPinnedPlace) -> None 21. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[bool], arg1: paddle::platform::CUDAPinnedPlace) -> None 22. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint16], arg1: paddle::platform::CUDAPinnedPlace) -> None 23. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[uint8], arg1: paddle::platform::CUDAPinnedPlace) -> None 24. set(self: paddle.fluid.core.Tensor, arg0: numpy.ndarray[int8], arg1: paddle::platform::CUDAPinnedPlace) -> None
382382
paddle.fluid.LoDTensor.set_lod set_lod(self: paddle.fluid.core.LoDTensor, arg0: List[List[int]]) -> None
383383
paddle.fluid.LoDTensor.set_recursive_sequence_lengths set_recursive_sequence_lengths(self: paddle.fluid.core.LoDTensor, arg0: List[List[int]]) -> None
384384
paddle.fluid.LoDTensor.shape shape(self: paddle.fluid.core.Tensor) -> List[int]

paddle/fluid/framework/data_type.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static DataTypeMap* InitDataTypeMap() {
6464
RegType(size_t, proto::VarType::SIZE_T);
6565
RegType(int16_t, proto::VarType::INT16);
6666
RegType(uint8_t, proto::VarType::UINT8);
67+
RegType(int8_t, proto::VarType::INT8);
6768

6869
#undef RegType
6970
return retv;

paddle/fluid/framework/data_type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
5454
case proto::VarType::INT16:
5555
visitor.template operator()<int16_t>();
5656
break;
57+
case proto::VarType::INT8:
58+
visitor.template operator()<int8_t>();
59+
break;
5760
default:
5861
PADDLE_THROW("Not supported %d", type);
5962
}

paddle/fluid/framework/framework.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ message VarType {
107107
// Tensor<size_t> is used in C++.
108108
SIZE_T = 19;
109109
UINT8 = 20;
110+
INT8 = 21;
110111

111112
// Other types that may need additional descriptions
112113
LOD_TENSOR = 7;

paddle/fluid/operators/math/math_function.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ template struct SetConstant<platform::CPUDeviceContext, uint8_t>;
4141
template struct Transpose<platform::CPUDeviceContext, int64_t, RANK>; \
4242
template struct Transpose<platform::CPUDeviceContext, bool, RANK>; \
4343
template struct Transpose<platform::CPUDeviceContext, int16_t, RANK>; \
44-
template struct Transpose<platform::CPUDeviceContext, uint8_t, RANK>;
44+
template struct Transpose<platform::CPUDeviceContext, uint8_t, RANK>; \
45+
template struct Transpose<platform::CPUDeviceContext, int8_t, RANK>;
4546

4647
DEFINE_CPU_TRANS(1);
4748
DEFINE_CPU_TRANS(2);

paddle/fluid/operators/math/math_function.cu

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ template struct SetConstant<platform::CUDADeviceContext, int>;
3333
template struct SetConstant<platform::CUDADeviceContext, int64_t>;
3434
template struct SetConstant<platform::CUDADeviceContext, bool>;
3535

36-
#define DEFINE_GPU_TRANS(RANK) \
37-
template struct Transpose<platform::CUDADeviceContext, float, RANK>; \
38-
template struct Transpose<platform::CUDADeviceContext, double, RANK>; \
39-
template struct Transpose<platform::CUDADeviceContext, float16, RANK>;
36+
#define DEFINE_GPU_TRANS(RANK) \
37+
template struct Transpose<platform::CUDADeviceContext, float, RANK>; \
38+
template struct Transpose<platform::CUDADeviceContext, double, RANK>; \
39+
template struct Transpose<platform::CUDADeviceContext, float16, RANK>; \
40+
template struct Transpose<platform::CUDADeviceContext, int8_t, RANK>;
4041

4142
DEFINE_GPU_TRANS(1);
4243
DEFINE_GPU_TRANS(2);

paddle/fluid/pybind/protobuf.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ void BindVarDsec(pybind11::module *m) {
234234
pybind11::enum_<pd::proto::VarType::Type>(var_desc, "VarType", "")
235235
.value("BOOL", pd::proto::VarType::BOOL)
236236
.value("UINT8", pd::proto::VarType::UINT8)
237+
.value("INT8", pd::proto::VarType::INT8)
237238
.value("INT16", pd::proto::VarType::INT16)
238239
.value("INT32", pd::proto::VarType::INT32)
239240
.value("INT64", pd::proto::VarType::INT64)

paddle/fluid/pybind/pybind.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ PYBIND11_PLUGIN(core) {
130130
.def("set", PyCPUTensorSetFromArray<bool>)
131131
.def("set", PyCPUTensorSetFromArray<uint16_t>)
132132
.def("set", PyCPUTensorSetFromArray<uint8_t>)
133+
.def("set", PyCPUTensorSetFromArray<int8_t>)
133134
#ifdef PADDLE_WITH_CUDA
134135
.def("set", PyCUDATensorSetFromArray<float>)
135136
.def("set", PyCUDATensorSetFromArray<int>)
@@ -138,13 +139,15 @@ PYBIND11_PLUGIN(core) {
138139
.def("set", PyCUDATensorSetFromArray<bool>)
139140
.def("set", PyCUDATensorSetFromArray<uint16_t>)
140141
.def("set", PyCUDATensorSetFromArray<uint8_t>)
142+
.def("set", PyCUDATensorSetFromArray<int8_t>)
141143
.def("set", PyCUDAPinnedTensorSetFromArray<float>)
142144
.def("set", PyCUDAPinnedTensorSetFromArray<int>)
143145
.def("set", PyCUDAPinnedTensorSetFromArray<double>)
144146
.def("set", PyCUDAPinnedTensorSetFromArray<int64_t>)
145147
.def("set", PyCUDAPinnedTensorSetFromArray<bool>)
146148
.def("set", PyCUDAPinnedTensorSetFromArray<uint16_t>)
147149
.def("set", PyCUDAPinnedTensorSetFromArray<uint8_t>)
150+
.def("set", PyCUDAPinnedTensorSetFromArray<int8_t>)
148151
#endif
149152
.def("shape", [](Tensor &self) { return vectorize(self.dims()); })
150153
.def("_set_float_element", TensorSetElement<float>)

paddle/fluid/pybind/tensor_py.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct CastToPyBufferImpl<true, I, ARGS...> {
9797
inline pybind11::buffer_info CastToPyBuffer(const framework::Tensor &tensor) {
9898
auto buffer_info =
9999
details::CastToPyBufferImpl<true, 0, float, int, double, int64_t, bool,
100-
uint8_t, platform::float16>()(tensor);
100+
uint8_t, int8_t, platform::float16>()(tensor);
101101
return buffer_info;
102102
}
103103

python/paddle/fluid/framework.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def convert_np_dtype_to_dtype_(np_dtype):
9595
return core.VarDesc.VarType.INT16
9696
elif dtype == np.uint8:
9797
return core.VarDesc.VarType.UINT8
98+
elif dtype == np.int8:
99+
return core.VarDesc.VarType.INT8
98100
else:
99101
raise ValueError("Not supported numpy dtype %s" % dtype)
100102

0 commit comments

Comments
 (0)