Skip to content

Runtime Coverity fixes #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions fuzz_testing/test/acl_auto_configure_fuzz_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,32 @@ TEST(auto_configure, simple) {
const auto kernel15_dev_global2 =
m_device_def.autodiscovery_def.device_global_mem_defs.find(
"kernel15_dev_global2");
CHECK(kernel15_dev_global !=
m_device_def.autodiscovery_def.device_global_mem_defs.end());
CHECK(kernel15_dev_global2 !=
m_device_def.autodiscovery_def.device_global_mem_defs.end());
CHECK_EQUAL(4096, kernel15_dev_global->second.address);
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
kernel15_dev_global->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming);
CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse);
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
kernel15_dev_global2->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming);
CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse);
bool kernel15_dev_global_found =
kernel15_dev_global !=
m_device_def.autodiscovery_def.device_global_mem_defs.end();
bool kernel15_dev_global2_found =
kernel15_dev_global2 !=
m_device_def.autodiscovery_def.device_global_mem_defs.end();
CHECK(kernel15_dev_global_found);
CHECK(kernel15_dev_global2_found);
if (kernel15_dev_global_found) {
CHECK_EQUAL(4096, kernel15_dev_global->second.address);
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
kernel15_dev_global->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming);
CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse);
}
if (kernel15_dev_global2_found) {
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
kernel15_dev_global2->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming);
CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse);
}

// Check a second parsing.
// It should allocate a new string for the name.
Expand Down
2 changes: 1 addition & 1 deletion include/acl_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ typedef struct {
int (*close_devices)(cl_uint num_devices, const cl_device_id *devices);

/// Allocates USM host memory
void *(*host_alloc)(const std::vector<cl_device_id> devices, size_t size,
void *(*host_alloc)(const std::vector<cl_device_id> &devices, size_t size,
size_t alignment, mem_properties_t *properties,
int *error);

Expand Down
4 changes: 4 additions & 0 deletions include/acl_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class acl_suspend_lock_guard {
};
~acl_suspend_lock_guard() { mutex.resume_lock(lock_count); }

// Delete copy constructor and copy assignment
acl_suspend_lock_guard(const acl_suspend_lock_guard &) = delete;
acl_suspend_lock_guard &operator=(const acl_suspend_lock_guard &) = delete;

private:
int lock_count;
acl_mutex_wrapper_t &mutex;
Expand Down
5 changes: 5 additions & 0 deletions include/acl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ class acl_device_program_info_t {

~acl_device_program_info_t();

// Delete copy constructor and copy assignment
acl_device_program_info_t(const acl_device_program_info_t &) = delete;
acl_device_program_info_t &
operator=(const acl_device_program_info_t &) = delete;

cl_program program = nullptr; // Back pointer.
cl_device_id device = nullptr; // For what device? Shortcut only.

Expand Down
8 changes: 0 additions & 8 deletions lib/CppUTest/include/CppUTest/Failure.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ class EqualsFailure: public Failure

EqualsFailure(Utest*, const char* fileName, long lineNumber,
const SimpleString& expected, const SimpleString& actual);

private:
EqualsFailure(const EqualsFailure&);
EqualsFailure& operator=(const EqualsFailure&);
};

class ContainsFailure: public Failure
Expand All @@ -87,10 +83,6 @@ class ContainsFailure: public Failure

ContainsFailure(Utest*, const char* fileName, long lineNumber,
const SimpleString& expected, const SimpleString& actual);

private:
ContainsFailure(const ContainsFailure&);
ContainsFailure& operator=(const ContainsFailure&);
};

#endif
5 changes: 4 additions & 1 deletion lib/acl_threadsupport/test/acl_threadsupport_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ void *test_thread(void *) {
break;
acl_thread_yield();
}
if (threadtest_state == END_STATE) {
acl_mutex_lock(&mymutex);
const bool is_end_state = (threadtest_state == END_STATE);
acl_mutex_unlock(&mymutex);
if (is_end_state) {
return 0;
}
// CLIENT_STATE
Expand Down
1 change: 1 addition & 0 deletions lib/pkg_editor/src/pkg_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,7 @@ int acl_pkg_pack(const char *out_file, const char **input_files_dirs) {
fprintf(stderr, "acl_pkg_pack: Unable to initialize zlib for writing %s\n",
out_file);
fclose(of);
deflateEnd(&z_info.strm);
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/pkg_editor/test/pkg_editor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include "pkg_editor/pkg_editor.h"
#include <assert.h>
Expand Down Expand Up @@ -465,7 +466,7 @@ static bool is_same_tmpdir(const std::vector<fs::path> &files,
const fs::path &unpack_dir) {
return std::all_of(files.begin(), files.end(), [&](const fs::path &path) {
fs::path unpacked_file_path = unpack_dir / path;
return files_same(path, unpacked_file_path);
return files_same(path, std::move(unpacked_file_path));
});
}

Expand Down
39 changes: 18 additions & 21 deletions src/acl_auto_configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

// Internal headers.
Expand Down Expand Up @@ -402,7 +403,7 @@ read_global_mem_defs(const std::string &config_str,
counters.back() > 0) {
std::string temp;
result = read_string_counters(config_str, curr_pos, temp, counters);
can_access.push_back(temp);
can_access.push_back(std::move(temp));
}
}

Expand All @@ -427,16 +428,16 @@ read_global_mem_defs(const std::string &config_str,
global_mem_defs[i].num_global_banks = num_dimms;
global_mem_defs[i].config_addr =
static_cast<size_t>(configuration_address);
global_mem_defs[i].name = gmem_name;
global_mem_defs[i].name = std::move(gmem_name);
global_mem_defs[i].range.begin = reinterpret_cast<void *>(gmem_start);
global_mem_defs[i].range.next = reinterpret_cast<void *>(gmem_end);
global_mem_defs[i].type =
static_cast<acl_system_global_mem_type_t>(gmem_type);
global_mem_defs[i].burst_interleaved = burst_interleaved;
global_mem_defs[i].allocation_type = allocation_type;
global_mem_defs[i].primary_interface = primary_interface;
global_mem_defs[i].can_access_list = can_access;
global_mem_defs[i].id = gmem_id;
global_mem_defs[i].primary_interface = std::move(primary_interface);
global_mem_defs[i].can_access_list = std::move(can_access);
global_mem_defs[i].id = std::move(gmem_id);
}

// forward compatibility: bypassing remaining fields at the end of global
Expand Down Expand Up @@ -474,28 +475,24 @@ read_hostpipe_infos(const std::string &config_str,
counters.emplace_back(total_fields_hostpipes);
std::string name;

auto hostpipe_is_host_to_dev = 0U;
auto hostpipe_is_dev_to_host = 0U;
bool hostpipe_is_host_to_dev = false;
bool hostpipe_is_dev_to_host = false;
auto hostpipe_width = 0U;
auto hostpipe_max_buffer_depth = 0U;
result =
result && read_string_counters(config_str, curr_pos, name, counters) &&
read_uint_counters(config_str, curr_pos, hostpipe_is_host_to_dev,
read_bool_counters(config_str, curr_pos, hostpipe_is_host_to_dev,
counters) &&
read_uint_counters(config_str, curr_pos, hostpipe_is_dev_to_host,
read_bool_counters(config_str, curr_pos, hostpipe_is_dev_to_host,
counters) &&
read_uint_counters(config_str, curr_pos, hostpipe_width, counters) &&
read_uint_counters(config_str, curr_pos, hostpipe_max_buffer_depth,
counters);
// is_host_to_dev and is_dev_to_host are exclusive because of the enum
// Type
acl_hostpipe_info_t acl_hostpipe_info;
acl_hostpipe_info.name = name;
acl_hostpipe_info.is_host_to_dev = hostpipe_is_host_to_dev;
acl_hostpipe_info.is_dev_to_host = hostpipe_is_dev_to_host;
acl_hostpipe_info.data_width = hostpipe_width;
acl_hostpipe_info.max_buffer_depth = hostpipe_max_buffer_depth;
hostpipe_infos.push_back(acl_hostpipe_info);
hostpipe_infos.push_back(acl_hostpipe_info_t{
std::move(name), hostpipe_is_host_to_dev, hostpipe_is_dev_to_host,
hostpipe_width, hostpipe_max_buffer_depth});

/*****************************************************************
Since the introduction of autodiscovery forwards-compatibility,
Expand Down Expand Up @@ -883,7 +880,7 @@ static bool read_kernel_args(const std::string &config_str,
****************************************************************/

if (result) {
args[j].name = name;
args[j].name = std::move(name);
args[j].addr_space =
static_cast<acl_kernel_arg_addr_space_t>(addr_space_type);
args[j].access_qualifier =
Expand All @@ -893,14 +890,14 @@ static bool read_kernel_args(const std::string &config_str,
args[j].alignment = alignment;
args[j].aspace_number = aspace_id;
args[j].lmem_size_bytes = lmem_size_bytes;
args[j].type_name = type_name;
args[j].type_name = std::move(type_name);
args[j].type_qualifier =
static_cast<acl_kernel_arg_type_qualifier_t>(type_qualifier);
args[j].host_accessible = host_accessible;
args[j].pipe_channel_id = pipe_channel_id;
args[j].buffer_location = buffer_location;
args[j].pipe_channel_id = std::move(pipe_channel_id);
args[j].buffer_location = std::move(buffer_location);
args[j].streaming_arg_info_available = streaming_arg_info_available;
args[j].streaming_arg_info = streaming_arg_info;
args[j].streaming_arg_info = std::move(streaming_arg_info);
}
// forward compatibility: bypassing remaining fields at the end of
// arguments section
Expand Down
4 changes: 2 additions & 2 deletions src/acl_hal_mmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
void *acl_hal_mmd_shared_alloc(cl_device_id device, size_t size,
size_t alignment, mem_properties_t *properties,
int *error);
void *acl_hal_mmd_host_alloc(const std::vector<cl_device_id> devices,
void *acl_hal_mmd_host_alloc(const std::vector<cl_device_id> &devices,
size_t size, size_t alignment,
mem_properties_t *properties, int *error);
int acl_hal_mmd_free(cl_context context, void *mem);
Expand Down Expand Up @@ -3054,7 +3054,7 @@ void *acl_hal_mmd_shared_alloc(cl_device_id device, size_t size,
return result;
}

void *acl_hal_mmd_host_alloc(const std::vector<cl_device_id> devices,
void *acl_hal_mmd_host_alloc(const std::vector<cl_device_id> &devices,
size_t size, size_t alignment,
mem_properties_t *properties, int *error) {
// Note we do not support devices in the same context with different MMDs
Expand Down
4 changes: 3 additions & 1 deletion src/acl_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sstream>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

// External library headers.
Expand Down Expand Up @@ -1372,7 +1373,8 @@ l_register_hostpipes_to_program(acl_device_program_info_t *dev_prog,
host_pipe_info.m_binded_kernel = NULL;
host_pipe_info.size_buffered = 0;

dev_prog->program_hostpipe_map[hostpipe.logical_name] = host_pipe_info;
dev_prog->program_hostpipe_map[hostpipe.logical_name] =
std::move(host_pipe_info);
}

// Start from 2024.1, Runtime receives sideband signals information
Expand Down
44 changes: 26 additions & 18 deletions test/acl_auto_configure_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,32 @@ TEST(auto_configure, simple) {
const auto kernel15_dev_global2 =
m_device_def.autodiscovery_def.device_global_mem_defs.find(
"kernel15_dev_global2");
CHECK(kernel15_dev_global !=
m_device_def.autodiscovery_def.device_global_mem_defs.end());
CHECK(kernel15_dev_global2 !=
m_device_def.autodiscovery_def.device_global_mem_defs.end());
CHECK_EQUAL(4096, kernel15_dev_global->second.address);
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
kernel15_dev_global->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming);
CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse);
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
kernel15_dev_global2->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming);
CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse);
bool kernel15_dev_global_found =
kernel15_dev_global !=
m_device_def.autodiscovery_def.device_global_mem_defs.end();
bool kernel15_dev_global2_found =
kernel15_dev_global2 !=
m_device_def.autodiscovery_def.device_global_mem_defs.end();
CHECK(kernel15_dev_global_found);
CHECK(kernel15_dev_global2_found);
if (kernel15_dev_global_found) {
CHECK_EQUAL(4096, kernel15_dev_global->second.address);
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_NONE,
kernel15_dev_global->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global->second.can_skip_programming);
CHECK_EQUAL(false, kernel15_dev_global->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global->second.reset_on_reuse);
}
if (kernel15_dev_global2_found) {
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
CHECK_EQUAL(ACL_DEVICE_GLOBAL_HOST_ACCESS_WRITE_ONLY,
kernel15_dev_global2->second.host_access);
CHECK_EQUAL(false, kernel15_dev_global2->second.can_skip_programming);
CHECK_EQUAL(true, kernel15_dev_global2->second.implement_in_csr);
CHECK_EQUAL(false, kernel15_dev_global2->second.reset_on_reuse);
}

// Check a second parsing.
// It should allocate a new string for the name.
Expand Down
4 changes: 2 additions & 2 deletions test/acl_hal_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int acl_test_hal_close_devices(cl_uint num_devices,
void *acl_test_hal_shared_alloc(cl_device_id device, size_t size,
size_t alignment, mem_properties_t *properties,
int *error);
void *acl_test_hal_host_alloc(const std::vector<cl_device_id> devices,
void *acl_test_hal_host_alloc(const std::vector<cl_device_id> &devices,
size_t size, size_t alignment,
mem_properties_t *properties, int *error);
int acl_test_hal_free(cl_context context, void *ptr);
Expand Down Expand Up @@ -652,7 +652,7 @@ void *acl_test_hal_shared_alloc(cl_device_id device, size_t size,
return (void *)0xdeadbeefdeadbeef;
}

void *acl_test_hal_host_alloc(const std::vector<cl_device_id>, size_t, size_t,
void *acl_test_hal_host_alloc(const std::vector<cl_device_id> &, size_t, size_t,
mem_properties_t *, int *) {
return (void *)0xdeadbeefdeadbeef;
}
Expand Down