Unverified Commit 581d31b0 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Add initial code generation (#762)



* Add code object op

* Formattting

* Add more value tests

* Formatting

* Fix from_value conversion from binary

* Formatting

* Dont use offload copy

* Remove iostream header

* Fix compilation errors

* Formatting

* Rename var

* Add missing files

* Formatting

* Remove duplicate variable

* Remove comment

* Template the function so sfinae will work

* Formatting

* Use template specialization since ADL is broken on hcc

* Formatting

* Annotate the constructor with HD for hcc

* Make variable const
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
parent e1819f81
......@@ -7,9 +7,10 @@
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/gpu/compile_hip.hpp>
#include <migraphx/gpu/compile_hip_code_object.hpp>
// NOLINTNEXTLINE
const std::string write_2s = R"migraphx(
const std::string write_2s = R"__migraphx__(
#include <hip/hip_runtime.h>
extern "C" {
......@@ -23,10 +24,10 @@ __global__ void write(int* data)
int main() {}
)migraphx";
)__migraphx__";
// NOLINTNEXTLINE
const std::string add_2s_binary = R"migraphx(
const std::string add_2s_binary = R"__migraphx__(
#include <hip/hip_runtime.h>
extern "C" {
......@@ -40,7 +41,33 @@ __global__ void add_2(std::int32_t* x, std::int32_t* y)
int main() {}
)migraphx";
)__migraphx__";
// NOLINTNEXTLINE
const std::string simple_pointwise_increment = R"__migraphx__(
#include <migraphx/kernels/index.hpp>
#include <args.hpp>
using namespace migraphx;
extern "C" {
__global__ void kernel(void* x, void* y)
{
make_tensors(x, y)([](auto xt, auto yt) __device__ {
auto idx = make_index();
const auto stride = idx.nglobal();
for(index_int i = idx.global; i < xt.get_shape().elements(); i += stride)
{
yt[i] = xt[i] + 1;
}
});
}
}
int main() {}
)__migraphx__";
migraphx::gpu::src_file make_src_file(const std::string& name, const std::string& content)
{
......@@ -106,4 +133,30 @@ TEST_CASE(code_object_hip)
EXPECT(result == output_literal.get_argument());
}
TEST_CASE(compile_code_object_hip)
{
migraphx::shape input{migraphx::shape::float_type, {5, 2}};
migraphx::gpu::hip_compile_options options;
options.global = 256 * 1024;
options.local = 1024;
options.inputs = {input, input};
options.output = input;
auto co = migraphx::gpu::compile_hip_code_object(simple_pointwise_increment, options);
migraphx::program p;
auto* mm = p.get_main_module();
auto input_literal = migraphx::generate_literal(input);
auto output_literal = migraphx::transform(input_literal, [](auto x) { return x + 1; });
auto x = mm->add_literal(input_literal);
auto y = mm->add_instruction(
migraphx::make_op("hip::allocate", {{"shape", migraphx::to_value(input)}}));
mm->add_instruction(co, x, y);
p.compile(migraphx::gpu::target{}, migraphx::compile_options{});
auto result = migraphx::gpu::from_gpu(p.eval({}).front());
EXPECT(result == output_literal.get_argument());
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
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