Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
CodeTemplate/c/mic/sync_transfer.c at master · b3601993/CodeTemplate · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
b3601993
CodeTemplate
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
CodeTemplate
/
c
/
mic
/
sync_transfer.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
93 lines (74 loc) · 2.06 KB
master
Breadcrumbs
CodeTemplate
/
c
/
mic
/
sync_transfer.c
Copy path
Top
File metadata and controls
Code
Blame
93 lines (74 loc) · 2.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include
<stdio.h>
#include
<stdlib.h>
#define
__ONMIC__
__attribute__((target(mic)))
/**
* 异步传输数据 offload_transfer
*/
__ONMIC__
void
add_inputs
(
int
n
,
float
*
f1
,
float
*
f2
){
int
i
;
for
(
i
=
0
;
i
<
n
;
i
++
) {
f2
[
i
]
+=
f1
[
i
];
}
}
void
display_vals
(
int
id
,
int
n
,
float
*
f2
) {
printf
(
"\nResults after Offload #%d:\n"
,
id
);
int
i
;
for
(
i
=
0
;
i
<
n
;
i
++
) {
printf
(
"f2[%d] is %f\n"
,
i
,
f2
[
i
] );
}
printf
(
"====================\n"
);
}
void
test
() {
float
*
f1
,
*
f2
;
int
n
=
10000
;
int
i
,
j
;
f1
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
n
);
f2
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
n
);
for
(
i
=
0
;
i
<
n
;
i
++
) {
f1
[
i
]
=
i
+
1
;
f2
[
i
]
=
0.0
;
}
// 这里只上传数据
#pragma
offload_transfer target(mic:0) signal(f1) \
in (f1:length(n) alloc_if(1) free_if(0))\
in (f2:length(n) alloc_if(1) free_if(0))
// wait(f1)等待上面的数据传输完毕, 再执行该操作
#pragma
offload target(mic:0) wait(f1) signal(f2) \
in(n) \
nocopy(f1:alloc_if (0) free_if(1))\
out(f2:length(n) alloc_if(0) free_if(1))
add_inputs
(
n
,
f1
,
f2
);
// 等该f2执行完
#pragma
offload_wait target(mic:0) wait(f2)
// 如果不加wait, 就会全部打印出0
display_vals
(
1
,
10
,
f2
);
// 多个数据异步上传
#pragma
offload_transfer target(mic:0) signal(f1) \
in(f1:length(n) alloc_if(1) free_if(0))
#pragma
offload_transfer target(mic:0) signal(f2) \
in(f2:length(n) alloc_if(1) free_if(0))
// 同时等待两个信号量
#pragma
offload target(mic:0) wait(f1, f2) \
in (n) \
nocopy (f1:alloc_if(0) free_if(1)) \
out (f2:length(n) alloc_if(0) free_if(1))
add_inputs
(
n
,
f1
,
f2
);
display_vals
(
2
,
10
,
f2
);
// 异步传输和同步传输结合
#pragma
offload_transfer target(mic:0) signal(f2)\
in(f2:length(n) alloc_if(1) free_if(0))
#pragma
offload target(mic:0) wait(f2) \
in(n) \
in(f1:length(n) alloc_if(1) free_if(0))\
nocopy(f2)
add_inputs
(
n
,
f1
,
f2
);
#pragma
offload_transfer target(mic:0) signal(f2) \
out(f2:length(n) alloc_if(0) free_if(1))
#pragma
offload_wait target(mic:0) wait(f2)
display_vals
(
3
,
10
,
f2
);
free
(
f1
);
free
(
f2
);
}
int
main
() {
test
();
}
You can’t perform that action at this time.