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. bzoj 1228: [SDOI2009]E&D 阿达马矩阵

    1228: [SDOI2009]E&D Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 448  Solved: 240[Submit][Sta ...

  2. asp防注入安全问题

    一.古老的绕验证漏洞虽然古老,依然存在于很多小程序之中,比如一些企业网站的后台,简单谈谈.这个漏洞出现在没有对接受的变量进行过滤,带入数据库判断查询时,造成SQL语句的逻辑问题.例如以下代码存在问题: ...

  3. 【leetcode】Palindrome Number (easy)

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  4. SaaS系列介绍之六: SaaS模式分析(上)

    1 引言 如果我们想要更多的玫瑰花,就必须种植更多的玫瑰树.                            ________姚群<成功激励格言精选> SaaS模式是个新兴的话题,有 ...

  5. SPRING IN ACTION 第4版笔记-第九章Securing web applications-005-Applying LDAP-backed authentication

    一. 1.This method is the  LDAP analog to  jdbcAuthentication() @Override protected void configure(Aut ...

  6. USB Type-C工作原理解析

    自从苹果发布了新MacBook,USB Type-C接口就成为了热议对象.我来从硬件角度解析下这个USB Type-C,以便大家更好的了解USB Type-C的工作原理. 特色 尺寸小,支持正反插,速 ...

  7. node.js模块之util模块

    util提供了各种使用的工具.require('util') to access them. Util.format(format,[..]) Returns a formatted string u ...

  8. uva11082 Matrix Decompressing

    网络流 首先算出每行每列的数的和. 每行的值减去c,每列的值减去R 然后每行和每列之间连边,容量为19. 这样一来,(i,j)的流量相当于(i,j)的值-1. 这样就避免了流量为0不对应答案的尴尬情况 ...

  9. BZOJ_2434_[NOI2011]_阿狸的打字机_(AC自动机+dfs序+树状数组)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=2434 给出\(n\)个字符串,\(m\)个询问,对于第\(i\)个询问,求第\(x_i\)个字 ...

  10. SQL RIGHT JOIN 关键字

    SQL RIGHT JOIN 关键字 RIGHT JOIN 关键字会右表 (table_name2) 那里返回所有的行,即使在左表 (table_name1) 中没有匹配的行. RIGHT JOIN ...