未验证 提交 69ab2700 编写于 作者: A Allen Guo 提交者: GitHub

fix compiling and running with ipu (#39920)

上级 09039636
...@@ -125,6 +125,15 @@ phi::KernelKey FallBackToCpu(const OpKernelType& expected_kernel_key, ...@@ -125,6 +125,15 @@ phi::KernelKey FallBackToCpu(const OpKernelType& expected_kernel_key,
return phi::KernelKey(phi::Backend::CPU, kernel_key.layout(), return phi::KernelKey(phi::Backend::CPU, kernel_key.layout(),
kernel_key.dtype()); kernel_key.dtype());
} }
#endif
#ifdef PADDLE_WITH_IPU
if (platform::is_ipu_place(expected_kernel_key.place_)) {
VLOG(3) << "pten missing IPU kernel: " << op.Type()
<< ", expected_kernel_key:" << expected_kernel_key
<< ", fallbacking to CPU one!";
return phi::KernelKey(phi::Backend::CPU, kernel_key.layout(),
kernel_key.dtype());
}
#endif #endif
return phi::KernelKey(); return phi::KernelKey();
} }
......
...@@ -24,7 +24,8 @@ namespace paddle { ...@@ -24,7 +24,8 @@ namespace paddle {
namespace platform { namespace platform {
namespace ipu { namespace ipu {
struct IpuStrategy { class IpuStrategy {
public:
IpuStrategy(); IpuStrategy();
// TODO(alleng) create PaddleOptions // TODO(alleng) create PaddleOptions
...@@ -75,22 +76,30 @@ struct IpuStrategy { ...@@ -75,22 +76,30 @@ struct IpuStrategy {
// custom ops // custom ops
std::vector<IpuCustomOpIdentifier> custom_ops; std::vector<IpuCustomOpIdentifier> custom_ops;
private: public:
std::map<std::string, std::function<void(bool)>> bool_options; void AddBoolOption(const std::string &option, bool value);
std::map<std::string, std::function<void(std::uint64_t)>> uint64_options; void AddUint64Option(const std::string &option, std::uint64_t value);
std::map<std::string, std::function<void(double)>> double_options; void AddDoubleOption(const std::string &option, double value);
std::map<std::string, std::function<void(std::string)>> string_options; void AddStringOption(const std::string &option, const std::string &value);
std::map<std::string, void InsertStringOption(const std::string &option, const std::string &value);
std::function<void(std::pair<std::string, std::string>)>> void InsertStringPairOption(const std::string &option, const std::string &key,
container_options; const std::string &value);
void SetTensorLocation(const std::string &tensor, const std::string &option,
std::uint64_t value);
void AddCustomOp(const std::string &paddle_op, const std::string &popart_op,
const std::string &domain, int version);
std::map<std::string, std::function<std::string()>> options_getter; std::string GetOption(const std::string &);
std::map<std::string, std::function<std::vector<std::string>()>> std::vector<std::string> GetVectorOption(const std::string &);
vector_options_getter; std::map<std::string, std::string> GetMapOption(const std::string &);
std::map<std::string, std::function<std::map<std::string, std::string>()>> std::string GetOptionType(const std::string &);
map_options_getter; std::vector<std::string> GetAllOptionNames();
std::map<std::string, std::string> options_type;
void EnablePattern(const std::string &t);
void DisablePattern(const std::string &t);
const bool IsPatternEnabled(const std::string &t);
private:
template <typename ValueType> template <typename ValueType>
void set( void set(
const std::string &key, ValueType value, const std::string &key, ValueType value,
...@@ -117,27 +126,20 @@ struct IpuStrategy { ...@@ -117,27 +126,20 @@ struct IpuStrategy {
return it->second(); return it->second();
} }
public: std::map<std::string, std::function<void(bool)>> bool_options;
void AddBoolOption(const std::string &option, bool value); std::map<std::string, std::function<void(std::uint64_t)>> uint64_options;
void AddUint64Option(const std::string &option, std::uint64_t value); std::map<std::string, std::function<void(double)>> double_options;
void AddDoubleOption(const std::string &option, double value); std::map<std::string, std::function<void(std::string)>> string_options;
void AddStringOption(const std::string &option, const std::string &value); std::map<std::string,
void InsertStringOption(const std::string &option, const std::string &value); std::function<void(std::pair<std::string, std::string>)>>
void InsertStringPairOption(const std::string &option, const std::string &key, container_options;
const std::string &value);
void SetTensorLocation(const std::string &tensor, const std::string &option,
std::uint64_t value);
void AddCustomOp(const std::string &paddle_op, const std::string &popart_op,
const std::string &domain, int version);
std::string GetOption(const std::string &);
std::vector<std::string> GetVectorOption(const std::string &);
std::map<std::string, std::string> GetMapOption(const std::string &);
std::string GetOptionType(const std::string &);
void EnablePattern(const std::string &t); std::map<std::string, std::function<std::string()>> options_getter;
void DisablePattern(const std::string &t); std::map<std::string, std::function<std::vector<std::string>()>>
const bool IsPatternEnabled(const std::string &t); vector_options_getter;
std::map<std::string, std::function<std::map<std::string, std::string>()>>
map_options_getter;
std::map<std::string, std::string> options_type;
}; };
} // namespace ipu } // namespace ipu
......
...@@ -3919,6 +3919,8 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -3919,6 +3919,8 @@ All parameter, weight, gradient are variables in Paddle.
} }
return res; return res;
}) })
.def("get_all_option_names",
&platform::ipu::IpuStrategy::GetAllOptionNames)
.def("enable_pattern", &platform::ipu::IpuStrategy::EnablePattern) .def("enable_pattern", &platform::ipu::IpuStrategy::EnablePattern)
.def("disable_pattern", &platform::ipu::IpuStrategy::DisablePattern) .def("disable_pattern", &platform::ipu::IpuStrategy::DisablePattern)
.def("is_pattern_enabled", &platform::ipu::IpuStrategy::IsPatternEnabled); .def("is_pattern_enabled", &platform::ipu::IpuStrategy::IsPatternEnabled);
......
if(WITH_IPU)
file(GLOB TEST_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py")
string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}")
foreach(TEST_OP ${TEST_OPS})
py_test_modules(${TEST_OP} MODULES ${TEST_OP})
endforeach(TEST_OP)
endif()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册