Skip to Content
C++ High Performance
book

C++ High Performance

by Viktor Sehr, Björn Andrist
January 2018
Intermediate to advanced
374 pages
9h 53m
English
Packt Publishing
Content preview from C++ High Performance

Verify GPU computation on the CPU

As GPUs are generally harder to debug than a regular C++ program, verifying the results is utterly important. As we are dealing with floating-point math, the result might not be 100% accurate, therefore we use a flt_eq() function that accepts minor differences as equal:

auto test_kernel(bc::context& ctx, bc::command_queue& q, bc::kernel& k) {
  auto flt_eq = [](float a, float b) {     auto epsilon = 0.00001f;     return std::abs(a - b) <= epsilon;  }; 
  auto cpu = box_filter_test_cpu(2000, 1000, 2); 
  auto gpu = box_filter_test_gpu(2000, 1000, 2, ctx, q, k); 
  auto is_equal = cpu == dst; 
  auto is_almost_equal = std::equal(    cpu.begin(), cpu.end(), gpu.begin(), flt_eq ); std::cout << "is_equal: " << is_equal << '\n' << "is_almost_equal: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ High Performance - Second Edition

C++ High Performance - Second Edition

Björn Andrist, Viktor Sehr
Advanced C++

Advanced C++

Gazihan Alankus, Olena Lizina, Rakesh Mane, Vivek Nagarajan, Brian Price
C++ In a Nutshell

C++ In a Nutshell

Ray Lischner
C++ Cookbook

C++ Cookbook

D. Ryan Stephens, Christopher Diggins, Jonathan Turkanis, Jeff Cogswell

Publisher Resources

ISBN: 9781787120952Supplemental Content