Commit 9bee6af8 authored by Shucai Xiao's avatar Shucai Xiao
Browse files

add the gpu implementation of the fp_conversion operator

parent efa8d9f4
......@@ -27,6 +27,7 @@ add_library(migraphx_device
device/add_relu.cpp
device/contiguous.cpp
device/logsoftmax.cpp
device/fp_conversion.cpp
device/mul.cpp
device/concat.cpp
device/pad.cpp
......@@ -50,6 +51,7 @@ add_library(migraphx_gpu
convolution.cpp
softmax.cpp
logsoftmax.cpp
fp_conversion.cpp
contiguous.cpp
concat.cpp
relu.cpp
......
#include <migraphx/gpu/device/fp_conversion.hpp>
#include <migraphx/gpu/device/nary.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {
namespace device {
argument
fp_conversion(hipStream_t stream, const shape& output_shape, const std::vector<argument>& args)
{
args.back().visit([&](auto output) {
args.front().visit([&](auto input) {
const auto* input_ptr = device_cast(input.data());
auto* output_ptr = device_cast(output.data());
gs_launch(stream,
output_shape.elements())([=](auto i) { output_ptr[i] = input_ptr[i]; });
});
});
return args.back();
}
} // namespace device
} // namespace gpu
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#include <migraphx/gpu/fp_conversion.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/device/gather.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {
shape hip_fp_conversion::compute_shape(std::vector<shape> inputs) const
{
inputs.pop_back();
return op.compute_shape(inputs);
}
argument hip_fp_conversion::compute(context& ctx,
const shape& output_shape,
const std::vector<argument>& args) const
{
return device::fp_conversion(ctx.get_stream().get(), output_shape, args);
}
} // namespace gpu
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#ifndef MIGRAPHX_GUARD_RTGLIB_DEVICE_FP_CONVERSION_HPP
#define MIGRAPHX_GUARD_RTGLIB_DEVICE_FP_CONVERSION_HPP
#include <migraphx/argument.hpp>
#include <migraphx/config.hpp>
#include <hip/hip_runtime_api.h>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {
namespace device {
argument
fp_conversion(hipStream_t stream, const shape& output_shape, const std::vector<argument>& args);
} // namespace device
} // namespace gpu
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
#ifndef MIGRAPHX_GUARD_RTGLIB_FP_CONVERSION_HPP
#define MIGRAPHX_GUARD_RTGLIB_FP_CONVERSION_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/fp_conversion.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {
struct hip_fp_conversion
{
op::fp_conversion op;
std::string name() const { return "gpu::fp_conversion"; }
shape compute_shape(std::vector<shape> inputs) const;
argument
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 MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
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