| 87 | } |
| 88 | |
| 89 | static inline bool compare_default(const unique_ptr<Device>& ldev, |
| 90 | const unique_ptr<Device>& rdev) { |
| 91 | const cl_device_type device_types[] = {CL_DEVICE_TYPE_GPU, |
| 92 | CL_DEVICE_TYPE_ACCELERATOR}; |
| 93 | |
| 94 | auto l_dev_type = ldev->getInfo<CL_DEVICE_TYPE>(); |
| 95 | auto r_dev_type = rdev->getInfo<CL_DEVICE_TYPE>(); |
| 96 | |
| 97 | // This ensures GPU > ACCELERATOR > CPU |
| 98 | for (auto current_type : device_types) { |
| 99 | auto is_l_curr_type = l_dev_type == current_type; |
| 100 | auto is_r_curr_type = r_dev_type == current_type; |
| 101 | |
| 102 | if (is_l_curr_type && !is_r_curr_type) { return true; } |
| 103 | if (!is_l_curr_type && is_r_curr_type) { return false; } |
| 104 | } |
| 105 | |
| 106 | // At this point, the devices are of same type. |
| 107 | // Sort based on emperical evidence of preferred platforms |
| 108 | |
| 109 | // Prefer AMD first |
| 110 | string lPlatName = getPlatformName(*ldev); |
| 111 | string rPlatName = getPlatformName(*rdev); |
| 112 | |
| 113 | if (l_dev_type == CL_DEVICE_TYPE_GPU && r_dev_type == CL_DEVICE_TYPE_GPU) { |
| 114 | // If GPU, prefer AMD > NVIDIA > Beignet / Intel > APPLE |
| 115 | const char* platforms[] = {"AMD", "NVIDIA", "APPLE", "INTEL", |
| 116 | "BEIGNET"}; |
| 117 | |
| 118 | for (auto ref_name : platforms) { |
| 119 | if (verify_present(lPlatName, ref_name) && |
| 120 | !verify_present(rPlatName, ref_name)) { |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | if (!verify_present(lPlatName, ref_name) && |
| 125 | verify_present(rPlatName, ref_name)) { |
| 126 | return false; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Intel falls back to compare based on memory |
| 131 | } else { |
| 132 | // If CPU, prefer Intel > AMD > POCL > APPLE |
| 133 | const char* platforms[] = {"INTEL", "AMD", "POCL", "APPLE"}; |
| 134 | |
| 135 | for (auto ref_name : platforms) { |
| 136 | if (verify_present(lPlatName, ref_name) && |
| 137 | !verify_present(rPlatName, ref_name)) { |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | if (!verify_present(lPlatName, ref_name) && |
| 142 | verify_present(rPlatName, ref_name)) { |
| 143 | return false; |
| 144 | } |
| 145 | } |
| 146 | } |
nothing calls this directly
no test coverage detected