C++20: An (Almost) Complete Overviewfixed-size: 42 ints spanb {data}; // dynamic-size: 42 ints span c {data}; // compilation error span d { ptr, len }; // dynamic-size: len ints Read-only span: span required to always produce a constant at compile time, a non- constant result should be a compilation error called: immediate functions consteval auto InchToMm(double inch) { return inch * 25.4; everything is constant ✔ double dynamic_inch { 8 }; const auto mm2 { InchToMm(dynamic_inch) }; // Compilation error: not constant ❌73 constinit Static initialization order fiasco Variables with static 0 码力 | 85 页 | 512.18 KB | 6 月前3
C++高性能并行编程与优化 - 课件 - 08 CUDA 开启的 GPU 编程里 的 __device__ 或 __global__ 函数,就会出错 。 分离 __device__ 函数的声明和定义:解决 • 开启 CMAKE_CUDA_SEPARABLE_COMPILATION 选 项(设为 ON ),即可启用分离声明和定义的支持。 • 不过我还是建议把要相互调用的 __device__ 函数放在 同一个文件,这样方便编译器自动内联优化(第四课讲 过)。 glDispatchComputeIndirect 的 API 和这个很像,但毕竟没有 CUDA 可以直接在核函数里调用核函数并指定参数这么方便…… 不过,这个功能同样需要开启 CUDA_SEPARABLE_COMPILATION 。 第 2 章:内存管理 如何从核函数里返回数据? • 我们试着把 kernel 的返回类型声明为 int ,试 图从 GPU 返回数据到 CPU 。 • 但发现这样做会在编译期出错,为什么?0 码力 | 142 页 | 13.52 MB | 1 年前3
共 2 条
- 1













