Commit 7ba86767 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Unpack List<KernelSignature> from HetMap



Iterate the list of function pointers ==> construct KernelSignature

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 1ccdb172
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -437,6 +437,31 @@ void QCORSyntaxHandler::GetReplacement(
                              << kernel_signature_var_name << "("
                              << new_var_name << ");\n";
        arg_ctor_list.emplace_back(kernel_signature_var_name);
      } else if (program_arg_types[i].rfind("std::vector<KernelSignature<",
                                            0) == 0) {
        // This is a list of KernelSignatures argument.
        // The one in HetMap is the vector of function pointers represented as a
        // hex string.
        const std::string new_var_name =
            "__temp_kernel_ptr_vector_var__" + std::to_string(var_counter++);
        // Retrieve the list of function pointer from the HetMap
        ref_type_copy_decl_ss << "auto " << new_var_name
                              << " = args.get<std::vector<std::string>>(\""
                              << program_parameters[i] << "\");\n";

        const std::string list_kernel_signature_var_name =
            "__temp_kernel_signature_var__" + std::to_string(var_counter++);
        // Declare the vector of kernel signatures
        ref_type_copy_decl_ss << program_arg_types[i] << " "
                              << list_kernel_signature_var_name << ";\n";
        // Construct the list from function pointers
        ref_type_copy_decl_ss << "std::vector<void*> temp_fn_ptrs(" << new_var_name << ".size());\n";
        ref_type_copy_decl_ss << "int fn_idx = 0;\n";
        ref_type_copy_decl_ss << "for (const auto& ptr_str: " << new_var_name << ") {\n";
        ref_type_copy_decl_ss << "temp_fn_ptrs[fn_idx] = (void *) strtoull(ptr_str.c_str(), nullptr, 16);\n";
        ref_type_copy_decl_ss <<  list_kernel_signature_var_name << ".emplace_back(temp_fn_ptrs[fn_idx++]);\n";
        ref_type_copy_decl_ss << "}\n";
        arg_ctor_list.emplace_back(list_kernel_signature_var_name);
      } else {
        // Otherwise, just unpack the arg inline in the ctor call.
        std::stringstream ss;