Bringing Existing Code to CUDA Using constexpr and std::pmr## +21 ## Bringing Existing Code to CUDA Using constexpr and std::pmr BOWIE OWENS 20 21 October 24-29 ## Outline • Introduction • Memory • Host vs Device Functions • Return on Investment • Concluding 17. --expt-relaxed-constexpr (-expt-relaxed-constexpr) Experimental flag: Allow host code to invoke ___device___{constexpr} functions, and device code to invoke ___host___{constexpr} functions. Note that -nvcc/ index.html#options-for-altering-compiler-linker-behavior-expt-relaxed- constexpr ## Using constexpr constexpr void _add(std::size_t n, float const* x, float* y) { for (std::size_t i = 0;0 码力 | 51 页 | 3.68 MB | 1 年前3
C++20: An (Almost) Complete OverviewExpressions • Pack Expansion in Lambda Captures ☐ constexpr Changes • virtual functions • union, try/catch, dynamic_cast, typeid • allocations • constexpr string & vector ☐ Concurrency Changes std::invoke(f, args...); }; Allowed in C++20 ## constexpr Changes ## constexpr ☐ constexpr virtual functions ☐ constexpr functions can now: • use dynamic cast() and typeid • do dynamic blocks But still cannot throw exceptions ## constexpr string & vector □ std::string and std::vector are now constexpr ☐ Needed to support constexpr reflection in the future  { std::array ## constexpr:强迫编译器在编译期求值(续) #includearr{}; for (int i = 1; i return ret; } int func() { constexpr int ret = func_impl(); return ret; } 结论:如果发现编译器放弃了自动优化,可以用 constexpr 函数迫使编译器进行常量折叠! 不过,constexpr 函数中无法使用非 constexpr 的容器:vector, map, set, string 等.... cpp:18: } movl $5050, %eax #, ret .cfi_endproc template constexpr int func_impl() { std::array arr{}; for (int 0 码力 | 108 页 | 9.47 MB | 2 年前3
Fast and small C++pair 1 template2 struct default_delete { 3 default_delete() = default; 4 5 constexpr void operator()(T* ptr) const noexcept 6 { 7 static_assert(0 < sizeof(T), "can't 24); constexpr static size_t max_cap() { return std::numeric_limits ::max(); } constexpr static size_t sso_cap() { return sizeof(mBuf) - 1; /* -1 for \0' */ } constexpr static bool fits_into_sso(size_t len) { return len <= sso_cap(); } constexpr bool is_long() const { return mPtr != mBuf; } constexpr string() : mPtr{mBuf}, mBuf{} constexpr string(const char* data, size_t len) : 0 码力 | 17 页 | 790.91 KB | 1 年前3
C++20 STL Features: 1 Year of Development on GitHubu=""> constexpr bool cmp_equal(T t, U u) noexcept; templateconstexpr bool cmp_not_equal(T t, U u) noexcept; template ## constexpr Algorithms ## C++20 constexpr Everything • constexpr enables compile-timeconstexpr bool cmp_less(T u=""> constexpr bool cmp_greater(T t, U u) noexcept; template constexpr bool cmp_less_equal(T t, U u) noexcept; template constexpr bool cmp_greater_equal(T class="" t=""> constexpr bool in_range(T t) noexcept; 0 码力 | 45 页 | 702.09 KB | 1 年前3
C++20 STL Features: 1 Year of Development on GitHubu=""> constexpr bool cmp_equal(T t, U u) noexcept; templateconstexpr bool cmp_not_equal(T t, U u) noexcept; template ## constexpr Algorithms ## C++20 constexpr Everything • constexpr enables compile-timeconstexpr bool cmp_less(T u=""> constexpr bool cmp_greater(T t, U u) noexcept; template constexpr bool cmp_less_equal(T t, U u) noexcept; template constexpr bool cmp_greater_equal(T class="" t=""> constexpr bool in_range(T t) noexcept; 0 码力 | 45 页 | 989.72 KB | 1 年前3
Compile-Time Compression and Resource Generation with C++20libraries I created for this code • Discuss some techniques I found building compile-time libraries ## constexpr in Brief • Specifies a variable or function CAN appear in a constant expression • Constant expressions expressions can be evaluated at compile-time • eg: ■ Array size ☐ non-type template parameter ## constexpr Variable • Must be a Literal Type ☐ scalar (int, char, etc) array of literals ■ struct/class/union Implies const constexpr int Base{0b0010'1000}; constexpr std::arrayValues{1, 2, 3}; int main() { // Base += 1; // ERROR return Base + Values[1]; } # constexpr Function0 码力 | 59 页 | 1.86 MB | 1 年前3
Compile-Time Validationreporting can be used with compile-time error detection void foo() { constexpr auto error = detect_error(); if constexpr (error) { report_error(error); } } ## Error Reporting – static\_assert message must be a string literal which limits the information that can be provided void foo() { constexpr auto error = detect_error(); static_assert(!error, "error message"); ## Error Message foo() { constexpr auto error = std::optional(custom_error{}); if constexpr (error) { report_error<*error>(); } }; ## Error Message templateconstexpr auto report_error() 0 码力 | 137 页 | 1.70 MB | 1 年前3
Modern C++ Tutorial: C++11/14/17/20 On the FlyReadings 13 Chapter 02: Language Usability Enhancements 13 2.1 Constants 13 nullptr 13 constexpr 15 2.2 Variables and initialization 17 if-switch 17 Initialize list 18 Structured binding auto 21 decltype 22 tail type inference 23 decltype(auto) 24 2.4 Control flow 25 if constexpr 25 Range-based for loop 26 2.5 Templates 26 Extern templates ..... 26 The “>” ..... 27 the equality of the two types. We will discuss them in detail later in the decltype section. ## constexpr C++ itself already has the concept of constant expressions, such as $ 1+2 $ , $ 3*4 $ . Such0 码力 | 92 页 | 1.79 MB | 2 年前3
Secrets of C++ Scripting Bindingsreports and contributions from users, I learned about: • Template Meta Programming • Lambdas constexpr ## ChaiScript ChaiScript had a moderate amount of success, and through its development and via reports and contributions from users, I learned about: • Template Meta Programming • Lambdas constexpr • Static Analysis ## ChaiScript ChaiScript had a moderate amount of success, and through its development reports and contributions from users, I learned about: • Template Meta Programming • Lambdas constexpr • Static Analysis • Compiler Warning Options ## ChaiScript ## ChaiScript had a moderate amount0 码力 | 177 页 | 1.65 MB | 1 年前3
共 181 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
相关搜索词
constexprstd::pmrCUDA性能优化内存管理ModulesRangesCoroutinesConcurrency Changes编译器优化restrict汇编内联Small String Optimizationtemplatestruct压缩对联结GitHubC++20STLVisual C++ LibrariesC++20 STL FeaturesGitHub DevelopmentrangesvNextlookup tablesconfiguration fusesUSB descriptorsCompile-Time ValidationMitzitemplate metaprogrammingC++23Modern C++C++11/14/17/20nullptrstructured bindingsC++ Scripting BindingsChaiScriptC++嵌入式脚本引擎constexpr friendly













