Commit 0fb45c0e authored by Nicolas Denoyelle's avatar Nicolas Denoyelle
Browse files

valgrind fixes

parent 719e2de8
Pipeline #11481 failed with stages
in 43 seconds
......@@ -78,7 +78,7 @@ int aml_area_cuda_mmap_opts(void **out,
const size_t size,
const int device, const int flags, void **ptr_map)
{
int current_device;
int current_device = -1;
int error = AML_SUCCESS;
int cuda_flags;
......
......@@ -363,18 +363,13 @@ static int aml_hwloc_distances_alloc(const hwloc_obj_type_t t0,
n = *nt0 + *nt1;
}
*out = malloc(sizeof(**out));
*out = AML_INNER_MALLOC_EXTRA(n, hwloc_obj_t,
n*n*sizeof(*((*out)->values)),
struct hwloc_distances_s);
if (*out == NULL)
return -AML_ENOMEM;
(*out)->objs = malloc(n * sizeof(hwloc_obj_t));
if ((*out)->objs == NULL)
goto err_with_distances;
(*out)->values = malloc(n * n * sizeof(*((*out)->values)));
if ((*out)->values == NULL)
goto err_with_objs;
(*out)->objs = AML_INNER_MALLOC_GET_ARRAY(*out, hwloc_obj_t, struct hwloc_distances_s);
(*out)->values = AML_INNER_MALLOC_GET_EXTRA(*out, n, hwloc_obj_t, struct hwloc_distances_s);
(*out)->nbobjs = n;
for (unsigned it0 = 0; it0 < *nt0; it0++)
......@@ -387,12 +382,6 @@ static int aml_hwloc_distances_alloc(const hwloc_obj_type_t t0,
hwloc_get_obj_by_type(aml_topology, t1, it1);
}
return AML_SUCCESS;
err_with_objs:
free((*out)->objs);
err_with_distances:
free(*out);
return -AML_ENOMEM;
}
#define OBJ_DIST(dist, i, j, row_stride, col_stride) \
......@@ -401,13 +390,6 @@ err_with_distances:
#define IND_DIST(dist, i, j) (dist)->values[(i) * (dist)->nbobjs + (j)]
static void aml_hwloc_distances_free(struct hwloc_distances_s *dist)
{
free(dist->objs);
free(dist->values);
free(dist);
}
/**
* Get distance matrix in hops between two types of objects.
* Distance matrix comes in the format used in <hwloc/distance.h>.
......@@ -637,7 +619,7 @@ static int aml_hwloc_distances_reshape(struct hwloc_distances_s *dist,
return AML_SUCCESS;
err_with_out:
aml_hwloc_distances_free(*out);
free(*out);
return -AML_FAILURE;
}
......@@ -653,8 +635,9 @@ int aml_hwloc_get_NUMA_distance(const hwloc_obj_type_t type,
enum hwloc_distances_kind_e kind,
struct hwloc_distances_s **out)
{
int err = AML_SUCCESS;
// number of hwloc matrices to return in handle
unsigned int nr = 32;
unsigned int i, nr = 32;
// hwloc distance matrix
struct hwloc_distances_s *handle[nr], *dist = NULL;
......@@ -667,41 +650,49 @@ int aml_hwloc_get_NUMA_distance(const hwloc_obj_type_t type,
return 0;
}
for (unsigned i = 0; i < nr; i++) {
for (i = 0; i < nr; i++) {
// We pick any distance
if (dist == NULL)
dist = handle[i];
// If we found a matrix with same type as initiator type
// then we pick this one.
if (handle[i]->objs[0]->type == type) {
else if (handle[i]->objs[0]->type == type) {
dist = handle[i];
break;
}
// We pick any distance
if (dist == NULL)
dist = handle[i];
// If we find one that is a NUMANODE distance, we chose this one
// over a default choice.
if (handle[i]->objs[0]->type == HWLOC_OBJ_NUMANODE)
else if (handle[i]->objs[0]->type == HWLOC_OBJ_NUMANODE)
dist = handle[i];
// If we find a distance that is finer grain than default,
// then we chose this one.
if (dist->objs[0]->type != HWLOC_OBJ_NUMANODE &&
else if (dist->objs[0]->type != HWLOC_OBJ_NUMANODE &&
dist->objs[0]->depth < handle[i]->objs[0]->depth)
dist = handle[i];
}
// If we were not able to find any matrix, we craft one.
if (dist == NULL) {
if (aml_hwloc_distance_hop_matrix(type, HWLOC_OBJ_NUMANODE,
out) != AML_SUCCESS)
return -AML_ENOMEM;
return AML_SUCCESS;
err = -AML_ENOMEM;
goto out;
}
// We reshape whatever matrix we got to be a distance to NUMANODEs
// matrix.
if (aml_hwloc_distances_reshape(dist, out, type, HWLOC_OBJ_NUMANODE) !=
AML_SUCCESS)
return -AML_ENOMEM;
return AML_SUCCESS;
err = -AML_ENOMEM;
out:
for (i=0; i < nr; i++)
hwloc_distances_release(aml_topology, handle[i]);
return err;
}
int aml_area_hwloc_preferred_create(struct aml_area **area,
......@@ -772,8 +763,7 @@ int aml_area_hwloc_preferred_create(struct aml_area **area,
}
// Cleanup
aml_hwloc_distances_free(dist);
free(dist);
// Success !
*area = ar;
return AML_SUCCESS;
......
......@@ -152,6 +152,8 @@ int aml_dma_cuda_request_wait(struct aml_dma_data *data,
// the provided dma did not create the provided request.
if (dma_req->status != AML_DMA_CUDA_REQUEST_STATUS_DONE)
return -AML_EINVAL;
aml_dma_cuda_request_destroy(data, req);
return AML_SUCCESS;
}
......
......@@ -198,6 +198,8 @@ void test_unified_mmap(const int device)
assert(!aml_area_munmap(area, unified_data, size));
}
aml_area_cuda_destroy(&area);
free(host_copy);
}
......
......@@ -173,6 +173,9 @@ void create_topology()
// Same values
assert(!memcmp(hops->values, xml_hops->values,
hops->nbobjs * sizeof(*hops->values)));
hwloc_distances_release(aml_topology, xml_hops);
free(hops);
}
void test_preferred()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment