Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
6106ed16
Commit
6106ed16
authored
Oct 09, 2021
by
Paul
Browse files
Create a type attribute
parent
8e50db0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
+33
-4
src/mlir.cpp
src/mlir.cpp
+33
-4
No files found.
src/mlir.cpp
View file @
6106ed16
...
...
@@ -132,6 +132,23 @@ struct mlir_program
return
mlirRankedTensorTypeGet
(
lens
.
size
(),
lens
.
data
(),
make_type
(
s
.
type
()));
}
template
<
class
Range
>
std
::
vector
<
MlirType
>
make_tensors
(
const
Range
&
r
)
{
std
::
vector
<
MlirType
>
result
;
std
::
transform
(
r
.
begin
(),
r
.
end
(),
std
::
back_inserter
(
result
),
[
&
](
const
auto
&
s
)
{
return
make_tensor
(
s
);
});
return
result
;
}
MlirType
make_function_type
(
const
std
::
vector
<
shape
>&
inputs
,
const
std
::
vector
<
shape
>&
outputs
)
{
auto
in
=
make_tensors
(
inputs
);
auto
out
=
make_tensors
(
outputs
);
return
mlirFunctionTypeGet
(
ctx
.
get
(),
in
.
size
(),
in
.
data
(),
out
.
size
(),
out
.
data
());
}
MlirIdentifier
id
(
const
std
::
string_view
&
s
)
const
{
return
mlirIdentifierGet
(
ctx
.
get
(),
make_mlir_string_ref
(
s
));
...
...
@@ -180,10 +197,7 @@ struct mlir_program
std
::
vector
<
MlirNamedAttribute
>
attributes
;
attributes
.
reserve
(
v
.
size
());
std
::
transform
(
v
.
begin
(),
v
.
end
(),
std
::
back_inserter
(
attributes
),
[
&
](
auto
&&
x
)
{
MlirNamedAttribute
attr
;
attr
.
name
=
id
(
x
.
get_key
());
attr
.
attribute
=
attribute
(
x
.
without_key
());
return
attr
;
return
name_attribute
(
x
.
get_key
(),
x
.
without_key
());
});
return
mlirDictionaryAttrGet
(
ctx
.
get
(),
attributes
.
size
(),
attributes
.
data
());
}
...
...
@@ -198,6 +212,21 @@ struct mlir_program
}
}
MlirAttribute
attribute
(
MlirType
t
)
const
{
return
mlirTypeAttrGet
(
t
);
}
template
<
class
T
>
MlirNamedAttribute
name_attribute
(
const
std
::
string_view
&
key
,
const
T
&
x
)
const
{
MlirNamedAttribute
attr
;
attr
.
name
=
id
(
key
);
attr
.
attribute
=
attribute
(
x
);
return
attr
;
}
mlir_context
ctx
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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