Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
aml
Commits
7812272a
Commit
7812272a
authored
Sep 16, 2020
by
Swann Perarnau
Browse files
Merge branch 'layout_dup_ptr' into 'staging'
[feature] add ptr argument to layout duplicate method See merge request
!158
parents
370ccb85
a95897fc
Pipeline
#11322
passed with stages
in 4 minutes and 39 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/aml.h
View file @
7812272a
...
...
@@ -460,13 +460,16 @@ struct aml_layout_ops {
* copied too.
* @param[in] layout a non-NULL handle to a layout to copy.
* @param[out] out a pointer to where to store the new layout.
* @param[in] ptr: If not NULL use this pointer as the new layout raw
*pointer.
* @return -AML_ENOTSUP if operation is not available.
* @return -AML_ENOMEM if layout allocation failed.
* @return -AML_EINVAL if src or dest are NULL.
* @return AML_SUCCESS if copy succeeded.
**/
int
(
*
duplicate
)(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
out
);
struct
aml_layout
**
out
,
void
*
ptr
);
/**
* Destroys the layout and frees all associated memory.
...
...
@@ -643,11 +646,14 @@ int aml_layout_fprintf(FILE *stream, const char *prefix,
* no user data is actually copied).
* @param[in] src the layout to duplicate
* @param[out] out a pointer to where to store the new layout
* @param[in] ptr: If not NULL use this pointer as the new layout raw pointer.
* @return -AML_ENOMEM if layout allocation failed.
* @return -AML_EINVAL if src or dest are NULL.
* @return AML_SUCCESS if copy succeeded.
**/
int
aml_layout_duplicate
(
const
struct
aml_layout
*
src
,
struct
aml_layout
**
out
);
int
aml_layout_duplicate
(
const
struct
aml_layout
*
src
,
struct
aml_layout
**
out
,
void
*
ptr
);
/**
* Destroy (free) a layout, irrespective of its type.
...
...
include/aml/layout/sparse.h
View file @
7812272a
...
...
@@ -130,10 +130,14 @@ size_t aml_layout_sparse_element_size(const struct aml_layout_data *data);
* @param[in] layout: The input sparse layout.
* @param[out] dest: A pointer where layout duplicate will be
* allocated.
* @param[in] ptr: If not NULL use these pointers as the new layout raw pointer.
* ptr is casted to (void**) and shall contain one new pointer per rawptr of
* this layout.
* @return same as aml_layout_sparse_create().
*/
int
aml_layout_sparse_duplicate
(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
dest
);
struct
aml_layout
**
dest
,
void
*
ptr
);
/**
* Pre-existing operators for sparse layout.
...
...
src/dma/dma_linux_par.c
View file @
7812272a
...
...
@@ -36,8 +36,8 @@ int aml_dma_request_linux_par_copy_init(struct aml_dma_request_linux_par *req,
{
assert
(
req
!=
NULL
);
req
->
type
=
AML_DMA_REQUEST_TYPE_LAYOUT
;
aml_layout_duplicate
(
dest
,
&
req
->
dest
);
aml_layout_duplicate
(
src
,
&
req
->
src
);
aml_layout_duplicate
(
dest
,
&
req
->
dest
,
NULL
);
aml_layout_duplicate
(
src
,
&
req
->
src
,
NULL
);
req
->
op
=
op
;
req
->
op_arg
=
op_arg
;
return
0
;
...
...
src/dma/dma_linux_seq.c
View file @
7812272a
...
...
@@ -37,8 +37,8 @@ int aml_dma_request_linux_seq_copy_init(struct aml_dma_request_linux_seq *req,
{
assert
(
req
!=
NULL
);
req
->
type
=
AML_DMA_REQUEST_TYPE_LAYOUT
;
aml_layout_duplicate
(
dest
,
&
req
->
dest
);
aml_layout_duplicate
(
src
,
&
req
->
src
);
aml_layout_duplicate
(
dest
,
&
req
->
dest
,
NULL
);
aml_layout_duplicate
(
src
,
&
req
->
src
,
NULL
);
req
->
op
=
op
;
req
->
op_arg
=
op_arg
;
return
0
;
...
...
src/layout/dense.c
View file @
7812272a
...
...
@@ -129,7 +129,8 @@ int aml_layout_dense_create(struct aml_layout **layout,
}
int
aml_layout_dense_duplicate
(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
out
)
struct
aml_layout
**
out
,
void
*
ptr
)
{
const
struct
aml_layout_dense
*
data
;
struct
aml_layout_dense
*
dret
;
...
...
@@ -147,7 +148,7 @@ int aml_layout_dense_duplicate(const struct aml_layout *layout,
ret
->
ops
=
layout
->
ops
;
dret
=
(
struct
aml_layout_dense
*
)
ret
->
data
;
dret
->
ptr
=
data
->
ptr
;
dret
->
ptr
=
ptr
?
ptr
:
data
->
ptr
;
/* small optimization by copying the contents of the end part of our
* single allocation (everything after the _data struct).
...
...
src/layout/layout.c
View file @
7812272a
...
...
@@ -298,14 +298,15 @@ int aml_layout_fprintf(FILE *stream, const char *prefix,
}
int
aml_layout_duplicate
(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
dest
)
struct
aml_layout
**
dest
,
void
*
ptr
)
{
assert
(
layout
!=
NULL
&&
layout
->
ops
!=
NULL
);
if
(
layout
->
ops
->
duplicate
==
NULL
)
return
-
AML_ENOTSUP
;
else
return
layout
->
ops
->
duplicate
(
layout
,
dest
);
return
layout
->
ops
->
duplicate
(
layout
,
dest
,
ptr
);
}
void
aml_layout_destroy
(
struct
aml_layout
**
layout
)
...
...
src/layout/pad.c
View file @
7812272a
...
...
@@ -107,7 +107,8 @@ int aml_layout_pad_create(struct aml_layout **layout, const int order,
}
int
aml_layout_pad_duplicate
(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
out
)
struct
aml_layout
**
out
,
void
*
ptr
)
{
const
struct
aml_layout_pad
*
data
;
struct
aml_layout_pad
*
dret
;
...
...
@@ -126,7 +127,7 @@ int aml_layout_pad_duplicate(const struct aml_layout *layout,
ret
->
ops
=
layout
->
ops
;
dret
=
(
struct
aml_layout_pad
*
)
ret
->
data
;
aml_layout_duplicate
(
data
->
target
,
&
dret
->
target
);
aml_layout_duplicate
(
data
->
target
,
&
dret
->
target
,
ptr
);
dret
->
tags
=
data
->
tags
;
/* small optimization to copy everything at the end of our single
* allocation, but careful about neutral and the arrays having a gap
...
...
src/layout/reshape.c
View file @
7812272a
...
...
@@ -126,7 +126,8 @@ int aml_layout_reshape_create(struct aml_layout **layout,
}
int
aml_layout_reshape_duplicate
(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
out
)
struct
aml_layout
**
out
,
void
*
ptr
)
{
const
struct
aml_layout_data_reshape
*
data
;
struct
aml_layout_data_reshape
*
dret
;
...
...
@@ -144,7 +145,7 @@ int aml_layout_reshape_duplicate(const struct aml_layout *layout,
ret
->
ops
=
layout
->
ops
;
dret
=
(
struct
aml_layout_data_reshape
*
)
ret
->
data
;
aml_layout_duplicate
(
data
->
target
,
&
dret
->
target
);
aml_layout_duplicate
(
data
->
target
,
&
dret
->
target
,
ptr
);
/* small optimization, copying all data at the end of the structure */
memcpy
(
dret
->
dims
,
data
->
dims
,
(
2
*
data
->
ndims
+
data
->
target_ndims
)
*
sizeof
(
size_t
));
...
...
src/layout/sparse.c
View file @
7812272a
...
...
@@ -53,12 +53,15 @@ int aml_layout_sparse_create(struct aml_layout **layout,
}
int
aml_layout_sparse_duplicate
(
const
struct
aml_layout
*
layout
,
struct
aml_layout
**
dest
)
struct
aml_layout
**
dest
,
void
*
ptr
)
{
struct
aml_layout_sparse
*
src
=
(
struct
aml_layout_sparse
*
)
layout
->
data
;
return
aml_layout_sparse_create
(
dest
,
src
->
nptr
,
src
->
ptrs
,
src
->
sizes
,
src
->
metadata
,
src
->
metadata_size
);
return
aml_layout_sparse_create
(
dest
,
src
->
nptr
,
ptr
?
(
void
**
)
ptr
:
src
->
ptrs
,
src
->
sizes
,
src
->
metadata
,
src
->
metadata_size
);
}
void
*
aml_layout_sparse_deref
(
const
struct
aml_layout_data
*
data
,
...
...
tests/layout/layout.c
View file @
7812272a
...
...
@@ -138,6 +138,6 @@ void test_layout_fprintf(FILE *stream, const char *prefix,
void
test_layout_duplicate
(
struct
aml_layout
*
layout
)
{
struct
aml_layout
*
l
;
assert
(
!
aml_layout_duplicate
(
layout
,
&
l
));
assert
(
!
aml_layout_duplicate
(
layout
,
&
l
,
NULL
));
aml_layout_destroy
(
&
l
);
}
tests/layout/test_sparse.c
View file @
7812272a
...
...
@@ -47,7 +47,7 @@ void test_functional()
// Duplicate
struct
aml_layout
*
dup
;
assert
(
aml_layout_duplicate
(
layout
,
&
dup
)
==
AML_SUCCESS
);
assert
(
aml_layout_duplicate
(
layout
,
&
dup
,
NULL
)
==
AML_SUCCESS
);
test_common
(
dup
,
nptr
,
data
);
// Cleanup
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment