Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hercules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
Hercules
Commits
8734113e
Commit
8734113e
authored
1 month ago
by
Russel Arbore
Browse files
Options
Downloads
Patches
Plain Diff
Use channels to send values between async calls, wrap in arcs to share
parent
9d65ddb3
No related branches found
No related tags found
1 merge request
!192
Optimize edge detection
Pipeline
#201777
passed
1 month ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hercules_cg/src/rt.rs
+43
-15
43 additions, 15 deletions
hercules_cg/src/rt.rs
with
43 additions
and
15 deletions
hercules_cg/src/rt.rs
+
43
−
15
View file @
8734113e
...
@@ -560,23 +560,33 @@ impl<'a> RTContext<'a> {
...
@@ -560,23 +560,33 @@ impl<'a> RTContext<'a> {
// same interface as AsyncRust functions.
// same interface as AsyncRust functions.
let
block
=
&
mut
blocks
.get_mut
(
&
bb
)
.unwrap
()
.data
;
let
block
=
&
mut
blocks
.get_mut
(
&
bb
)
.unwrap
()
.data
;
let
is_async
=
func
.schedules
[
id
.idx
()]
.contains
(
&
Schedule
::
AsyncCall
);
let
is_async
=
func
.schedules
[
id
.idx
()]
.contains
(
&
Schedule
::
AsyncCall
);
if
is_async
{
for
arg
in
args
{
if
let
Some
(
arc
)
=
self
.clone_arc
(
*
arg
,
false
)
{
write!
(
block
,
"{}"
,
arc
)
?
;
}
}
}
let
device
=
self
.devices
[
callee_id
.idx
()];
let
device
=
self
.devices
[
callee_id
.idx
()];
let
prefix
=
match
(
device
,
is_async
)
{
let
prefix
=
match
(
device
,
is_async
)
{
(
Device
::
AsyncRust
,
false
)
=>
""
,
(
Device
::
AsyncRust
,
false
)
|
(
_
,
false
)
=>
{
(
_
,
false
)
=>
""
,
format!
(
"{} = "
,
self
.get_value
(
id
,
bb
,
true
))
(
Device
::
AsyncRust
,
true
)
=>
"Some(::async_std::task::spawn("
,
}
(
_
,
true
)
=>
"Some(::async_std::task::spawn(async move {"
,
(
_
,
true
)
=>
format!
(
"{}::async_std::task::spawn(async move {{ async_call_sender_{}.send("
,
self
.clone_arc
(
id
,
true
)
.unwrap
(),
id
.idx
()
),
};
};
let
postfix
=
match
(
device
,
is_async
)
{
let
postfix
=
match
(
device
,
is_async
)
{
(
Device
::
AsyncRust
,
false
)
=>
".await"
,
(
Device
::
AsyncRust
,
false
)
=>
".await"
,
(
_
,
false
)
=>
""
,
(
_
,
false
)
=>
""
,
(
Device
::
AsyncRust
,
true
)
=>
"
)
)"
,
(
Device
::
AsyncRust
,
true
)
=>
"
.await).await}
)"
,
(
_
,
true
)
=>
"
}
))"
,
(
_
,
true
)
=>
")
.await}
)"
,
};
};
write!
(
write!
(
block
,
block
,
"{} = {}{}("
,
"{}{}("
,
self
.get_value
(
id
,
bb
,
true
),
prefix
,
prefix
,
self
.module.functions
[
callee_id
.idx
()]
.name
self
.module.functions
[
callee_id
.idx
()]
.name
)
?
;
)
?
;
...
@@ -1069,11 +1079,15 @@ impl<'a> RTContext<'a> {
...
@@ -1069,11 +1079,15 @@ impl<'a> RTContext<'a> {
}
}
// If the node is a call with an AsyncCall schedule, it should be
// If the node is a call with an AsyncCall schedule, it should be
//
spawn
ed
as
a
task and awaited later
.
//
lower
ed
to
a
channel
.
let
is_async_call
=
let
is_async_call
=
func
.nodes
[
idx
]
.is_call
()
&&
func
.schedules
[
idx
]
.contains
(
&
Schedule
::
AsyncCall
);
func
.nodes
[
idx
]
.is_call
()
&&
func
.schedules
[
idx
]
.contains
(
&
Schedule
::
AsyncCall
);
if
is_async_call
{
if
is_async_call
{
write!
(
w
,
"let mut async_call_{} = None;"
,
idx
)
?
;
write!
(
w
,
"let mut async_call_channel_{} = ::async_std::channel::bounded(1);let async_call_sender_{} = ::std::sync::Arc::new(async_call_channel_{}.0);let async_call_receiver_{} = ::std::sync::Arc::new(async_call_channel_{}.1);"
,
idx
,
idx
,
idx
,
idx
,
idx
)
?
;
}
else
{
}
else
{
write!
(
write!
(
w
,
w
,
...
@@ -1356,16 +1370,30 @@ impl<'a> RTContext<'a> {
...
@@ -1356,16 +1370,30 @@ impl<'a> RTContext<'a> {
}
else
if
func
.nodes
[
id
.idx
()]
.is_call
()
}
else
if
func
.nodes
[
id
.idx
()]
.is_call
()
&&
func
.schedules
[
id
.idx
()]
.contains
(
&
Schedule
::
AsyncCall
)
&&
func
.schedules
[
id
.idx
()]
.contains
(
&
Schedule
::
AsyncCall
)
{
{
format!
(
assert!
(
!
lhs
);
"async_call_{}{}"
,
format!
(
"async_call_receiver_{}.recv().await.unwrap()"
,
id
.idx
(),)
id
.idx
(),
if
lhs
{
""
}
else
{
".unwrap().await"
}
)
}
else
{
}
else
{
format!
(
"node_{}"
,
id
.idx
())
format!
(
"node_{}"
,
id
.idx
())
}
}
}
}
fn
clone_arc
(
&
self
,
id
:
NodeID
,
lhs
:
bool
)
->
Option
<
String
>
{
let
func
=
self
.get_func
();
if
func
.nodes
[
id
.idx
()]
.is_call
()
&&
func
.schedules
[
id
.idx
()]
.contains
(
&
Schedule
::
AsyncCall
)
{
let
kind
=
if
lhs
{
"sender"
}
else
{
"receiver"
};
Some
(
format!
(
"let async_call_{}_{} = async_call_{}_{}.clone();"
,
kind
,
id
.idx
(),
kind
,
id
.idx
()
))
}
else
{
None
}
}
fn
get_type
(
&
self
,
id
:
TypeID
)
->
&
'static
str
{
fn
get_type
(
&
self
,
id
:
TypeID
)
->
&
'static
str
{
convert_type
(
&
self
.module.types
[
id
.idx
()])
convert_type
(
&
self
.module.types
[
id
.idx
()])
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment