Skip to content

Commit c790d57

Browse files
authored
data_type (#12933)
* data_type * "remove tabs"
1 parent d0b7134 commit c790d57

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

paddle/fluid/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ add_subdirectory(memory)
22
add_subdirectory(platform)
33
add_subdirectory(framework)
44
add_subdirectory(operators)
5-
add_subdirectory(pybind)
65
add_subdirectory(string)
6+
7+
if (NOT WIN32)
8+
add_subdirectory(pybind)
79
add_subdirectory(recordio)
10+
endif(NOT WIN32)
11+
812
if(WITH_INFERENCE)
913
# NOTE: please add subdirectory inference at last.
1014
add_subdirectory(inference)

paddle/fluid/framework/CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
add_subdirectory(details)
21
add_subdirectory(ir)
2+
if (NOT WIN32)
3+
add_subdirectory(details)
4+
endif (NOT WIN32)
35
# ddim lib
46
proto_library(framework_proto SRCS framework.proto)
57

@@ -28,8 +30,12 @@ if(WITH_GPU)
2830
else()
2931
cc_test(mixed_vector_test SRCS mixed_vector_test.cc DEPS place memory device_context tensor)
3032
endif()
31-
33+
if (NOT WIN32)
3234
cc_library(lod_tensor SRCS lod_tensor.cc DEPS ddim place tensor framework_proto recordio)
35+
else()
36+
cc_library(lod_tensor SRCS lod_tensor.cc DEPS ddim place tensor framework_proto)
37+
endif (NOT WIN32)
38+
3339
cc_test(lod_tensor_test SRCS lod_tensor_test.cc DEPS lod_tensor memory)
3440
nv_test(lod_tensor_gpu_test SRCS lod_tensor_test.cu DEPS lod_tensor)
3541

@@ -69,14 +75,22 @@ cc_library(op_proto_maker SRCS op_proto_maker.cc DEPS framework_proto attribute
6975
cc_test(op_proto_maker_test SRCS op_proto_maker_test.cc DEPS op_proto_maker)
7076
cc_library(op_info SRCS op_info.cc DEPS attribute framework_proto)
7177
cc_library(shape_inference SRCS shape_inference.cc DEPS ddim attribute device_context)
78+
79+
if (NOT WIN32)
7280
cc_library(operator SRCS operator.cc DEPS op_info device_context tensor scope glog
7381
shape_inference data_transform lod_tensor profiler)
82+
else()
83+
cc_library(operator SRCS operator.cc DEPS op_info device_context tensor scope glog
84+
shape_inference data_transform lod_tensor)
85+
endif(NOT WIN32)
86+
7487
cc_test(operator_test SRCS operator_test.cc DEPS operator op_registry device_context)
7588
cc_library(proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc DEPS shape_inference op_info operator glog)
7689

7790
cc_library(op_registry SRCS op_registry.cc DEPS op_proto_maker op_info operator glog proto_desc)
7891
nv_test(op_registry_test SRCS op_registry_test.cc DEPS op_registry)
7992

93+
if (NOT WIN32)
8094
py_proto_compile(framework_py_proto SRCS framework.proto)
8195
# Generate an empty __init__.py to make framework_py_proto as a valid python module.
8296
add_custom_target(framework_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch __init__.py)
@@ -86,6 +100,7 @@ add_custom_command(TARGET framework_py_proto POST_BUILD
86100
COMMAND cp *.py ${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/
87101
COMMENT "Copy generated python proto into directory paddle/fluid/proto."
88102
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
103+
endif(NOT WIN32)
89104

90105
cc_library(lod_rank_table SRCS lod_rank_table.cc DEPS lod_tensor)
91106

@@ -120,7 +135,9 @@ cc_test(cow_ptr_tests SRCS details/cow_ptr_test.cc)
120135
# cc_test(channel_test SRCS channel_test.cc)
121136
cc_test(tuple_test SRCS tuple_test.cc )
122137

138+
if (NOT WIN32)
123139
cc_test(rw_lock_test SRCS rw_lock_test.cc)
140+
endif (NOT WIN32)
124141

125142
# disable test temporarily.
126143
# TODO https://github.com/PaddlePaddle/Paddle/issues/11971

paddle/fluid/framework/data_type.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace framework {
2626
extern proto::VarType::Type ToDataType(std::type_index type);
2727
extern std::type_index ToTypeIndex(proto::VarType::Type type);
2828

29+
#if !defined(_WIN32)
2930
template <typename Visitor>
3031
inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
3132
switch (type) {
@@ -57,6 +58,40 @@ inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
5758
PADDLE_THROW("Not supported %d", type);
5859
}
5960
}
61+
#else
62+
// the msvc compiler do not implement two-stage name lookup correctly.
63+
template <typename Visitor>
64+
inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
65+
switch (type) {
66+
case proto::VarType::FP16:
67+
visitor.operator()<platform::float16>();
68+
break;
69+
case proto::VarType::FP32:
70+
visitor.operator()<float>();
71+
break;
72+
case proto::VarType::FP64:
73+
visitor.operator()<double>();
74+
break;
75+
case proto::VarType::INT32:
76+
visitor.operator()<int>();
77+
break;
78+
case proto::VarType::INT64:
79+
visitor.operator()<int64_t>();
80+
break;
81+
case proto::VarType::BOOL:
82+
visitor.operator()<bool>();
83+
break;
84+
case proto::VarType::UINT8:
85+
visitor.operator()<uint8_t>();
86+
break;
87+
case proto::VarType::INT16:
88+
visitor.operator()<int16_t>();
89+
break;
90+
default:
91+
PADDLE_THROW("Not supported %d", type);
92+
}
93+
}
94+
#endif // _WIN32
6095

6196
extern std::string DataTypeToString(const proto::VarType::Type type);
6297
extern size_t SizeOfType(std::type_index type);

0 commit comments

Comments
 (0)