Skip to content

Commit 881774f

Browse files
Formatting
1 parent 0fc7cf1 commit 881774f

File tree

10 files changed

+134
-135
lines changed

10 files changed

+134
-135
lines changed

src/driver/main.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,10 @@ struct compiler
586586
{"--exhaustive-tune"},
587587
ap.help("Exhastively search for best tuning parameters for kernels"),
588588
ap.set_value(true));
589-
ap(co.portable,
590-
{"--portable"},
591-
ap.help("PROTOTYPE: Create portable kernels that get finalized in ./driver run"),
592-
ap.set_value(true));
589+
ap(co.portable,
590+
{"--portable"},
591+
ap.help("PROTOTYPE: Create portable kernels that get finalized in ./driver run"),
592+
ap.set_value(true));
593593
ap(to_fp16, {"--fp16"}, ap.help("Quantize for fp16"), ap.set_value(true));
594594
ap(to_bf16, {"--bf16"}, ap.help("Quantize for bf16"), ap.set_value(true));
595595
ap(to_int8, {"--int8"}, ap.help("Quantize for int8"), ap.set_value(true));
@@ -607,21 +607,21 @@ struct compiler
607607
return parameters.generate(p, ct.get_target(), true, l.batch);
608608
}
609609

610-
bool has_portable_ops(program& p)
610+
bool has_portable_ops(program& p)
611611
{
612612
auto mods = p.get_modules();
613-
for(const auto* mod: mods)
613+
for(const auto* mod : mods)
614614
{
615-
for(const auto& ins : *mod)
616-
{
617-
if(ins.name() == "gpu::code_object")
615+
for(const auto& ins : *mod)
616+
{
617+
if(ins.name() == "gpu::code_object")
618618
{
619-
migraphx::gpu::code_object_op migx_co = migraphx::any_cast<migraphx::gpu::code_object_op>(ins.get_operator());
619+
migraphx::gpu::code_object_op migx_co =
620+
migraphx::any_cast<migraphx::gpu::code_object_op>(ins.get_operator());
620621
if(migx_co.is_mlir())
621622
return true;
622623
}
623-
624-
}
624+
}
625625
}
626626
return false;
627627
}
@@ -637,15 +637,16 @@ struct compiler
637637
std::cout << "Already compiled\n";
638638

639639
bool has_port_ops = has_portable_ops(p);
640-
if(has_port_ops) // means we must finalize it
641-
{
642-
auto ctx = ct.get_target().get_context();
640+
if(has_port_ops) // means we must finalize it
641+
{
642+
auto ctx = ct.get_target().get_context();
643643
auto& gpu_ctx = any_cast<migraphx::gpu::context>(ctx);
644-
migraphx::run_passes(*p.get_main_module(), {migraphx::gpu::compile_bytecode{&gpu_ctx}});
644+
migraphx::run_passes(*p.get_main_module(),
645+
{migraphx::gpu::compile_bytecode{&gpu_ctx}});
645646
p.finalize();
646647
l.save(p);
647-
}
648-
648+
}
649+
649650
if(ct.target_name == "gpu")
650651
{
651652
if(is_offload_copy_set(p) and not co.offload_copy)
@@ -666,9 +667,10 @@ struct compiler
666667
}
667668
}
668669

669-
if(!has_port_ops)
670+
if(!has_port_ops)
670671
{
671-
std::cout << "The program is already compiled, skipping compilation ..." << std::endl;
672+
std::cout << "The program is already compiled, skipping compilation ..."
673+
<< std::endl;
672674
}
673675
if(to_fp16 or to_bf16 or to_int8 or to_fp8 or to_int4)
674676
{
@@ -886,8 +888,8 @@ struct roctx : command<roctx>
886888

887889
void run()
888890
{
889-
auto p = c.compile();
890-
auto m = c.params(p);
891+
auto p = c.compile();
892+
auto m = c.params(p);
891893
auto rtx = create_marker_roctx();
892894
p.mark(m, std::move(rtx));
893895
}

src/targets/gpu/code_object_op.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ code_object_op::compute(context& ctx, const shape&, const std::vector<argument>&
6060
return args[get_output_arg(args.size())];
6161
}
6262
void code_object_op::finalize(context&, const shape&, const std::vector<shape>&)
63-
{
63+
{
6464
assert(not code_object.empty());
6565
if(this->format == code_object_format::binary)
6666
{

src/targets/gpu/compile_bytecode.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ namespace gpu {
4444
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_GPU_COMPILE_PARALLEL);
4545
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_BENCHMARKING);
4646

47-
4847
// For the most part this is just a modified compile_ops file, changed to deal with MLIR bytecode
49-
// important thing here to note is that we do not save the mlir module anywhere, causing us to have to reread
50-
// each bytecode sequence over and over again, this is extremely inefficient. We would need to export mlir.cpp
51-
// structs/APIs to expose the mlir objects, then we would need to read each bytecode sequence once and when we
52-
// need to compile, affix tuning params, then run, we can just clone the module via:
48+
// important thing here to note is that we do not save the mlir module anywhere, causing us to have
49+
// to reread each bytecode sequence over and over again, this is extremely inefficient. We would
50+
// need to export mlir.cpp structs/APIs to expose the mlir objects, then we would need to read each
51+
// bytecode sequence once and when we need to compile, affix tuning params, then run, we can just
52+
// clone the module via:
5353
// mlir_module new_module = original_module.clone()
54-
// this might be useful for the general pipeline as well since we won't have to rerun the pipeline from
55-
// start to finish, instead we can start from right before affixing parameters and arch info.
54+
// this might be useful for the general pipeline as well since we won't have to rerun the pipeline
55+
// from start to finish, instead we can start from right before affixing parameters and arch info.
5656

5757
struct bc_compiled_result
5858
{
@@ -72,20 +72,18 @@ struct bc_compile_plan
7272
operation preop;
7373
instruction_ref ins;
7474
module_ref mod;
75-
optional<tuning_config> config = nullopt;
75+
optional<tuning_config> config = nullopt;
7676
std::vector<optional<bc_compiled_result>> results = {};
77-
void update_config(bool exhaustive)
78-
{
79-
config = get_tuning_config_mlir(*ctx, ins, exhaustive);
80-
}
77+
void update_config(bool exhaustive) { config = get_tuning_config_mlir(*ctx, ins, exhaustive); }
8178
template <class Vector>
8279
void insert_compiles(Vector& compiles, const value& solution, std::size_t i)
8380
{
8481
compiles.emplace_back([=] {
8582
try
8683
{
8784
/* maybe change what compiled_result is, we dont want to substitute */
88-
results[i] = bc_compiled_result{compile_mlir(*ctx, ins, any_cast<code_object_op>(preop), solution), ins};
85+
results[i] = bc_compiled_result{
86+
compile_mlir(*ctx, ins, any_cast<code_object_op>(preop), solution), ins};
8987
}
9088
catch(const std::exception& e)
9189
{
@@ -191,7 +189,7 @@ struct bc_compile_plan
191189
return *results.front();
192190
}
193191
if(not config)
194-
MIGRAPHX_THROW("Multiple kernels without config for " + preop.name());
192+
MIGRAPHX_THROW("Multiple kernels without config for " + preop.name());
195193
if(trace_level > 1)
196194
std::cout << "Problem: " << config->problem << std::endl;
197195

@@ -212,7 +210,7 @@ struct bc_compile_plan
212210
}
213211
if(trace_level > 2)
214212
std::cout << *cr << std::endl;
215-
213+
216214
/*
217215
create a small program with insturction being compiled and call "replace"
218216
on that which would insert all the compiled code objects, prefills etc.
@@ -235,7 +233,8 @@ struct bc_compile_plan
235233
run_passes(*bench_mm, {dead_code_elimination{}});
236234
// by default, measure runtime with bundle of 1 benchmark config,
237235
// repeat 20 times
238-
auto t = time_program(*ctx, bench_prog, std::unordered_map<std::string, double>{}, 1, 20);
236+
auto t = time_program(
237+
*ctx, bench_prog, std::unordered_map<std::string, double>{}, 1, 20);
239238
if(trace_level > 1)
240239
std::cout << t << "ms" << std::endl;
241240
return t;
@@ -325,7 +324,7 @@ void compile_bytecode::apply(module& m) const
325324
{
326325
if(ins->name() != "gpu::code_object")
327326
continue;
328-
327+
329328
operation preop = any_cast<code_object_op>(ins->get_operator());
330329

331330
if(any_cast<code_object_op>(preop).format == code_object_format::binary)
@@ -341,5 +340,5 @@ void compile_bytecode::apply(module& m) const
341340
}
342341

343342
} // namespace gpu
344-
} // namespace migraphx
345343
} // namespace MIGRAPHX_INLINE_NS
344+
} // namespace migraphx

src/targets/gpu/compile_hip_code_object.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ compile_hip_code_object(context& ctx, const std::string& content, hip_compile_op
203203
options.params.insert(options.params.end(), warnings.begin(), warnings.end());
204204
options.emplace_param("-ftemplate-backtrace-limit=0");
205205
options.emplace_param("-Werror");
206-
auto cos = ctx.get_portable_flag()
207-
? compile_hip_src(srcs, options.params, "amdgcnspirv")
208-
: compile_hip_src(srcs, options.params, get_device_name());
206+
auto cos = ctx.get_portable_flag() ? compile_hip_src(srcs, options.params, "amdgcnspirv")
207+
: compile_hip_src(srcs, options.params, get_device_name());
209208
if(cos.size() != 1)
210209
MIGRAPHX_THROW("No code object");
211210
return code_object_op{value::binary{cos.front()},

src/targets/gpu/include/migraphx/gpu/code_object_op.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace migraphx {
3434
inline namespace MIGRAPHX_INLINE_NS {
3535
namespace gpu {
3636

37-
enum struct code_object_format
37+
enum struct code_object_format
3838
{
3939
binary,
4040
mlir_bytecode
@@ -54,14 +54,16 @@ struct code_object_op
5454
kernel k{};
5555
code_object_format format = code_object_format::binary;
5656
// maybe add instruction_ref ins;
57-
/* this allows us to simply convert the mlirbc back to mlir, then run the remaining passes
57+
/* this allows us to simply convert the mlirbc back to mlir, then run the remaining passes
5858
after we can just compile it using compile_ops, might need some small adjustments
5959
mainly: how are we to start at the "end" of the pipeline at the kernel_pass?
6060
6161
try:
62-
MIGRAPHX_TRACE_COMPILE=1 MIGRAPHX_TRACE_MLIR=1 MIGRAPHX_MLIR_TUNE_LIMIT=1 ./bin/driver compile ../spirv/MXRs/gemm.mxr
62+
MIGRAPHX_TRACE_COMPILE=1 MIGRAPHX_TRACE_MLIR=1 MIGRAPHX_MLIR_TUNE_LIMIT=1 ./bin/driver
63+
compile ../spirv/MXRs/gemm.mxr
6364
64-
MIGRAPHX_TRACE_CMD_EXECUTE=1 MIGRAPHX_TRACE_COMPILE=1 MIGRAPHX_TRACE_MLIR=1 MIGRAPHX_MLIR_TUNE_LIMIT=1 ./bin/driver compile --portable ../spirv/MXRs/pointwise.mxr
65+
MIGRAPHX_TRACE_CMD_EXECUTE=1 MIGRAPHX_TRACE_COMPILE=1 MIGRAPHX_TRACE_MLIR=1
66+
MIGRAPHX_MLIR_TUNE_LIMIT=1 ./bin/driver compile --portable ../spirv/MXRs/pointwise.mxr
6567
*/
6668

6769
template <class Self, class F>
@@ -94,7 +96,7 @@ struct code_object_op
9496
{
9597
return get_output_arg(shapes.size());
9698
}
97-
bool is_mlir() const {return format == code_object_format::mlir_bytecode; }
99+
bool is_mlir() const { return format == code_object_format::mlir_bytecode; }
98100

99101
friend std::ostream& operator<<(std::ostream& os, const code_object_op& op)
100102
{
@@ -105,7 +107,7 @@ struct code_object_op
105107
os << "local=" << op.local << ",";
106108
if(op.output_arg != -1)
107109
os << "output_arg=" << op.output_arg << ",";
108-
os << "format=" << (op.format == code_object_format::binary ? "binary" : "mlir_bytecode");
110+
os << "format=" << (op.format == code_object_format::binary ? "binary" : "mlir_bytecode");
109111
os << "]";
110112
return os;
111113
}

src/targets/gpu/include/migraphx/gpu/context.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ struct context
270270
void set_exhaustive_tune_flag(bool t) { exhaustive_tune = t; }
271271

272272
bool get_portable_flag() const { return portable; }
273-
273+
274274
void set_portable_flag(bool p) { portable = p; }
275275

276276
hip_device::stream& get_stream() { return get_current_device().get_stream(); }
@@ -386,7 +386,7 @@ struct context
386386
std::shared_ptr<hip_device> current_device;
387387
std::vector<shared<hip_event_ptr>> events;
388388
bool exhaustive_tune = false;
389-
bool portable = false;
389+
bool portable = false;
390390
bool measure_perf = false;
391391
// for event perf timing
392392
shared<hip_event_ptr> start_event = nullptr;

src/targets/gpu/include/migraphx/gpu/mlir.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ MIGRAPHX_GPU_EXPORT mlir_code_object compile_mlir(const context& migraphx_ctx,
6464
MIGRAPHX_GPU_EXPORT mlir_code_object compile_mlir(const context& migraphx_ctx,
6565
instruction_ref ins,
6666
code_object_op co,
67-
const value& solution);
67+
const value& solution);
6868

6969
MIGRAPHX_GPU_EXPORT instruction_ref insert_mlir(module& m,
7070
instruction_ref ins,
@@ -74,11 +74,11 @@ MIGRAPHX_GPU_EXPORT instruction_ref insert_mlir(module& m,
7474
MIGRAPHX_GPU_EXPORT tuning_config get_tuning_config_mlir(const context& migraphx_ctx,
7575
module m,
7676
const std::vector<shape>& inputs,
77-
bool exhaustive);
78-
77+
bool exhaustive);
78+
7979
MIGRAPHX_GPU_EXPORT tuning_config get_tuning_config_mlir(const context& migraphx_ctx,
80-
instruction_ref ins,
81-
bool exhaustive);
80+
instruction_ref ins,
81+
bool exhaustive);
8282

8383
MIGRAPHX_GPU_EXPORT void
8484
dump_mlir_to_mxr(module m, const std::vector<instruction_ref>& inputs, const fs::path& location);

src/targets/gpu/jit/mlir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct mlir_compiler : compiler<mlir_compiler>
146146
if(gemm_like_ins != smod->end() and pointwise_ins != smod->end() and
147147
not is_module_fusible(*smod, ctx, solution))
148148
{
149-
std::cout << "Compiling fused gemm w/perfConf\n";
149+
std::cout << "Compiling fused gemm w/perfConf\n";
150150
auto input_args = ins->inputs();
151151
// remove alloc buffer
152152
input_args.pop_back();

0 commit comments

Comments
 (0)