Skip to content

Commit

Permalink
COV-* Fix misc Coverity defects (#8614)
Browse files Browse the repository at this point in the history
Signed-off-by: Soren Soe <[email protected]>
  • Loading branch information
stsoe authored Nov 23, 2024
1 parent df6db61 commit 4ca0a2b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/runtime_src/core/common/api/aie/xrt_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ xrtAIEStartProfiling(xrtDeviceHandle handle, int option, const char *port1Name,
const std::string port2 = port2Name ? port2Name : "";
auto hdl = event->start(option, port1, port2, value);
if (hdl != xrt::aie::profiling_impl::invalid_handle) {
profiling_cache[hdl] = event;
profiling_cache[hdl] = std::move(event);
return hdl;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/common/api/xrt_bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class bo_impl
}

// Managed imported handle
bo_impl(device_type dev, xrt_core::shared_handle::export_handle ehdl)
bo_impl(const device_type& dev, xrt_core::shared_handle::export_handle ehdl)
: bo_impl(dev, pid_type{0}, ehdl)
{}

Expand Down
23 changes: 14 additions & 9 deletions src/runtime_src/core/common/api/xrt_hw_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
// This trace point measures the time to tear down a hw context on the device
XRT_TRACE_POINT_SCOPE(xrt_hw_context_dtor);

// finish_flush_device should only be called when the underlying
// hw_context_impl is destroyed. The xdp::update_device cannot exist
// in the hw_context_impl constructor because an existing
// shared pointer must already exist to call get_shared_ptr(),
// which is not true at that time.
xrt_core::xdp::finish_flush_device(this);

// Reset within scope of dtor for trace point to measure time to reset
m_hdl.reset();
try {
// finish_flush_device should only be called when the underlying
// hw_context_impl is destroyed. The xdp::update_device cannot exist
// in the hw_context_impl constructor because an existing
// shared pointer must already exist to call get_shared_ptr(),
// which is not true at that time.
xrt_core::xdp::finish_flush_device(this);

// Reset within scope of dtor for trace point to measure time to reset
m_hdl.reset();
}
catch (...) {
// ignore, dtor cannot throw
}
}

hw_context_impl() = delete;
Expand Down
16 changes: 9 additions & 7 deletions src/runtime_src/core/common/api/xrt_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ class ip_context
// collect the memory connections for each IP argument
for (const auto& arg : ip.get_args()) {
auto argidx = arg.get_index();
if (argidx == xrt_core::xclbin::kernel_argument::no_index)
throw xrt_core::error("Invalid kernel argument index in xclbin");

for (const auto& mem : arg.get_mems()) {
auto memidx = mem.get_index();
Expand Down Expand Up @@ -587,7 +589,7 @@ class ip_context
return ipctx;
}

[[nodiscard]] access_mode
access_mode
get_access_mode() const
{
return cu_access_mode(m_hwctx.get_mode());
Expand All @@ -598,31 +600,31 @@ class ip_context
close()
{}

[[nodiscard]] size_t
size_t
get_size() const
{
return m_size;
}

[[nodiscard]] uint64_t
uint64_t
get_address() const
{
return m_address;
}

[[nodiscard]] xrt_core::cuidx_type
xrt_core::cuidx_type
get_index() const
{
return m_idx;
}

[[nodiscard]] unsigned int
unsigned int
get_cuidx() const
{
return m_idx.domain_index; // index used for execution cumask
}

[[nodiscard]] slot_id
slot_id
get_slot() const
{
auto hwctx_hdl = static_cast<xrt_core::hwctx_handle*>(m_hwctx);
Expand All @@ -639,7 +641,7 @@ class ip_context
// Get default memory bank for argument at specified index The
// default memory bank is the connection with the highest group
// connectivity index
[[nodiscard]] int32_t
int32_t
arg_memidx(size_t argidx) const
{
return m_args.get_arg_memidx(argidx);
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/common/runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class recipe
read_xclbin(const boost::property_tree::ptree& pt, const artifacts::repo& repo)
{
auto path = pt.get<std::string>("xclbin_path");
auto data = repo.get(path);
auto& data = repo.get(path);
return xrt::xclbin{data};
}

Expand Down Expand Up @@ -551,7 +551,7 @@ class recipe
, m_argidx{pt.get<int>("argidx")}
, m_xrt_bo{create_xrt_bo(m_buffer, m_offset, m_size)}
{
XRT_DEBUGF("recipe::execution::run::argument(%s, %d, %d, %d) bound(%s)\n",
XRT_DEBUGF("recipe::execution::run::argument(%s, %lu, %lu, %d) bound(%s)\n",
m_buffer.get_name().c_str(), m_offset, m_size, m_argidx, m_xrt_bo ? "true" : "false");
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/xocl/api/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ action_migrate_memobjects(size_t num, const cl_mem* memobjs, cl_mem_migration_fl
throw_if_error();
std::vector<cl_mem> mo(memobjs,memobjs+num);

return [mo,flags](xocl::event* ev) {
return [mo = std::move(mo), flags](xocl::event* ev) {
XOCL_DEBUG(std::cout,"launching migrate DMA event(",ev->get_uid(),")\n");
auto command_queue = ev->get_command_queue();
auto device = command_queue->get_device();
Expand Down
26 changes: 13 additions & 13 deletions src/runtime_src/xocl/api/printf/rt_printf_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,70 +388,70 @@ PrintfArg::PrintfArg(double val)
{
}

PrintfArg::PrintfArg(std::vector<int8_t> vec)
PrintfArg::PrintfArg(const std::vector<int8_t>& vec)
: m_typeInfo(AT_INTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(intVec));
}

PrintfArg::PrintfArg(std::vector<uint8_t> vec)
PrintfArg::PrintfArg(const std::vector<uint8_t>& vec)
: m_typeInfo(AT_UINTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(uintVec));
}

PrintfArg::PrintfArg(std::vector<int16_t> vec)
PrintfArg::PrintfArg(const std::vector<int16_t>& vec)
: m_typeInfo(AT_INTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(intVec));
}

PrintfArg::PrintfArg(std::vector<uint16_t> vec)
PrintfArg::PrintfArg(const std::vector<uint16_t>& vec)
: m_typeInfo(AT_UINTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(uintVec));
}

PrintfArg::PrintfArg(std::vector<int32_t> vec)
PrintfArg::PrintfArg(const std::vector<int32_t>& vec)
: m_typeInfo(AT_INTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(intVec));
}

PrintfArg::PrintfArg(std::vector<uint32_t> vec)
PrintfArg::PrintfArg(const std::vector<uint32_t>& vec)
: m_typeInfo(AT_UINTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(uintVec));
}

PrintfArg::PrintfArg(std::vector<int64_t> vec)
PrintfArg::PrintfArg(const std::vector<int64_t>& vec)
: m_typeInfo(AT_INTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(intVec));
}

PrintfArg::PrintfArg(std::vector<uint64_t> vec)
PrintfArg::PrintfArg(const std::vector<uint64_t>& vec)
: m_typeInfo(AT_UINTVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(uintVec));
}

PrintfArg::PrintfArg(std::vector<float> vec)
PrintfArg::PrintfArg(const std::vector<float>& vec)
: m_typeInfo(AT_FLOATVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
std::copy(vec.begin(), vec.end(), std::back_inserter(floatVec));
}

PrintfArg::PrintfArg(std::vector<double> vec)
PrintfArg::PrintfArg(const std::vector<double>& vec)
: m_typeInfo(AT_FLOATVEC), ptr(nullptr)
, int_arg(0), uint_arg(0), float_arg(0.0)
{
Expand Down Expand Up @@ -1005,7 +1005,7 @@ PrintfArg BufferPrintf::buildArg(int bufIdx, ConversionSpec& conversion) const

/////////////////////////////////////////////////////////////////////////

std::string convertArg(PrintfArg& arg, ConversionSpec& conversion)
std::string convertArg(const PrintfArg& arg, const ConversionSpec& conversion)
{
std::string retval = "";
char formatStr[32];
Expand Down Expand Up @@ -1116,7 +1116,7 @@ std::string convertArg(PrintfArg& arg, ConversionSpec& conversion)
return retval;
}

std::string string_printf(const std::string& formatStr, std::vector<PrintfArg> args)
std::string string_printf(const std::string& formatStr, const std::vector<PrintfArg>& args)
{
std::vector<ConversionSpec> specVec;
std::vector<std::string> splitVec;
Expand All @@ -1142,7 +1142,7 @@ std::string string_printf(const std::string& formatStr, std::vector<PrintfArg> a
oss << splitVec[0];
}
for ( size_t idx = 1; idx < splitVec.size(); ++idx ) {
PrintfArg& arg = args[idx-1];
auto& arg = args[idx-1];
ConversionSpec& conversion = specVec[idx-1];
oss << convertArg(arg, conversion);
oss << splitVec[idx];
Expand Down
22 changes: 11 additions & 11 deletions src/runtime_src/xocl/api/printf/rt_printf_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ struct PrintfArg
PrintfArg(int64_t val);
PrintfArg(uint64_t val);
PrintfArg(double val);
PrintfArg(std::vector<int8_t> vec);
PrintfArg(std::vector<uint8_t> vec);
PrintfArg(std::vector<int16_t> vec);
PrintfArg(std::vector<uint16_t> vec);
PrintfArg(std::vector<int32_t> vec);
PrintfArg(std::vector<uint32_t> vec);
PrintfArg(std::vector<int64_t> vec);
PrintfArg(std::vector<uint64_t> vec);
PrintfArg(std::vector<float> vec);
PrintfArg(std::vector<double> vec);
PrintfArg(const std::vector<int8_t>& vec);
PrintfArg(const std::vector<uint8_t>& vec);
PrintfArg(const std::vector<int16_t>& vec);
PrintfArg(const std::vector<uint16_t>& vec);
PrintfArg(const std::vector<int32_t>& vec);
PrintfArg(const std::vector<uint32_t>& vec);
PrintfArg(const std::vector<int64_t>& vec);
PrintfArg(const std::vector<uint64_t>& vec);
PrintfArg(const std::vector<float>& vec);
PrintfArg(const std::vector<double>& vec);

TypeInfo m_typeInfo;
void *ptr;
Expand Down Expand Up @@ -324,7 +324,7 @@ std::string convertArg(PrintfArg& arg, ConversionSpec& conversion);
// Given format string and args, create and return a string (similar to sprintf).
// This exercises the round trip internal printf and is used to test breaking down
// a format and printing arguments.
std::string string_printf(const std::string& formatStr, std::vector<PrintfArg> args);
std::string string_printf(const std::string& formatStr, const std::vector<PrintfArg>& args);

// Throws an exception with the given error message. Put as a utility function
// because I am not sure on the exception throwing and error reporting standards
Expand Down

0 comments on commit 4ca0a2b

Please sign in to comment.