From 1403517664ea77e7eef89fd6c5f5254b3aa446d0 Mon Sep 17 00:00:00 2001 From: ravil-mobile Date: Tue, 5 Sep 2023 15:14:55 +0200 Subject: [PATCH] Fixed printing to stdout when `MIGRAPHX_TRACE_MLIR` is enabled (#2148) --- src/targets/gpu/mlir.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/targets/gpu/mlir.cpp b/src/targets/gpu/mlir.cpp index 4eb48a84c6c..1bf3348162b 100644 --- a/src/targets/gpu/mlir.cpp +++ b/src/targets/gpu/mlir.cpp @@ -647,8 +647,8 @@ struct mlir_program void set_gpu_properties(const context& migraphx_ctx) { const auto& device = migraphx_ctx.get_current_device(); - target_arch = device.get_device_name(); - num_cu = device.get_cu_count(); + target_arch = device.get_device_name(); + num_cu = device.get_cu_count(); } std::pair get_launch_params() const @@ -869,15 +869,22 @@ code_object_op compile_mlir(const context& migraphx_ctx, adjust_param_shapes(m, to_shapes(inputs)); const bool trace = enabled(MIGRAPHX_TRACE_MLIR{}); + static std::mutex mutex; if(trace) + { + const std::lock_guard lock(mutex); std::cout << m << std::endl; + } mlir_program mp; mp.set_gpu_properties(migraphx_ctx); mp.parse(m); auto mod_op = mlirModuleGetOperation(mp.mmodule.get()); if(trace) + { + const std::lock_guard lock(mutex); std::cout << mlir_print(&mlirOperationPrint, mod_op) << std::endl; + } auto co = mp.compile(solution); co.expected_inputs = to_shapes(inputs); co.output = m.get_output_shapes().front();