#include #include #include #ifdef _WIN32 #include #endif static const int N = 4; int main() { #ifdef _WIN32 // Set console code page to UTF-8 SetConsoleOutputCP(CP_UTF8); SetConsoleCP(CP_UTF8); #endif sycl::queue q; auto device = q.get_device(); std::cout << "执行设备: " << device.get_info() << std::endl; std::cout << "设备类型: "; if (device.is_cpu()) { std::cout << "CPU" << std::endl; } else if (device.is_gpu()) { std::cout << "GPU" << std::endl; } else { std::cout << "其他" << std::endl; } int *data = sycl::malloc_shared(N, q); for (int i = 0; i < N; i++) data[i] = i; try { q.single_task([=]() { for (int i = 0; i < N; i++) { data[i] *= 2; } }).wait(); } catch (sycl::exception &e) { // Do something to output or handle the exception std::cout << "Caught sync SYCL exception: " << e.what() << "\n"; return 1; } catch (std::exception &e) { std::cout << "Caught std exception: " << e.what() << "\n"; return 2; } catch (...) { std::cout << "Caught unknown exception\n"; return 3; } for (int i = 0; i < N; i++) std::cout << data[i] << std::endl; sycl::free(data, q); return 0; }