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的更多相关文章

  1. Part 3 - Advanced Concepts(11-13)

    https://simpleisbetterthancomplex.com/series/2017/09/18/a-complete-beginners-guide-to-django-part-3. ...

  2. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  3. Code First :使用Entity. Framework编程(6) ----转发 收藏

    Chapter6 Controlling Database Location,Creation Process, and Seed Data 第6章 控制数据库位置,创建过程和种子数据 In prev ...

  4. [翻译] Autofac 中注册的概念

    原文链接:http://docs.autofac.org/en/latest/register/registration.html 所谓注册组件,是指创建 ContainerBuilder 的实例,并 ...

  5. 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 ...

  6. [z] 人工智能和图形学、图像处理方面的各种会议的评级

    转载自:『http://www.cvchina.info/2010/08/31/conference-ranking-byar/』 澳大利亚政府和澳大利亚研究理事会做的,有一定考价值. 会议名称 会议 ...

  7. C++程序结构---1

    C++ 基础教程Beta 版 原作:Juan Soulié 翻译:Jing Xu (aqua) 英文原版 本教程根据Juan Soulie的英文版C++教程翻译并改编. 本版为最新校对版,尚未定稿.如 ...

  8. Understanding Convolution in Deep Learning

    Understanding Convolution in Deep Learning Convolution is probably the most important concept in dee ...

  9. TestNG超详细教程

    testNG官网:http://testng.org/doc/download.html howtodoinjava.com里的testNG教程,简单详细:http://howtodoinjava.c ...

随机推荐

  1. IDEA 创建maven-web project失败一例

    今天使用IDEA创建WEB-APP总是失败,经排查原来是MAVEN环境没配置好!!! 配置: M2_HOME--->maven解压目录 path---->%M2_HOME%\bin\

  2. codeforces #309 div1 A

    先说我的解法吧 首先设f(i,j)表示选了前i个球且j种颜色都已经选完了的方案数 这显然是可以随便转移的 #include<cstdio> #include<cstring> ...

  3. xcode 开发ios兼容性问题的上下黑边 和 coco2d-x 游戏分辨率适配 ResolutionPolicy::FIXED_WIDTH 都会引起上下黑边问题!!!

    1:Xcode6在iPhone5+iOS7模拟器上编译,上下有黑边问题 问题描述: Xcode6环境下,对iPhone5或iPhone5s模拟器,在iOS7或iOS7.1下运行,屏幕上下有黑边.在iO ...

  4. POJ2506——Tiling

    Tiling Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a samp ...

  5. JavaScript Function.apply() 函数详解

    apply()函数用于调用当前函数functionObject,并可同时使用指定对象thisObj作为本次函数执行时函数内部的this指针引用. 该函数属于Function对象,所有主流浏览器均支持该 ...

  6. Windows Embedded Compact 2013升级:VS2013也能编译

    IT之家(www.ithome.com):Windows Embedded Compact 2013升级:VS2013也能编译 今天,微软为Windows Embedded Compact 2013送 ...

  7. poj 3295 Tautology (构造)

    题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...

  8. Tomcat 配置问题总结

    本人是一个前端屌丝儿,最近没事研究了一下tomcat的部署问题,一下列几个实用的小技能(直接上干货了,不赘述): 1,路径引用部署 在tomcat目录下的conf/Catalina/localhost ...

  9. ZJOI2008泡泡堂BNB

    1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1305  Solved: 676[Submit][Sta ...

  10. HAOI2011 problem b

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 1047  Solved: 434[Submit][ ...