|
| 1 | +// AdaptiveCpp compilation with cpu & nvidia targets: syclcc -O3 --hipsycl-targets="omp;cuda:sm_80" <code>.cpp |
| 2 | +// AdaptiveCpp compilation with cpu & amd targets: syclcc -O3 --hipsycl-targets="omp;hip:gfx90a" <code>.cpp |
| 3 | +// OneAPI with cpu & nvidia targets:clang++ -std=c++17 -O3 -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64_x86_64 -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_80 <code>.cpp |
| 4 | +// OneAPI with cpu & amd targets: icpx -std=c++17 -O3 -fsycl -fsycl-targets=amdgcn-amd-amdhsa,spir64_x86_64 -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx90a <code>.cpp |
| 5 | + |
| 6 | +#include <cassert> |
| 7 | +#include <iostream> |
| 8 | +#include <numeric> |
| 9 | +#include <vector> |
| 10 | +#include <ctime> |
| 11 | +#include <chrono> |
| 12 | +#include <getopt.h> |
| 13 | + |
| 14 | +#include <sycl/sycl.hpp> |
| 15 | + |
| 16 | +using namespace sycl; |
| 17 | + |
| 18 | +void ShowDevice(queue &q) { |
| 19 | + |
| 20 | + // Output platform and device information. |
| 21 | + |
| 22 | + auto device = q.get_device(); |
| 23 | + auto p_name = device.get_platform().get_info<info::platform::name>(); |
| 24 | + std::cout << "\t\t\t\tPlatform Name: " << p_name << "\n"; |
| 25 | + auto p_version = device.get_platform().get_info<info::platform::version>(); |
| 26 | + std::cout << "\t\t\t\tPlatform Version: " << p_version << "\n"; |
| 27 | + auto d_name = device.get_info<info::device::name>(); |
| 28 | + std::cout << "\t\t\t\tDevice Name: " << d_name << "\n"; |
| 29 | + auto max_work_group = device.get_info<info::device::max_work_group_size>(); |
| 30 | + std::cout << "\t\t\t\tMax Work Group: " << max_work_group << "\n"; |
| 31 | + auto max_compute_units = device.get_info<info::device::max_compute_units>(); |
| 32 | + std::cout << "\t\t\t\tMax Compute Units: " << max_compute_units << "\n\n"; |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +int main(int argc, char *argv[]) |
| 37 | +{ |
| 38 | + sycl::property_list q_prof{property::queue::enable_profiling{}, sycl::property::queue::in_order{}}; |
| 39 | + std::cout << "\nList Devices\n" << std::endl; |
| 40 | + |
| 41 | + std::cout << "\tChecking for CPUs\n" << std::endl; |
| 42 | + auto cpu_devices= sycl::device::get_devices(sycl::info::device_type::cpu); |
| 43 | + auto n_cpus=size( cpu_devices ); |
| 44 | + std::cout << "\t\t There are "<< n_cpus << " CPUs\n"<< std::endl; |
| 45 | + if(n_cpus>0) |
| 46 | + { |
| 47 | + for (int i_cpu=0;i_cpu<n_cpus; i_cpu++) |
| 48 | + { |
| 49 | + std::cout << "\t\t\t Device: " << cpu_devices[i_cpu].get_info<sycl::info::device::name >()<< "\n" << std::endl; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + std::cout << "\tChecking for GPUs\n" << std::endl; |
| 55 | + auto gpu_devices= sycl::device::get_devices(sycl::info::device_type::gpu); |
| 56 | + auto n_gpus=size( gpu_devices ); |
| 57 | + std::cout << "\t\t There are "<< n_gpus << " GPUs\n"<< std::endl; |
| 58 | + if(n_gpus>0) |
| 59 | + { |
| 60 | + for (int i_gpu=0;i_gpu<n_gpus; i_gpu++) |
| 61 | + { |
| 62 | + std::cout << "\t\t\t Device: " << gpu_devices[i_gpu].get_info<sycl::info::device::name >()<< "\n" << std::endl; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + if(n_cpus>0) |
| 67 | + { |
| 68 | + std::cout << "Checking properties of a queue CPU device\n" << std::endl; |
| 69 | + queue q{cpu_devices[0],q_prof}; |
| 70 | + ShowDevice(q); |
| 71 | + } |
| 72 | + |
| 73 | + if(n_gpus>0) |
| 74 | + { |
| 75 | + std::cout << "Checking properties of a GPU device\n" << std::endl; |
| 76 | + queue q{gpu_devices[0],q_prof}; |
| 77 | + ShowDevice(q); |
| 78 | + } |
| 79 | +} |
0 commit comments