diff --git a/paddle/fluid/distributed/auto_parallel/dist_attr.h b/paddle/fluid/distributed/auto_parallel/dist_attr.h index 46fb1d7f6fc5e..57eded076c207 100644 --- a/paddle/fluid/distributed/auto_parallel/dist_attr.h +++ b/paddle/fluid/distributed/auto_parallel/dist_attr.h @@ -55,13 +55,13 @@ using phi::distributed::auto_parallel::OperatorDistAttrProto; constexpr const char* kDefault = "default"; -std::vector get_tensor_shape(const VarDesc* tensor); +TEST_API std::vector get_tensor_shape(const VarDesc* tensor); class OperatorDistAttr { public: OperatorDistAttr() = default; - explicit OperatorDistAttr(const OpDesc& op); + TEST_API explicit OperatorDistAttr(const OpDesc& op); OperatorDistAttr(const OperatorDistAttr& dist_attr); @@ -90,7 +90,7 @@ class OperatorDistAttr { return output_dist_attrs_; } - void set_output_dist_attrs( + TEST_API void set_output_dist_attrs( const std::map& dist_attrs); const TensorDistAttr& input_dist_attr(const std::string& name) const { @@ -101,8 +101,8 @@ class OperatorDistAttr { return input_dist_attrs_.at(name); } - void set_input_dist_attr(const std::string& name, - const TensorDistAttr& dist_attr); + TEST_API void set_input_dist_attr(const std::string& name, + const TensorDistAttr& dist_attr); const TensorDistAttr& output_dist_attr(const std::string& name) const { return output_dist_attrs_.at(name); @@ -112,12 +112,12 @@ class OperatorDistAttr { return output_dist_attrs_.at(name); } - void set_output_dist_attr(const std::string& name, - const TensorDistAttr& dist_attr); + TEST_API void set_output_dist_attr(const std::string& name, + const TensorDistAttr& dist_attr); const ProcessMesh& process_mesh() const { return process_mesh_; } - void set_process_mesh(const ProcessMesh& process_mesh); + TEST_API void set_process_mesh(const ProcessMesh& process_mesh); const std::string& op_type() const { return op_type_; } @@ -185,9 +185,9 @@ class OperatorDistAttr { return annotated_.count(name) == 1 && annotated_.at(name) == true; } - void mark_annotated(const std::string& name); + TEST_API void mark_annotated(const std::string& name); - void clear_annotated(); + TEST_API void clear_annotated(); const std::vector& input_dims_mapping(const std::string& name) const; @@ -211,18 +211,18 @@ class OperatorDistAttr { bool verify_annotated(const std::map& annotated) const; - bool verify(const OpDesc* op = nullptr) const; + TEST_API bool verify(const OpDesc* op = nullptr) const; void rename_input(const std::string& old_name, const std::string& new_name); void rename_output(const std::string& old_name, const std::string& new_name); // OperatorDistAttr from_string(const std::string& dist_str); - std::string to_string() const; + TEST_API std::string to_string() const; - void from_proto(const OperatorDistAttrProto& proto); + TEST_API void from_proto(const OperatorDistAttrProto& proto); - OperatorDistAttrProto to_proto() const; + TEST_API OperatorDistAttrProto to_proto() const; std::string serialize_to_string(); @@ -262,7 +262,8 @@ inline std::ostream& operator<<(std::ostream& os, const OperatorDistAttr& obj) { return os; } -bool operator==(const OperatorDistAttr& lhs, const OperatorDistAttr& rhs); +TEST_API bool operator==(const OperatorDistAttr& lhs, + const OperatorDistAttr& rhs); inline bool operator!=(const OperatorDistAttr& lhs, const OperatorDistAttr& rhs) { diff --git a/paddle/phi/core/distributed/auto_parallel/device_mesh.h b/paddle/phi/core/distributed/auto_parallel/device_mesh.h index 0741e03fe94c0..cac207706e7f2 100644 --- a/paddle/phi/core/distributed/auto_parallel/device_mesh.h +++ b/paddle/phi/core/distributed/auto_parallel/device_mesh.h @@ -34,7 +34,7 @@ class DeviceCapabilityProto; class DeviceProto; class LinkCapabilityProto; class LinkProto; -class DeviceMeshProto; +class TEST_API DeviceMeshProto; struct DeviceCapability { double single_precision_flops = 0.0; @@ -77,7 +77,7 @@ class Device { } // Device from_string(const std::string& mesh_str); - std::string to_string() const; + TEST_API std::string to_string() const; static Device from_proto(const DeviceProto& proto); void to_proto(DeviceProto* proto) const; @@ -95,7 +95,7 @@ inline std::ostream& operator<<(std::ostream& os, const Device& obj) { return os; } -bool operator==(const Device& lhs, const Device& rhs); +TEST_API bool operator==(const Device& lhs, const Device& rhs); inline bool operator!=(const Device& lhs, const Device& rhs) { return !operator==(lhs, rhs); @@ -134,7 +134,7 @@ class Link { } // Link from_string(const std::string& str); - std::string to_string() const; + TEST_API std::string to_string() const; static Link from_proto(const LinkProto& proto); void to_proto(LinkProto* proto) const; @@ -151,7 +151,7 @@ inline std::ostream& operator<<(std::ostream& os, const Link& obj) { return os; } -bool operator==(const Link& lhs, const Link& rhs); +TEST_API bool operator==(const Link& lhs, const Link& rhs); inline bool operator!=(const Link& lhs, const Link& rhs) { return !operator==(lhs, rhs); @@ -203,10 +203,10 @@ class DeviceMesh { public: DeviceMesh() = default; - DeviceMesh(const std::string& name, - const std::vector& shape, - const std::vector& device_ids, - const std::vector& dim_names); + TEST_API DeviceMesh(const std::string& name, + const std::vector& shape, + const std::vector& device_ids, + const std::vector& dim_names); const std::string& name() const { return name_; } @@ -251,7 +251,7 @@ class DeviceMesh { return machines_.at(machine_id); } - int64_t size() const; + TEST_API int64_t size() const; int64_t ndim() const { return shape_.size(); } int64_t dim_size(int64_t dim) const { @@ -270,15 +270,15 @@ class DeviceMesh { } bool empty() const { return (shape_.empty() || device_ids_.empty()); } - bool contains(int64_t device_id) const; + TEST_API bool contains(int64_t device_id) const; - void add_device(const Device& device); - void add_link(const Link& link); + TEST_API void add_device(const Device& device); + TEST_API void add_link(const Link& link); // DeviceMesh from_string(const std::string& mesh_str); - std::string to_string() const; + TEST_API std::string to_string() const; - static DeviceMesh from_proto(const DeviceMeshProto& proto); + TEST_API static DeviceMesh from_proto(const DeviceMeshProto& proto); void to_proto(DeviceMeshProto* proto) const; private: @@ -296,7 +296,7 @@ inline std::ostream& operator<<(std::ostream& os, const DeviceMesh& obj) { return os; } -bool operator==(const DeviceMesh& lhs, const DeviceMesh& rhs); +TEST_API bool operator==(const DeviceMesh& lhs, const DeviceMesh& rhs); inline bool operator!=(const DeviceMesh& lhs, const DeviceMesh& rhs) { return !operator==(lhs, rhs); diff --git a/paddle/phi/core/distributed/auto_parallel/dist_attr.h b/paddle/phi/core/distributed/auto_parallel/dist_attr.h index e4016b9f65cdc..ee1dda120fca2 100644 --- a/paddle/phi/core/distributed/auto_parallel/dist_attr.h +++ b/paddle/phi/core/distributed/auto_parallel/dist_attr.h @@ -33,7 +33,7 @@ namespace phi { namespace distributed { namespace auto_parallel { -class TensorDistAttrProto; +class TEST_API TensorDistAttrProto; } constexpr int kReplicateDim = -1; @@ -216,7 +216,7 @@ inline std::ostream& operator<<(std::ostream& os, const TensorDistAttr& obj) { return os; } -bool operator==(const TensorDistAttr& lhs, const TensorDistAttr& rhs); +TEST_API bool operator==(const TensorDistAttr& lhs, const TensorDistAttr& rhs); inline bool operator!=(const TensorDistAttr& lhs, const TensorDistAttr& rhs) { return !operator==(lhs, rhs); diff --git a/paddle/phi/core/distributed/auto_parallel/process_mesh.h b/paddle/phi/core/distributed/auto_parallel/process_mesh.h index 9501118380c86..6113b615a4223 100644 --- a/paddle/phi/core/distributed/auto_parallel/process_mesh.h +++ b/paddle/phi/core/distributed/auto_parallel/process_mesh.h @@ -28,16 +28,16 @@ namespace phi { namespace distributed { namespace auto_parallel { -class ProcessMeshProto; +class TEST_API ProcessMeshProto; } class ProcessMesh { public: ProcessMesh() = default; - ProcessMesh(const std::vector& shape, - const std::vector& process_ids, - const std::vector& dim_names); + TEST_API ProcessMesh(const std::vector& shape, + const std::vector& process_ids, + const std::vector& dim_names); const std::vector& shape() const { return shape_; } @@ -45,7 +45,7 @@ class ProcessMesh { const std::vector& dim_names() const { return dim_names_; } - int64_t size() const; + TEST_API int64_t size() const; int64_t ndim() const { return shape_.size(); } @@ -65,14 +65,15 @@ class ProcessMesh { } bool empty() const { return (shape_.empty() || process_ids_.empty()); } - bool contains(int64_t process_id) const; + TEST_API bool contains(int64_t process_id) const; size_t hash() const { return std::hash{}(to_string()); } // ProcessMesh from_string(const std::string& mesh_str); - std::string to_string() const; + TEST_API std::string to_string() const; - static ProcessMesh from_proto(const auto_parallel::ProcessMeshProto& proto); + TEST_API static ProcessMesh from_proto( + const auto_parallel::ProcessMeshProto& proto); void to_proto(auto_parallel::ProcessMeshProto* proto) const; private: @@ -86,7 +87,7 @@ inline std::ostream& operator<<(std::ostream& os, const ProcessMesh& obj) { return os; } -bool operator==(const ProcessMesh& lhs, const ProcessMesh& rhs); +TEST_API bool operator==(const ProcessMesh& lhs, const ProcessMesh& rhs); inline bool operator!=(const ProcessMesh& lhs, const ProcessMesh& rhs) { return !operator==(lhs, rhs); diff --git a/paddle/phi/core/distributed/auto_parallel/proto_helper.h b/paddle/phi/core/distributed/auto_parallel/proto_helper.h index 66bdf2af74406..3bfd7d3d63234 100644 --- a/paddle/phi/core/distributed/auto_parallel/proto_helper.h +++ b/paddle/phi/core/distributed/auto_parallel/proto_helper.h @@ -14,6 +14,7 @@ #pragma once #include "paddle/phi/core/distributed/auto_parallel/auto_parallel.pb.h" +#include "paddle/utils/test_macros.h" namespace phi { namespace distributed { class TensorDistAttr; @@ -26,8 +27,9 @@ class Link; class DeviceMesh; class DistributedMapper; } // namespace auto_parallel -auto_parallel::TensorDistAttrProto to_proto(const TensorDistAttr& dist_attr); -auto_parallel::ProcessMeshProto to_proto(const ProcessMesh& dist_attr); +TEST_API auto_parallel::TensorDistAttrProto to_proto( + const TensorDistAttr& dist_attr); +TEST_API auto_parallel::ProcessMeshProto to_proto(const ProcessMesh& dist_attr); auto_parallel::DeviceCapabilityProto to_proto( const auto_parallel::DeviceCapability& device_capibilty); diff --git a/test/cpp/auto_parallel/CMakeLists.txt b/test/cpp/auto_parallel/CMakeLists.txt index e48b634d68db2..b38e324c5f0db 100644 --- a/test/cpp/auto_parallel/CMakeLists.txt +++ b/test/cpp/auto_parallel/CMakeLists.txt @@ -1,19 +1,13 @@ -cc_test(device_mesh_test SRCS device_mesh_test.cc) +paddle_test(device_mesh_test SRCS device_mesh_test.cc) -cc_test(process_mesh_test SRCS process_mesh_test.cc) +paddle_test(process_mesh_test SRCS process_mesh_test.cc) -cc_test( - dist_attr_test - SRCS dist_attr_test.cc - DEPS proto_desc) +paddle_test(dist_attr_test SRCS dist_attr_test.cc) if(WITH_DISTRIBUTE) cc_library(spmd_rule_test_util SRCS spmd_rule_test_util.cc) add_dependencies(spmd_rule_test_util spmd_rules) - cc_test( - dist_tensor_test - SRCS dist_tensor_test.cc - DEPS phi common) + paddle_test(dist_tensor_test SRCS dist_tensor_test.cc DEPS common) paddle_test(spmd_rule_test SRCS spmd_rule_test.cc DEPS spmd_rule_test_util spmd_rules)