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 ...
随机推荐
- The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2971 题意:将输入的英文数字表达转化为阿拉伯数字. #include< ...
- SGU 180
求逆序数对 归并排序 #include <cstdio> #include <cstring> #include <cmath> #include <a ...
- linux下c++實現簡單的生產者消費者隊列模式
引言 生產者消費者是一個經典的模式 利用生產者,消費者和緩衝區降低了生產者和消費者之間的的耦合度 便於對生產者和消費者的修改 下面記錄的是一個經典的單一生產者多消費者的模式 設計思路 以隊列做為緩衝區 ...
- 深入浅出ShellExecute
Q: 如何打开一个应用程序? ShellExecute(this->m_hWnd,"open","calc.exe",""," ...
- linux 文件比对总结
1. 过滤a.log的重复数据 #统计 cat datatest.log|sort|uniq -d |wc -l #放入b.log cat datatest.log|sort|uniq -d > ...
- 孟岩的c++ 的学习方法,这何尝有不是做人做事的方法呢?
“(孟岩)我主张,在具备基础之后,学习任何新东西,都要抓住主线,突出重点.对 于关键理论的学习,要集中精力,速战速决.而旁枝末节和非本质性的知识内容,完全可 以留给实践去零敲碎打. “原因是这样的,任 ...
- 120. Triangle
题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...
- 搜索插件:ack.vim
ack.vim是Perl脚本ack的前端,对于Vim,也是grepprg和quickfix的简单封装,非常适合搜索 github地址为 https://github.com/mileszs/ack.v ...
- MarshalByRefObject浅析
首先了解一下不同应用程序域中的对象的通信方式有两种: 一种是跨应用程序域边界传输对象副本 一种是使用代理交换消息. 简单来讲,继承此类的对象可以跨越应用程序域边界被引用,甚至被远程引用. 当一个对象需 ...
- 1890. Money out of Thin Air(线段树 dfs转换区间)
1890 将树的每个节点都转换为区间的形式 然后再利用线段树对结点更新 这题用了延迟标记 相对普通线段树 多了dfs的转换 把所要求的转换为某段区间 RE了N次 最后没办法了 记得有个加栈的语句 拿来 ...