SYCL

科技工作者之家 2020-11-17

SYCL是OpenCL的高级编程模型,作为基于纯C ++ 11(用于SYCL 1.2.1)和C ++ 14(用于SYCL 2.2)的单源特定于域的嵌入式语言(DSEL), 用于提高编程效率。 这是由Khronos Group于2014年3月发布的标准。

作用SYCL是一个免版税的跨平台抽象层,基于OpenCL的基本概念,可移植性和效率,使得异构处理器的代码可以使用完全标准的“单一来源”风格编写C ++。 SYCL支持单一源代码开发,其中C ++模板函数可以包含主机代码和设备代码,以构建使用OpenCL加速的复杂算法,然后在不同类型数据的源代码中重复使用它们。

虽然最初是为了与OpenCL和SPIR一起使用而开发的,但它实际上是一个能够以其他系统为目标的更一般的异构框架1。

版本最新版本是于2018年6月21日发布的SYCL 1.2.1修订版2(第一版于2017年12月6日发布)。

2014年3月,GCL在临时版本1.2 中引入了SYCL,随后于2015年5月在IWOCL 2015上引入了SYCL 1.2最终版本。

2016年5月在IWOCL 2016上推出了SYCL 2.2暂定。

公共版本是:

a.针对OpenCL 1.2硬件特性的SYCL 1.2.1,具有OpenCL 1.2互操作性模式;

b.以OpenCL 2.2互操作性模式为目标的针对OpenCL 2.2硬件特性的临时SYCL 2.2。

例子以下示例显示了定义在默认加速器上运行的3个内核的隐式任务图的单源纯C ++编程模型。

#include #include using namespace cl::sycl;// Size of the matricesconstexpr size_t N = 2000;constexpr size_t M = 3000;int main() { // Create a queue to work on default device queue q; // Create some 2D buffers with N×M float values for our matrices buffer a{{ N, M }}; buffer b{{ N, M }}; buffer c{{ N, M }}; // Launch a first asynchronous kernel to initialize buffer "a" q.submit([&](auto &cgh) { // The kernel write "a", so get a write accessor on it auto A = a.get_access(cgh); // Enqueue parallel kernel on an N×M 2D iteration space cgh.parallel_for({ N, M }, [=] (auto index) { A[index] = index[0]*2 + index[1]; }); }); // Launch an asynchronous kernel to initialize buffer "b" q.submit([&](auto &cgh) { // The kernel write "b", so get a write accessor on it auto B = b.get_access(cgh); // Enqueue a parallel kernel on an N×M 2D iteration space cgh.parallel_for({ N, M }, [=] (auto index) { B[index] = index[0]*2014 + index[1]*42; }); }); // Launch an asynchronous kernel to compute matrix addition c = a + b q.submit([&](auto &cgh) { // In the kernel "a" and "b" are read, but "c" is written // Since the kernel reads "a" and "b", the runtime will add implicitly // a producer-consumer dependency to the previous kernels producing them. auto A = a.get_access(cgh); auto B = b.get_access(cgh); auto C = c.get_access(cgh); // Enqueue a parallel kernel on an N×M 2D iteration space cgh.parallel_for({ N, M }, [=] (auto index) { C[index] = A[index] + B[index]; }); }); /* Request an access to read "c" from the host-side. The SYCL runtime will wait for "c" to be ready available on the host side before returning the accessor. This means that there is no communication happening in the loop nest below. */ auto C = c.get_access(); std::cout

科技工作者之家

科技工作者之家APP是专注科技人才,知识分享与人才交流的服务平台。