博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++amp加速设置
阅读量:5321 次
发布时间:2019-06-14

本文共 3311 字,大约阅读时间需要 11 分钟。

参考自:https://msdn.microsoft.com/en-us/library/hh873132.aspx

1 #include 
2 #include
3 4 using namespace Concurrency; 5 6 // 缺省加速设备 7 void default_properties() 8 { 9 accelerator default_acc; 10 std::wcout << default_acc.device_path << "\n"; 11 std::wcout << default_acc.dedicated_memory << "\n"; 12 } 13 14 // 列出所有加速设备 15 void list_all_accelerators() 16 { 17 std::vector
accs = accelerator::get_all(); 18 for (int i = 0; i < accs.size(); i++) 19 { 20 std::wcout << accs[i].device_path << "\n"; 21 std::wcout << accs[i].dedicated_memory << "\n"; 22 std::wcout << (accs[i].supports_cpu_shared_memory ?\ 23 "CPU shared memory: true" : "CPU shared memory: false") << "\n"; 24 std::wcout << (accs[i].supports_double_precision ? \ 25 "double precision:true" : "double precision: false") << "\n"; 26 std::wcout << (accs[i].supports_limited_double_precision ? \ 27 "limited double precision: true" : "limited double precision: false") << "\n"; 28 std::wcout << accs[i].description << "\n\n\n"; 29 } 30 } 31 32 // 选择最大加速设备 33 void pick_with_most_memory() 34 { 35 std::vector
accs = accelerator::get_all(); 36 accelerator acc_chosen = accs[0]; 37 for (int i = 0; i < accs.size(); i++) 38 { 39 if (accs[i].dedicated_memory > acc_chosen.dedicated_memory) 40 { 41 acc_chosen = accs[i]; 42 } 43 } 44 45 std::wcout << "The accelerator with the most memory is " 46 << acc_chosen.device_path << "\n" 47 << acc_chosen.dedicated_memory << ".\n"; 48 } 49 50 // 和CPU共享内存 51 void sharedMemory() 52 { 53 accelerator acc = accelerator(accelerator::default_accelerator); 54 55 // Early out if the default accelerator doesn't support shared memory 56 if (!acc.supports_cpu_shared_memory) 57 { 58 std::cout << "The default accelerator does not support shared memory" << std::endl; 59 return; 60 } 61 62 // Override the default CPU access type 63 acc.set_default_cpu_access_type(access_type_read_write); 64 65 // Create an accelerator_view from the default acclerator. The 66 // accelerator_view reflects the default_cpu_access_type of the 67 // accelerator it's associated with. 68 accelerator_view acc_v = acc.default_view; 69 } 70 71 // 选择加速设备 72 bool pick_accelerator() 73 { 74 std::vector
accs = accelerator::get_all(); 75 accelerator chosen_one; 76 77 auto result = std::find_if(accs.begin(), accs.end(), [](const accelerator& acc) 78 { 79 return !acc.is_emulated && acc.supports_double_precision && !acc.has_display; 80 }); 81 82 if (result != accs.end()) 83 { 84 chosen_one = *(result); 85 } 86 87 std::wcout << chosen_one.description << std::endl; 88 89 bool success = accelerator::set_default(chosen_one.device_path); 90 91 return success; 92 } 93 94 void main() 95 { 96 default_properties(); 97 //list_all_accelerators(); 98 //pick_with_most_memory(); 99 //sharedMemory();100 101 pick_accelerator();102 }

 

转载于:https://www.cnblogs.com/WuhanLiukai/p/4544457.html

你可能感兴趣的文章
windows 安装yaml支持和pytest支持等
查看>>
读书笔记:季羡林关于如何做研究学问的心得
查看>>
面向对象的优点
查看>>
套接口和I/O通信
查看>>
阿里巴巴面试之利用两个int值实现读写锁
查看>>
浅谈性能测试
查看>>
Winform 菜单和工具栏控件
查看>>
jequery动态创建form
查看>>
CDH版本大数据集群下搭建的Hue详细启动步骤(图文详解)
查看>>
第六次java作业
查看>>
巧用Win+R
查看>>
浅析原生js模仿addclass和removeclass
查看>>
Python中的greenlet包实现并发编程的入门教程
查看>>
tweenlite使用说明
查看>>
java中遍历属性字段及值(常见方法)
查看>>
Jenkins执行批处理文件失败
查看>>
深入理解jQuery框架-框架结构
查看>>
[7.14NOIP模拟4]通讯 题解 (Tarjan缩点+贪心)
查看>>
刷水记录
查看>>
疫情控制
查看>>