From c8b626ab592ca31f4e71e1391560226aa8c2c84b Mon Sep 17 00:00:00 2001 From: Ioannis Magkanaris Date: Thu, 12 May 2022 13:18:11 +0200 Subject: [PATCH] Replaced fmt literals with fmt::format --- src/codegen/codegen_c_visitor.cpp | 2 +- src/codegen/codegen_c_visitor.hpp | 1 - src/codegen/codegen_driver.cpp | 5 +- src/codegen/codegen_info.cpp | 3 +- .../llvm/codegen_llvm_helper_visitor.cpp | 71 ++++++++++--------- .../llvm/codegen_llvm_helper_visitor.hpp | 6 +- src/codegen/llvm/codegen_llvm_visitor.cpp | 58 ++++++++------- .../llvm/replace_with_lib_functions.cpp | 6 +- src/main.cpp | 30 ++++---- test/benchmark/cuda_driver.cpp | 15 ++-- 10 files changed, 103 insertions(+), 94 deletions(-) diff --git a/src/codegen/codegen_c_visitor.cpp b/src/codegen/codegen_c_visitor.cpp index aa790d9bcb..762958d023 100644 --- a/src/codegen/codegen_c_visitor.cpp +++ b/src/codegen/codegen_c_visitor.cpp @@ -904,7 +904,7 @@ bool CodegenCVisitor::shadow_vector_setup_required() { void CodegenCVisitor::print_channel_iteration_loop(const std::string& start = "start", const std::string& end = "end") { - printer->start_block("for (int id = {}; id < {}; id++)"_format(start, end)); + printer->start_block(fmt::format("for (int id = {}; id < {}; id++)", start, end)); } diff --git a/src/codegen/codegen_c_visitor.hpp b/src/codegen/codegen_c_visitor.hpp index ac1fd190ca..1c4349914e 100644 --- a/src/codegen/codegen_c_visitor.hpp +++ b/src/codegen/codegen_c_visitor.hpp @@ -35,7 +35,6 @@ namespace nmodl { /// encapsulates code generation backend implementations namespace codegen { -using namespace fmt::literals; /** * @defgroup codegen Code Generation Implementation * @brief Implementations of code generation backends diff --git a/src/codegen/codegen_driver.cpp b/src/codegen/codegen_driver.cpp index 8dc6cfd8ea..5677f53eb4 100644 --- a/src/codegen/codegen_driver.cpp +++ b/src/codegen/codegen_driver.cpp @@ -157,8 +157,9 @@ bool CodegenDriver::prepare_mod(std::shared_ptr node, const std::s ast_to_nmodl(*node, filename); if (cfg.nmodl_ast && kineticBlockVisitor.get_conserve_statement_count()) { logger->warn( - fmt::format("{} presents non-standard CONSERVE statements in DERIVATIVE blocks. Use it only for debugging/developing", - filename)); + fmt::format("{} presents non-standard CONSERVE statements in DERIVATIVE blocks. " + "Use it only for debugging/developing", + filename)); } } diff --git a/src/codegen/codegen_info.cpp b/src/codegen/codegen_info.cpp index 29de809ac3..0540c02d04 100644 --- a/src/codegen/codegen_info.cpp +++ b/src/codegen/codegen_info.cpp @@ -16,7 +16,6 @@ namespace nmodl { namespace codegen { -using namespace fmt::literals; using symtab::syminfo::NmodlType; using visitor::VarUsageVisitor; @@ -328,7 +327,7 @@ void CodegenInfo::get_int_variables() { */ if (!watch_statements.empty()) { for (int i = 0; i < watch_statements.size() + 1; i++) { - codegen_int_variables.emplace_back(make_symbol("watch{}"_format(i)), + codegen_int_variables.emplace_back(make_symbol(fmt::format("watch{}", i)), false, false, true); diff --git a/src/codegen/llvm/codegen_llvm_helper_visitor.cpp b/src/codegen/llvm/codegen_llvm_helper_visitor.cpp index 0f398526bf..0e05c6d885 100644 --- a/src/codegen/llvm/codegen_llvm_helper_visitor.cpp +++ b/src/codegen/llvm/codegen_llvm_helper_visitor.cpp @@ -18,8 +18,6 @@ namespace nmodl { namespace codegen { -using namespace fmt::literals; - using symtab::syminfo::Status; /// initialize static member variables @@ -148,7 +146,7 @@ void CodegenLLVMHelperVisitor::create_function_for_node(ast::Block& node) { auto name = new ast::Name(new ast::String(function_name)); /// return variable name has "ret_" prefix - std::string return_var_name = "ret_{}"_format(function_name); + std::string return_var_name = fmt::format("ret_{}", function_name); auto return_var = new ast::Name(new ast::String(return_var_name)); /// return type based on node type @@ -337,11 +335,12 @@ void CodegenLLVMHelperVisitor::ion_read_statements(BlockType type, // ion variable to be read std::string& ion_varname = variable_names.second; // index for reading ion variable - std::string index_varname = "{}_id"_format(varname); + std::string index_varname = fmt::format("{}_id", varname); // first load the index - std::string index_statement = "{} = {}_index[id]"_format(index_varname, ion_varname); + std::string index_statement = fmt::format("{} = {}_index[id]", index_varname, ion_varname); // now assign the value - std::string read_statement = "{} = {}[{}]"_format(varname, ion_varname, index_varname); + std::string read_statement = + fmt::format("{} = {}[{}]", varname, ion_varname, index_varname); // push index definition, index statement and actual read statement int_variables.push_back(index_varname); index_statements.push_back(visitor::create_statement(index_statement)); @@ -398,9 +397,9 @@ void CodegenLLVMHelperVisitor::ion_write_statements(BlockType type, /// create write ion and corresponding index statements auto create_write_statements = [&](std::string ion_varname, std::string op, std::string rhs) { // index for writing ion variable - std::string index_varname = "{}_id"_format(ion_varname); + std::string index_varname = fmt::format("{}_id", ion_varname); // load index - std::string index_statement = "{} = {}_index[id]"_format(index_varname, ion_varname); + std::string index_statement = fmt::format("{} = {}_index[id]", index_varname, ion_varname); // push index definition, index statement and actual write statement int_variables.push_back(index_varname); index_statements.push_back(visitor::create_statement(index_statement)); @@ -425,7 +424,7 @@ void CodegenLLVMHelperVisitor::ion_write_statements(BlockType type, // for synapse type if (info.point_process) { auto area = codegen::naming::NODE_AREA_VARIABLE; - rhs += "*(1.e2/{0}[{0}_id])"_format(area); + rhs += fmt::format("*(1.e2/{0}[{0}_id])", area); } create_write_statements(lhs, op, rhs); } @@ -449,10 +448,10 @@ void CodegenLLVMHelperVisitor::ion_write_statements(BlockType type, index = 2; } else { /// \todo Unhandled case also in neuron implementation - throw std::logic_error("codegen error for {} ion"_format(ion.name)); + throw std::logic_error(fmt::format("codegen error for {} ion", ion.name)); } - std::string ion_type_name = "{}_type"_format(ion.name); - std::string lhs = "int {}"_format(ion_type_name); + std::string ion_type_name = fmt::format("{}_type", ion.name); + std::string lhs = fmt::format("int {}", ion_type_name); std::string op = "="; std::string rhs = ion_type_name; create_write_statements(lhs, op, rhs); @@ -557,7 +556,7 @@ void CodegenLLVMHelperVisitor::rename_local_variables(ast::StatementBlock& node) /// rename local variable in entire statement block for (auto& var: local_statement->get_variables()) { std::string old_name = var->get_node_name(); - std::string new_name = "{}_{}"_format(old_name, local_block_counter); + std::string new_name = fmt::format("{}_{}", old_name, local_block_counter); visitor::RenameVisitor(old_name, new_name).visit_statement_block(node); } } @@ -668,9 +667,10 @@ void CodegenLLVMHelperVisitor::visit_nrn_state_block(ast::NrnStateBlock& node) { // prepare main body of the compute function { /// access node index and corresponding voltage - index_statements.push_back( - visitor::create_statement("node_id = node_index[{}]"_format(naming::INDUCTION_VAR))); - body_statements.push_back(visitor::create_statement("v = {}[node_id]"_format(VOLTAGE_VAR))); + index_statements.push_back(visitor::create_statement( + fmt::format("node_id = node_index[{}]", naming::INDUCTION_VAR))); + body_statements.push_back( + visitor::create_statement(fmt::format("v = {}[node_id]", VOLTAGE_VAR))); /// read ion variables ion_read_statements( @@ -870,11 +870,11 @@ void CodegenLLVMHelperVisitor::print_nrn_current_body(const ast::BreakpointBlock // sum now all currents for (auto& current: info.currents) { statements.emplace_back( - visitor::create_statement("current = current + {}"_format(current))); + visitor::create_statement(fmt::format("current = current + {}", current))); } // assign computed current to the given variable - statements.emplace_back(visitor::create_statement("{} = current"_format(variable))); + statements.emplace_back(visitor::create_statement(fmt::format("{} = current", variable))); // create StatementBlock for better readability of the generated code and add that to the main // body statements @@ -913,10 +913,10 @@ void CodegenLLVMHelperVisitor::print_nrn_cur_non_conductance_kernel( for (const auto& var: ion.writes) { if (ion.is_ionic_current(var)) { // also create local variable - std::string name{"di{}"_format(ion.name)}; + std::string name{fmt::format("di{}", ion.name)}; double_variables.emplace_back(name); body_statements.emplace_back( - visitor::create_statement("{} = {}"_format(name, var))); + visitor::create_statement(fmt::format("{} = {}", name, var))); } } } @@ -931,9 +931,9 @@ void CodegenLLVMHelperVisitor::print_nrn_cur_non_conductance_kernel( // in case of point process we need to load area from another vector. if (info.point_process) { // create integer variable for index and then load value from area_index vector - int_variables.emplace_back("{}_id"_format(naming::NODE_AREA_VARIABLE)); + int_variables.emplace_back(fmt::format("{}_id", naming::NODE_AREA_VARIABLE)); index_statements.emplace_back(visitor::create_statement( - " {0}_id = {0}_index[id]"_format(naming::NODE_AREA_VARIABLE))); + fmt::format(" {0}_id = {0}_index[id]", naming::NODE_AREA_VARIABLE))); } // update all ionic currents now @@ -941,22 +941,22 @@ void CodegenLLVMHelperVisitor::print_nrn_cur_non_conductance_kernel( for (const auto& var: ion.writes) { if (ion.is_ionic_current(var)) { // variable on the lhs - std::string lhs{"{}di{}dv"_format(naming::ION_VARNAME_PREFIX, ion.name)}; + std::string lhs{fmt::format("{}di{}dv", naming::ION_VARNAME_PREFIX, ion.name)}; // expression on the rhs - std::string rhs{"(di{}-{})/0.001"_format(ion.name, var)}; + std::string rhs{fmt::format("(di{}-{})/0.001", ion.name, var)}; if (info.point_process) { - rhs += "*1.e2/{0}[{0}_id]"_format(naming::NODE_AREA_VARIABLE); + rhs += fmt::format("*1.e2/{0}[{0}_id]", naming::NODE_AREA_VARIABLE); } // load the index for lhs variable int_variables.emplace_back(lhs + "_id"); - std::string index_statement{"{}_id = {}_index[id]"_format(lhs, lhs)}; + std::string index_statement{fmt::format("{}_id = {}_index[id]", lhs, lhs)}; index_statements.emplace_back(visitor::create_statement(index_statement)); // add statement that actually updates the - body_statements.emplace_back( - visitor::create_statement("{0}[{0}_id] = {0}[{0}_id] + {1}"_format(lhs, rhs))); + body_statements.emplace_back(visitor::create_statement( + fmt::format("{0}[{0}_id] = {0}[{0}_id] + {1}", lhs, rhs))); } } } @@ -989,9 +989,10 @@ void CodegenLLVMHelperVisitor::visit_breakpoint_block(ast::BreakpointBlock& node /// prepare all function statements { /// access node index and corresponding voltage - index_statements.push_back( - visitor::create_statement("node_id = node_index[{}]"_format(naming::INDUCTION_VAR))); - body_statements.push_back(visitor::create_statement("v = {}[node_id]"_format(VOLTAGE_VAR))); + index_statements.push_back(visitor::create_statement( + fmt::format("node_id = node_index[{}]", naming::INDUCTION_VAR))); + body_statements.push_back( + visitor::create_statement(fmt::format("v = {}[node_id]", VOLTAGE_VAR))); /// read ion variables ion_read_statements(BlockType::Equation, @@ -1020,7 +1021,7 @@ void CodegenLLVMHelperVisitor::visit_breakpoint_block(ast::BreakpointBlock& node if (info.point_process) { double_variables.emplace_back("mfactor"); body_statements.emplace_back(visitor::create_statement( - "mfactor = 1.e2/{0}[{0}_id]"_format(naming::NODE_AREA_VARIABLE))); + fmt::format("mfactor = 1.e2/{0}[{0}_id]", naming::NODE_AREA_VARIABLE))); body_statements.emplace_back(visitor::create_statement("g = g*mfactor")); body_statements.emplace_back(visitor::create_statement("rhs = rhs*mfactor")); } @@ -1046,9 +1047,9 @@ void CodegenLLVMHelperVisitor::visit_breakpoint_block(ast::BreakpointBlock& node stringutils::remove_character(d_op, '='); body_statements.emplace_back(visitor::create_statement( - "vec_rhs[node_id] = vec_rhs[node_id] {} rhs"_format(rhs_op))); - body_statements.emplace_back( - visitor::create_statement("vec_d[node_id] = vec_d[node_id] {} g"_format(d_op))); + fmt::format("vec_rhs[node_id] = vec_rhs[node_id] {} rhs", rhs_op))); + body_statements.emplace_back(visitor::create_statement( + fmt::format("vec_d[node_id] = vec_d[node_id] {} g", d_op))); } } diff --git a/src/codegen/llvm/codegen_llvm_helper_visitor.hpp b/src/codegen/llvm/codegen_llvm_helper_visitor.hpp index ab554521fc..50ef1d6b8d 100644 --- a/src/codegen/llvm/codegen_llvm_helper_visitor.hpp +++ b/src/codegen/llvm/codegen_llvm_helper_visitor.hpp @@ -24,7 +24,6 @@ namespace nmodl { namespace codegen { -using namespace fmt::literals; typedef std::vector> CodegenFunctionVector; /** @@ -66,7 +65,7 @@ struct InstanceVarHelper { const auto& vars = instance->get_codegen_vars(); auto it = find_variable(vars, name); if (it == vars.end()) { - throw std::runtime_error("Can not find variable with name {}"_format(name)); + throw std::runtime_error(fmt::format("Can not find variable with name {}", name)); } return *it; } @@ -76,7 +75,8 @@ struct InstanceVarHelper { const auto& vars = instance->get_codegen_vars(); auto it = find_variable(vars, name); if (it == vars.end()) { - throw std::runtime_error("Can not find codegen variable with name {}"_format(name)); + throw std::runtime_error( + fmt::format("Can not find codegen variable with name {}", name)); } return (it - vars.begin()); } diff --git a/src/codegen/llvm/codegen_llvm_visitor.cpp b/src/codegen/llvm/codegen_llvm_visitor.cpp index 1516f23634..c11ba6cc3b 100644 --- a/src/codegen/llvm/codegen_llvm_visitor.cpp +++ b/src/codegen/llvm/codegen_llvm_visitor.cpp @@ -933,7 +933,7 @@ void CodegenLLVMVisitor::visit_program(const ast::Program& node) { void CodegenLLVMVisitor::print_mechanism_range_var_structure() { printer->add_newline(2); printer->add_line("/** Instance Struct passed as argument to LLVM IR kernels */"); - printer->start_block("struct {} "_format(instance_struct())); + printer->start_block(fmt::format("struct {} ", instance_struct())); for (const auto& variable: instance_var_helper.instance->get_codegen_vars()) { auto is_pointer = variable->get_is_pointer(); auto name = to_nmodl(variable->get_name()); @@ -942,10 +942,14 @@ void CodegenLLVMVisitor::print_mechanism_range_var_structure() { auto pointer = is_pointer ? "*" : ""; auto var_name = variable->get_node_name(); switch (nmodl_type) { -#define DISPATCH(type, c_type) \ - case type: \ - printer->add_line("{}{}{} {}{};"_format( \ - qualifier, c_type, pointer, is_pointer ? ptr_type_qualifier() : "", var_name)); \ +#define DISPATCH(type, c_type) \ + case type: \ + printer->add_line(fmt::format("{}{}{} {}{};", \ + qualifier, \ + c_type, \ + pointer, \ + is_pointer ? ptr_type_qualifier() : "", \ + var_name)); \ break; DISPATCH(ast::AstNodeType::DOUBLE, "double"); @@ -972,7 +976,8 @@ void CodegenLLVMVisitor::print_instance_variable_setup() { printer->add_newline(2); printer->add_line("/** initialize mechanism instance variables */"); printer->start_block("static inline void setup_instance(NrnThread* nt, Memb_list* ml) "); - printer->add_line("{0}* inst = ({0}*) mem_alloc(1, sizeof({0}));"_format(instance_struct())); + printer->add_line( + fmt::format("{0}* inst = ({0}*) mem_alloc(1, sizeof({0}));", instance_struct())); if (channel_task_dependency_enabled() && !info.codegen_shadow_variables.empty()) { printer->add_line("setup_shadow_vectors(inst, ml);"); } @@ -995,12 +1000,12 @@ void CodegenLLVMVisitor::print_instance_variable_setup() { auto name = var->get_name(); auto range_var_type = get_range_var_float_type(var); if (float_type == range_var_type) { - auto variable = "ml->data+{}{}"_format(id, stride); + auto variable = fmt::format("ml->data+{}{}", id, stride); auto device_variable = get_variable_device_pointer(variable, float_type_pointer); - printer->add_line("inst->{} = {};"_format(name, device_variable)); + printer->add_line(fmt::format("inst->{} = {};", name, device_variable)); } else { - printer->add_line("inst->{} = setup_range_variable(ml->data+{}{}, pnodecount);"_format( - name, id, stride)); + printer->add_line(fmt::format( + "inst->{} = setup_range_variable(ml->data+{}{}, pnodecount);", name, id, stride)); variables_to_free.push_back(name); } id += var->get_length(); @@ -1021,7 +1026,7 @@ void CodegenLLVMVisitor::print_instance_variable_setup() { type = info.artificial_cell ? "void*" : float_type_pointer; } auto device_variable = get_variable_device_pointer(variable, type); - printer->add_line("inst->{} = {};"_format(name, device_variable)); + printer->add_line(fmt::format("inst->{} = {};", name, device_variable)); } int index_id = 0; @@ -1030,7 +1035,7 @@ void CodegenLLVMVisitor::print_instance_variable_setup() { std::string var_name = int_var.symbol->get_name() + "_index"; // Create for loop that instantiates the ion__index with // indexes[*pdnodecount] - printer->add_line("inst->{} = indexes+{}*pnodecount;"_format(var_name, index_id)); + printer->add_line(fmt::format("inst->{} = indexes+{}*pnodecount;", var_name, index_id)); index_id++; } @@ -1047,21 +1052,21 @@ void CodegenLLVMVisitor::print_instance_variable_setup() { printer->add_line(fmt::format("inst->{} = nt->_shadow_d;", naming::NTHREAD_D_SHADOW)); // Setup global variables - printer->add_line("inst->{0} = nt->{0};"_format(naming::NTHREAD_T_VARIABLE)); - printer->add_line("inst->{0} = nt->{0};"_format(naming::NTHREAD_DT_VARIABLE)); - printer->add_line("inst->{0} = {0};"_format(naming::CELSIUS_VARIABLE)); - printer->add_line("inst->{0} = {0};"_format(naming::SECOND_ORDER_VARIABLE)); - printer->add_line("inst->{} = ml->nodecount;"_format(naming::MECH_NODECOUNT_VAR)); + printer->add_line(fmt::format("inst->{0} = nt->{0};", naming::NTHREAD_T_VARIABLE)); + printer->add_line(fmt::format("inst->{0} = nt->{0};", naming::NTHREAD_DT_VARIABLE)); + printer->add_line(fmt::format("inst->{0} = {0};", naming::CELSIUS_VARIABLE)); + printer->add_line(fmt::format("inst->{0} = {0};", naming::SECOND_ORDER_VARIABLE)); + printer->add_line(fmt::format("inst->{} = ml->nodecount;", naming::MECH_NODECOUNT_VAR)); printer->add_line("ml->instance = inst;"); printer->end_block(3); printer->add_line("/** cleanup mechanism instance variables */"); printer->start_block("static inline void cleanup_instance(Memb_list* ml) "); - printer->add_line("{0}* inst = ({0}*) ml->instance;"_format(instance_struct())); + printer->add_line(fmt::format("{0}* inst = ({0}*) ml->instance;", instance_struct())); if (range_variable_setup_required()) { for (auto& var: variables_to_free) { - printer->add_line("mem_free((void*)inst->{});"_format(var)); + printer->add_line(fmt::format("mem_free((void*)inst->{});", var)); } } printer->add_line("mem_free((void*)inst);"); @@ -1071,7 +1076,7 @@ void CodegenLLVMVisitor::print_instance_variable_setup() { CodegenLLVMVisitor::ParamVector CodegenLLVMVisitor::get_compute_function_parameter() { auto params = ParamVector(); params.emplace_back(param_type_qualifier(), - "{}*"_format(instance_struct()), + fmt::format("{}*", instance_struct()), ptr_type_qualifier(), "inst"); return params; @@ -1082,18 +1087,19 @@ void CodegenLLVMVisitor::print_backend_compute_routine_decl() { auto compute_function = compute_method_name(BlockType::Initial); printer->add_newline(2); - printer->add_line("extern void {}({});"_format(compute_function, get_parameter_str(params))); + printer->add_line( + fmt::format("extern void {}({});", compute_function, get_parameter_str(params))); if (info.nrn_cur_required()) { compute_function = compute_method_name(BlockType::Equation); printer->add_line( - "extern void {}({});"_format(compute_function, get_parameter_str(params))); + fmt::format("extern void {}({});", compute_function, get_parameter_str(params))); } if (info.nrn_state_required()) { compute_function = compute_method_name(BlockType::State); printer->add_line( - "extern void {}({});"_format(compute_function, get_parameter_str(params))); + fmt::format("extern void {}({});", compute_function, get_parameter_str(params))); } } @@ -1105,10 +1111,10 @@ void CodegenLLVMVisitor::print_wrapper_routine(const std::string& wrapper_functi auto compute_function = compute_method_name(type); printer->add_newline(2); - printer->start_block("void {}({})"_format(function_name, args)); + printer->start_block(fmt::format("void {}({})", function_name, args)); printer->add_line("int nodecount = ml->nodecount;"); // clang-format off - printer->add_line("{0}* {1}inst = ({0}*) ml->instance;"_format(instance_struct(), ptr_type_qualifier())); + printer->add_line(fmt::format("{0}* {1}inst = ({0}*) ml->instance;", instance_struct(), ptr_type_qualifier())); // clang-format on if (type == BlockType::Initial) { @@ -1121,7 +1127,7 @@ void CodegenLLVMVisitor::print_wrapper_routine(const std::string& wrapper_functi printer->add_newline(); } - printer->add_line("{}(inst);"_format(compute_function)); + printer->add_line(fmt::format("{}(inst);", compute_function)); printer->end_block(); printer->add_newline(); } diff --git a/src/codegen/llvm/replace_with_lib_functions.cpp b/src/codegen/llvm/replace_with_lib_functions.cpp index 750e2c2318..07d6dd8f04 100644 --- a/src/codegen/llvm/replace_with_lib_functions.cpp +++ b/src/codegen/llvm/replace_with_lib_functions.cpp @@ -174,8 +174,10 @@ bool ReplaceWithLibdevice::replace_call(CallInst& call_inst) { {"llvm.pow.f64", "__nv_pow"}, {"llvm.log.f32", "__nv_logf"}, {"llvm.log.f64", "__nv_log"}, - {"llvm.fabs.f32", "__nv_fabsf"}, - {"llvm.fabs.f64", "__nv_fabs"}}; + {"llvm.fabs.f32", + "__nv_fabsf"}, + {"llvm.fabs.f64", + "__nv_fabs"}}; // If replacement is not supported, abort. std::string old_name = function->getName().str(); diff --git a/src/main.cpp b/src/main.cpp index e3e9e32929..23428eff79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -102,7 +102,9 @@ int main(int argc, const char* argv[]) { host_opt->add_flag("--c", cfg.c_backend, fmt::format("C/C++ backend ({})", cfg.c_backend)) ->ignore_case(); host_opt - ->add_flag("--omp", cfg.omp_backend, fmt::format("C/C++ backend with OpenMP ({})", cfg.omp_backend)) + ->add_flag("--omp", + cfg.omp_backend, + fmt::format("C/C++ backend with OpenMP ({})", cfg.omp_backend)) ->ignore_case(); host_opt ->add_flag("--ispc", @@ -201,17 +203,17 @@ int main(int argc, const char* argv[]) { auto llvm_opt = app.add_subcommand("llvm", "LLVM code generation option")->ignore_case(); auto llvm_ir_opt = llvm_opt->add_flag("--ir", cfg.llvm_ir, - "Generate LLVM IR ({})"_format(cfg.llvm_ir))->ignore_case(); + fmt::format("Generate LLVM IR ({})", cfg.llvm_ir))->ignore_case(); llvm_ir_opt->required(true); llvm_opt->add_flag("--no-debug", cfg.llvm_no_debug, - "Disable debug information ({})"_format(cfg.llvm_no_debug))->ignore_case(); + fmt::format("Disable debug information ({})", cfg.llvm_no_debug))->ignore_case(); llvm_opt->add_option("--opt-level-ir", cfg.llvm_opt_level_ir, - "LLVM IR optimisation level (O{})"_format(cfg.llvm_opt_level_ir))->ignore_case()->check(CLI::IsMember({"0", "1", "2", "3"})); + fmt::format("LLVM IR optimisation level (O{})", cfg.llvm_opt_level_ir))->ignore_case()->check(CLI::IsMember({"0", "1", "2", "3"})); llvm_opt->add_flag("--single-precision", cfg.llvm_float_type, - "Use single precision floating-point types ({})"_format(cfg.llvm_float_type))->ignore_case(); + fmt::format("Use single precision floating-point types ({})", cfg.llvm_float_type))->ignore_case(); llvm_opt->add_option("--fmf", cfg.llvm_fast_math_flags, "Fast math flags for floating-point optimizations (none)")->check(CLI::IsMember({"afn", "arcp", "contract", "ninf", "nnan", "nsz", "reassoc", "fast"})); @@ -224,11 +226,11 @@ int main(int argc, const char* argv[]) { "Name of CPU platform to use")->ignore_case(); auto simd_math_library_opt = cpu_opt->add_option("--math-library", cfg.llvm_math_library, - "Math library for SIMD code generation ({})"_format(cfg.llvm_math_library)); + fmt::format("Math library for SIMD code generation ({})", cfg.llvm_math_library)); simd_math_library_opt->check(CLI::IsMember({"Accelerate", "libmvec", "libsystem_m", "MASSV", "SLEEF", "SVML", "none"})); cpu_opt->add_option("--vector-width", cfg.llvm_vector_width, - "Explicit vectorization width for IR generation ({})"_format(cfg.llvm_vector_width))->ignore_case(); + fmt::format("Explicit vectorization width for IR generation ({})", cfg.llvm_vector_width))->ignore_case(); auto gpu_opt = app.add_subcommand("gpu", "LLVM GPU option")->ignore_case(); gpu_opt->needs(llvm_opt); @@ -241,7 +243,7 @@ int main(int argc, const char* argv[]) { "Name of target architecture to use")->ignore_case(); auto gpu_math_library_opt = gpu_opt->add_option("--math-library", cfg.llvm_math_library, - "Math library for GPU code generation ({})"_format(cfg.llvm_math_library)); + fmt::format("Math library for GPU code generation ({})", cfg.llvm_math_library)); gpu_math_library_opt->check(CLI::IsMember({"libdevice"})); // Allow only one platform at a time. @@ -253,25 +255,25 @@ int main(int argc, const char* argv[]) { benchmark_opt->needs(llvm_opt); benchmark_opt->add_flag("--run", llvm_benchmark, - "Run LLVM benchmark ({})"_format(llvm_benchmark))->ignore_case(); + fmt::format("Run LLVM benchmark ({})", llvm_benchmark))->ignore_case(); benchmark_opt->add_option("--opt-level-codegen", cfg.llvm_opt_level_codegen, - "Machine code optimisation level (O{})"_format(cfg.llvm_opt_level_codegen))->ignore_case()->check(CLI::IsMember({"0", "1", "2", "3"})); + fmt::format("Machine code optimisation level (O{})", cfg.llvm_opt_level_codegen))->ignore_case()->check(CLI::IsMember({"0", "1", "2", "3"})); benchmark_opt->add_option("--libs", cfg.shared_lib_paths, "Shared libraries to link IR against") ->ignore_case() ->check(CLI::ExistingFile); benchmark_opt->add_option("--instance-size", instance_size, - "Instance struct size ({})"_format(instance_size))->ignore_case(); + fmt::format("Instance struct size ({})", instance_size))->ignore_case(); benchmark_opt->add_option("--repeat", num_experiments, - "Number of experiments for benchmarking ({})"_format(num_experiments))->ignore_case(); + fmt::format("Number of experiments for benchmarking ({})", num_experiments))->ignore_case(); benchmark_opt->add_option("--grid-dim-x", llvm_cuda_grid_dim_x, - "Grid dimension X ({})"_format(llvm_cuda_grid_dim_x))->ignore_case(); + fmt::format("Grid dimension X ({})", llvm_cuda_grid_dim_x))->ignore_case(); benchmark_opt->add_option("--block-dim-x", llvm_cuda_block_dim_x, - "Block dimension X ({})"_format(llvm_cuda_block_dim_x))->ignore_case(); + fmt::format("Block dimension X ({})", llvm_cuda_block_dim_x))->ignore_case(); #endif // clang-format on diff --git a/test/benchmark/cuda_driver.cpp b/test/benchmark/cuda_driver.cpp index cecc97b35d..b65caeff0d 100644 --- a/test/benchmark/cuda_driver.cpp +++ b/test/benchmark/cuda_driver.cpp @@ -20,8 +20,6 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Target/TargetMachine.h" -using fmt::literals::operator""_format; - namespace nmodl { namespace runner { @@ -47,7 +45,7 @@ void CUDADriver::link_libraries(llvm::Module& module, BenchmarkInfo* benchmark_i parseBitcodeFile(libdevice_file_memory_buffer->get()->getMemBufferRef(), module.getContext()); if (std::error_code error = errorToErrorCode(libdevice_expected_module.takeError())) { - throw std::runtime_error("Error reading bitcode: {}"_format(error.message())); + throw std::runtime_error(fmt::format("Error reading bitcode: {}", error.message())); } linker.linkInModule(std::move(libdevice_expected_module.get()), llvm::Linker::LinkOnlyNeeded); @@ -112,7 +110,7 @@ void CUDADriver::init(const codegen::Platform& platform, BenchmarkInfo* benchmar char name[128]; checkCudaErrors(cuDeviceGetName(name, 128, device)); device_info.name = name; - logger->info("Using CUDA Device [0]: {}"_format(device_info.name)); + logger->info(fmt::format("Using CUDA Device [0]: {}", device_info.name)); // Get the compute capability of the device that is actually going to be used to run the kernel checkCudaErrors(cuDeviceGetAttribute(&device_info.compute_version_major, @@ -121,8 +119,9 @@ void CUDADriver::init(const codegen::Platform& platform, BenchmarkInfo* benchmar checkCudaErrors(cuDeviceGetAttribute(&device_info.compute_version_minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, device)); - logger->info("Device Compute Capability: {}.{}"_format(device_info.compute_version_major, - device_info.compute_version_minor)); + logger->info(fmt::format("Device Compute Capability: {}.{}", + device_info.compute_version_major, + device_info.compute_version_minor)); if (device_info.compute_version_major < 2) { throw std::runtime_error("ERROR: Device 0 is not SM 2.0 or greater"); } @@ -185,10 +184,10 @@ void CUDADriver::init(const codegen::Platform& platform, BenchmarkInfo* benchmar auto cuda_jit_ret = cuModuleLoadDataEx( &cudaModule, ptx_compiled_module.c_str(), jitNumOptions, jitOptions, jitOptVals); if (!std::string(jitLogBuffer).empty()) { - logger->info("CUDA JIT INFO LOG: {}"_format(std::string(jitLogBuffer))); + logger->info(fmt::format("CUDA JIT INFO LOG: {}", std::string(jitLogBuffer))); } if (!std::string(jitErrorLogBuffer).empty()) { - logger->info("CUDA JIT ERROR LOG: {}"_format(std::string(jitErrorLogBuffer))); + logger->info(fmt::format("CUDA JIT ERROR LOG: {}", std::string(jitErrorLogBuffer))); } delete[] jitOptions; delete[] jitOptVals;