8.2 C++ AMP advanced concepts
C++ AMP一些更高级的概念:
1. device内存的分配和拷贝.
void vecAdd(float* A, float* B, float* C, int n)
{
array<float,> AA(n), BA(n);
array<float,> CA(n);
copy(A,AA);
copy(B,BA);
parallel_for_each(CA.get_extent(),
[&AA,&BA,&CA](index<> i) restrict(amp)
{
CA[i] = AA[i] + BA[i];
});
copy(CA,C);
}
array<T,Dimesion>的作用是分配 Accelerator memory,类似于cudaMalloc().
copy(source,destination)的作用是拷贝内存动作,可以在host和Accelerator之间来回拷贝,类似于cudaMemcpy().
这两者加起来的功能就是array_view<>.
另外注意到执行完kernel计算后,拷贝CA数据回host C, 但是并没有执行CV.synchronize()动作,其实copy有隐式同步的功能.
2. host和accelerator异步执行
上面的代码host和accelerator的执行顺序如下图:(左边的是host,右边的是accelerator)

accelerator设备在执行compute的时候,host可以同时执行其他的动作,比如下面的代码:
parallel_for_each(CA.get_extent(),
[&AA,&BA,&CA](index<> i) restrict(amp)
{
CA[i] = AA[i] + BA[i];
});
completion_future done = CV.synchronize_async();
otherProcessing(A,B);
done.get();
completion_future done关联CV的操作. done.get()等待,直到关联的异步操作完成为止.
这个代码的执行顺序图如下:

可以看到,在accelerator执行计算的时候,cpu在执行otherProcessing().
8.2 C++ AMP advanced concepts的更多相关文章
- Part 3 - Advanced Concepts(11-13)
https://simpleisbetterthancomplex.com/series/2017/09/18/a-complete-beginners-guide-to-django-part-3. ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- Code First :使用Entity. Framework编程(6) ----转发 收藏
Chapter6 Controlling Database Location,Creation Process, and Seed Data 第6章 控制数据库位置,创建过程和种子数据 In prev ...
- [翻译] Autofac 中注册的概念
原文链接:http://docs.autofac.org/en/latest/register/registration.html 所谓注册组件,是指创建 ContainerBuilder 的实例,并 ...
- TN035: Using Multiple Resource Files and Header Files with Visual C++
TN035: Using Multiple Resource Files and Header Files with Visual C++ This note describes how the Vi ...
- [z] 人工智能和图形学、图像处理方面的各种会议的评级
转载自:『http://www.cvchina.info/2010/08/31/conference-ranking-byar/』 澳大利亚政府和澳大利亚研究理事会做的,有一定考价值. 会议名称 会议 ...
- C++程序结构---1
C++ 基础教程Beta 版 原作:Juan Soulié 翻译:Jing Xu (aqua) 英文原版 本教程根据Juan Soulie的英文版C++教程翻译并改编. 本版为最新校对版,尚未定稿.如 ...
- Understanding Convolution in Deep Learning
Understanding Convolution in Deep Learning Convolution is probably the most important concept in dee ...
- TestNG超详细教程
testNG官网:http://testng.org/doc/download.html howtodoinjava.com里的testNG教程,简单详细:http://howtodoinjava.c ...
随机推荐
- PAT-乙级-1006. 换个格式输出整数 (15)
1006. 换个格式输出整数 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 让我们用字母B来表示“百” ...
- ZOJ Problem Set - 1002(DFS)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002 题意:给出一个n,有n*n大小的城市,(.)表示空地,从碉堡(O)射 ...
- 转Spring+Hibernate+EHcache配置(二)
Spring AOP+EHCache简单缓存系统解决方案 需要使用Spring来实现一个Cache简单的解决方案,具体需求如下:使用任意一个现有开源Cache Framework,要求可以Cache系 ...
- DeepFace--Facebook的人脸识别(转)
DeepFace基本框架 人脸识别的基本流程是: detect -> aligh -> represent -> classify 人脸对齐流程 分为如下几步: a. 人脸检测,使用 ...
- spark storage之SparkEnv
此文旨在对spark storage模块进行分析,整理自己所看所得,等以后再整理. ok,首先看看SparkContext中sparkEnv相关代码: private[spark] def creat ...
- linq集合内部赋值
linq集合内部赋值 比如将一个列的值,赋值给另一列 有三种方法: 1. e.Result.ToList().ForEach(n => n.IsIntermediarybool = SetIsI ...
- struts2总结六: Struts2的拦截器
一.Struts2的系统结构图
- [itint5]直角路线遍历棋盘
http://www.itint5.com/oj/#22 这题一开始直接用暴力的DFS来做,果然到25的规模就挂了. vector<bool> visited(50, false); ve ...
- 使用nginx做为静态服务器--监听两个域名配置
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; ...
- hadoop博客 oschina
http://my.oschina.net/Xiao629/blog?catalog=449279