Commit cf86db72 authored by Paul's avatar Paul
Browse files

Merge branch 'master' into fp16

parents af454aeb 414e2fac
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
#define MIGRAPH_GUARD_MIGRAPHLIB_HIP_HPP #define MIGRAPH_GUARD_MIGRAPHLIB_HIP_HPP
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/config.hpp>
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
migraph::argument allocate_gpu(const migraph::shape& s, bool host = false); migraph::argument allocate_gpu(const migraph::shape& s, bool host = false);
...@@ -67,6 +69,7 @@ struct hip_write ...@@ -67,6 +69,7 @@ struct hip_write
{ {
return to_gpu(args.front()); return to_gpu(args.front());
} }
int output_alias(const std::vector<shape>&) const { return 0; }
}; };
struct hip_copy struct hip_copy
...@@ -82,8 +85,11 @@ struct hip_copy ...@@ -82,8 +85,11 @@ struct hip_copy
copy_to_gpu(args[0], args[1]); copy_to_gpu(args[0], args[1]);
return args[1]; return args[1];
} }
int output_alias(const std::vector<shape>&) const { return 1; }
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/generate.hpp> #include <migraph/generate.hpp>
#include <migraph/shape_for_each.hpp> #include <migraph/shape_for_each.hpp>
#include <migraph/config.hpp>
#include <migraph/gpu/miopen.hpp> #include <migraph/gpu/miopen.hpp>
#include <migraph/gpu/hip.hpp> #include <migraph/gpu/hip.hpp>
#include <migraph/dfor.hpp> #include <migraph/dfor.hpp>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct miopen_leaky_relu struct miopen_leaky_relu
...@@ -27,10 +29,11 @@ struct miopen_leaky_relu ...@@ -27,10 +29,11 @@ struct miopen_leaky_relu
shape compute_shape(const std::vector<shape>& inputs) const; shape compute_shape(const std::vector<shape>& inputs) const;
argument argument
compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const; compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const;
int output_alias(const std::vector<shape>& shapes) const { return shapes.size() - 1; }
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
#define MIGRAPH_GUARD_RTGLIB_MIOPEN_LOWERING_HPP #define MIGRAPH_GUARD_RTGLIB_MIOPEN_LOWERING_HPP
#include <migraph/program.hpp> #include <migraph/program.hpp>
#include <migraph/config.hpp>
#include <migraph/gpu/context.hpp> #include <migraph/gpu/context.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct lowering struct lowering
...@@ -15,7 +17,7 @@ struct lowering ...@@ -15,7 +17,7 @@ struct lowering
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include <migraph/manage_ptr.hpp> #include <migraph/manage_ptr.hpp>
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <miopen/miopen.h> #include <miopen/miopen.h>
#include <migraph/config.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
using miopen_handle = MIGRAPH_MANAGE_PTR(miopenHandle_t, miopenDestroy); using miopen_handle = MIGRAPH_MANAGE_PTR(miopenHandle_t, miopenDestroy);
...@@ -115,7 +117,7 @@ inline fused_operator_args make_fused_args() ...@@ -115,7 +117,7 @@ inline fused_operator_args make_fused_args()
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/generate.hpp> #include <migraph/generate.hpp>
#include <migraph/shape_for_each.hpp> #include <migraph/shape_for_each.hpp>
#include <migraph/config.hpp>
#include <migraph/gpu/miopen.hpp> #include <migraph/gpu/miopen.hpp>
#include <migraph/gpu/hip.hpp> #include <migraph/gpu/hip.hpp>
#include <migraph/dfor.hpp> #include <migraph/dfor.hpp>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct hip_mul struct hip_mul
...@@ -25,10 +27,11 @@ struct hip_mul ...@@ -25,10 +27,11 @@ struct hip_mul
std::string name() const { return "gpu::mul"; } std::string name() const { return "gpu::mul"; }
shape compute_shape(const std::vector<shape>& inputs) const; shape compute_shape(const std::vector<shape>& inputs) const;
argument compute(context&, const shape&, const std::vector<argument>& args) const; argument compute(context&, const shape&, const std::vector<argument>& args) const;
int output_alias(const std::vector<shape>& shapes) const { return shapes.size() - 1; }
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/generate.hpp> #include <migraph/generate.hpp>
#include <migraph/shape_for_each.hpp> #include <migraph/shape_for_each.hpp>
#include <migraph/config.hpp>
#include <migraph/gpu/miopen.hpp> #include <migraph/gpu/miopen.hpp>
#include <migraph/gpu/hip.hpp> #include <migraph/gpu/hip.hpp>
#include <migraph/dfor.hpp> #include <migraph/dfor.hpp>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct miopen_pooling struct miopen_pooling
...@@ -29,10 +31,11 @@ struct miopen_pooling ...@@ -29,10 +31,11 @@ struct miopen_pooling
shape compute_shape(const std::vector<shape>& inputs) const; shape compute_shape(const std::vector<shape>& inputs) const;
argument argument
compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const; compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const;
int output_alias(const std::vector<shape>& shapes) const { return shapes.size() - 1; }
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/generate.hpp> #include <migraph/generate.hpp>
#include <migraph/shape_for_each.hpp> #include <migraph/shape_for_each.hpp>
#include <migraph/config.hpp>
#include <migraph/gpu/miopen.hpp> #include <migraph/gpu/miopen.hpp>
#include <migraph/gpu/hip.hpp> #include <migraph/gpu/hip.hpp>
#include <migraph/dfor.hpp> #include <migraph/dfor.hpp>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct miopen_relu struct miopen_relu
...@@ -27,10 +29,11 @@ struct miopen_relu ...@@ -27,10 +29,11 @@ struct miopen_relu
shape compute_shape(const std::vector<shape>& inputs) const; shape compute_shape(const std::vector<shape>& inputs) const;
argument argument
compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const; compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const;
int output_alias(const std::vector<shape>& shapes) const { return shapes.size() - 1; }
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
#include <migraph/manage_ptr.hpp> #include <migraph/manage_ptr.hpp>
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/config.hpp>
#include <rocblas.h> #include <rocblas.h>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
using rocblas_handle_ptr = MIGRAPH_MANAGE_PTR(rocblas_handle, rocblas_destroy_handle); using rocblas_handle_ptr = MIGRAPH_MANAGE_PTR(rocblas_handle, rocblas_destroy_handle);
...@@ -14,7 +16,7 @@ rocblas_handle_ptr create_rocblas_handle_ptr(); ...@@ -14,7 +16,7 @@ rocblas_handle_ptr create_rocblas_handle_ptr();
rocblas_handle_ptr create_rocblas_handle_ptr(hipStream_t s); rocblas_handle_ptr create_rocblas_handle_ptr(hipStream_t s);
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <migraph/operators.hpp> #include <migraph/operators.hpp>
#include <migraph/generate.hpp> #include <migraph/generate.hpp>
#include <migraph/shape_for_each.hpp> #include <migraph/shape_for_each.hpp>
#include <migraph/config.hpp>
#include <migraph/gpu/miopen.hpp> #include <migraph/gpu/miopen.hpp>
#include <migraph/gpu/hip.hpp> #include <migraph/gpu/hip.hpp>
#include <migraph/dfor.hpp> #include <migraph/dfor.hpp>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct miopen_softmax struct miopen_softmax
...@@ -27,10 +29,11 @@ struct miopen_softmax ...@@ -27,10 +29,11 @@ struct miopen_softmax
shape compute_shape(const std::vector<shape>& inputs) const; shape compute_shape(const std::vector<shape>& inputs) const;
argument argument
compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const; compute(context& ctx, const shape& output_shape, const std::vector<argument>& args) const;
int output_alias(const std::vector<shape>& shapes) const { return shapes.size() - 1; }
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
#define MIGRAPH_GUARD_MIGRAPHLIB_MIOPEN_TARGET_HPP #define MIGRAPH_GUARD_MIGRAPHLIB_MIOPEN_TARGET_HPP
#include <migraph/program.hpp> #include <migraph/program.hpp>
#include <migraph/config.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct target struct target
...@@ -12,7 +14,9 @@ struct target ...@@ -12,7 +14,9 @@ struct target
std::vector<pass> get_passes(migraph::context& gctx) const; std::vector<pass> get_passes(migraph::context& gctx) const;
migraph::context get_context() const; migraph::context get_context() const;
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <migraph/gpu/context.hpp> #include <migraph/gpu/context.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
...@@ -17,7 +18,7 @@ struct write_literals ...@@ -17,7 +18,7 @@ struct write_literals
}; };
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
shape miopen_leaky_relu::compute_shape(const std::vector<shape>& inputs) const shape miopen_leaky_relu::compute_shape(const std::vector<shape>& inputs) const
...@@ -33,5 +34,5 @@ argument miopen_leaky_relu::compute(context& ctx, ...@@ -33,5 +34,5 @@ argument miopen_leaky_relu::compute(context& ctx,
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
struct miopen_apply struct miopen_apply
...@@ -50,9 +51,9 @@ struct miopen_apply ...@@ -50,9 +51,9 @@ struct miopen_apply
{ {
check_shape(s, apply_convolution(it)); check_shape(s, apply_convolution(it));
} }
else if(it->name() == "activation") else if(it->name() == "relu")
{ {
check_shape(s, apply_activation(it)); check_shape(s, apply_relu(it));
} }
else if(it->name() == "leaky_relu") else if(it->name() == "leaky_relu")
{ {
...@@ -131,17 +132,13 @@ struct miopen_apply ...@@ -131,17 +132,13 @@ struct miopen_apply
ins, miopen_pooling{op, std::move(pd)}, ins->inputs().at(0), output); ins, miopen_pooling{op, std::move(pd)}, ins->inputs().at(0), output);
} }
instruction_ref apply_activation(instruction_ref ins) instruction_ref apply_relu(instruction_ref ins)
{ {
auto&& op = any_cast<op::activation>(ins->get_operator()); auto ad = make_relu();
auto ad = make_relu();
if(op.mode == "relu") auto output = insert_allocation(ins, ins->get_shape());
{ return prog->replace_instruction(
auto output = insert_allocation(ins, ins->get_shape()); ins, miopen_relu{std::move(ad)}, ins->inputs().at(0), output);
return prog->replace_instruction(
ins, miopen_relu{std::move(ad)}, ins->inputs().at(0), output);
}
return ins;
} }
instruction_ref apply_leaky_relu(instruction_ref ins) instruction_ref apply_leaky_relu(instruction_ref ins)
...@@ -224,4 +221,5 @@ struct miopen_apply ...@@ -224,4 +221,5 @@ struct miopen_apply
void lowering::apply(program& p) const { miopen_apply{&p, ctx}.apply(); } void lowering::apply(program& p) const { miopen_apply{&p, ctx}.apply(); }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
shape hip_mul::compute_shape(const std::vector<shape>& inputs) const shape hip_mul::compute_shape(const std::vector<shape>& inputs) const
...@@ -21,5 +22,5 @@ argument hip_mul::compute(context& ctx, const shape&, const std::vector<argument ...@@ -21,5 +22,5 @@ argument hip_mul::compute(context& ctx, const shape&, const std::vector<argument
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
shape miopen_pooling::compute_shape(const std::vector<shape>& inputs) const shape miopen_pooling::compute_shape(const std::vector<shape>& inputs) const
...@@ -37,5 +38,5 @@ argument miopen_pooling::compute(context& ctx, ...@@ -37,5 +38,5 @@ argument miopen_pooling::compute(context& ctx,
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
shape miopen_relu::compute_shape(const std::vector<shape>& inputs) const shape miopen_relu::compute_shape(const std::vector<shape>& inputs) const
...@@ -33,5 +34,5 @@ argument miopen_relu::compute(context& ctx, ...@@ -33,5 +34,5 @@ argument miopen_relu::compute(context& ctx,
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
#include <migraph/gpu/rocblas.hpp> #include <migraph/gpu/rocblas.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
rocblas_handle_ptr create_rocblas_handle_ptr() rocblas_handle_ptr create_rocblas_handle_ptr()
...@@ -18,5 +19,5 @@ rocblas_handle_ptr create_rocblas_handle_ptr(hipStream_t s) ...@@ -18,5 +19,5 @@ rocblas_handle_ptr create_rocblas_handle_ptr(hipStream_t s)
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <utility> #include <utility>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
shape miopen_softmax::compute_shape(const std::vector<shape>& inputs) const shape miopen_softmax::compute_shape(const std::vector<shape>& inputs) const
...@@ -32,5 +33,5 @@ argument miopen_softmax::compute(context& ctx, ...@@ -32,5 +33,5 @@ argument miopen_softmax::compute(context& ctx,
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
#include <migraph/eliminate_contiguous.hpp> #include <migraph/eliminate_contiguous.hpp>
#include <migraph/common_subexpression_elimination.hpp> #include <migraph/common_subexpression_elimination.hpp>
#include <migraph/fwd_conv_batchnorm_rewrite.hpp> #include <migraph/fwd_conv_batchnorm_rewrite.hpp>
#include <migraph/eliminate_concat.hpp>
#include <migraph/gpu/concat_gpu_opt.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
std::vector<pass> target::get_passes(migraph::context& gctx) const std::vector<pass> target::get_passes(migraph::context& gctx) const
...@@ -38,6 +41,8 @@ std::vector<pass> target::get_passes(migraph::context& gctx) const ...@@ -38,6 +41,8 @@ std::vector<pass> target::get_passes(migraph::context& gctx) const
simplify_reshapes{}, simplify_reshapes{},
dead_code_elimination{}, dead_code_elimination{},
lowering{ctx}, lowering{ctx},
eliminate_concat{concat_gpu_optimization{}},
dead_code_elimination{},
eliminate_contiguous{}, eliminate_contiguous{},
dead_code_elimination{}, dead_code_elimination{},
fuse_ops{&ctx}, fuse_ops{&ctx},
...@@ -56,4 +61,5 @@ std::string target::name() const { return "miopen"; } ...@@ -56,4 +61,5 @@ std::string target::name() const { return "miopen"; }
migraph::context target::get_context() const { return context{}; } migraph::context target::get_context() const { return context{}; }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <migraph/env.hpp> #include <migraph/env.hpp>
namespace migraph { namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
namespace gpu { namespace gpu {
MIGRAPH_DECLARE_ENV_VAR(MIGRAPH_COPY_LITERALS) MIGRAPH_DECLARE_ENV_VAR(MIGRAPH_COPY_LITERALS)
...@@ -51,5 +51,7 @@ void write_literals::apply(program& p) const ...@@ -51,5 +51,7 @@ void write_literals::apply(program& p) const
} }
} }
} }
} // namespace gpu } // namespace gpu
} // namespace MIGRAPH_INLINE_NS
} // namespace migraph } // namespace migraph
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment