C++amp加速设置

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

  1 #include <amp.h>
  2 #include <iostream>
  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<accelerator> 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<accelerator> 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<accelerator> 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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值