89591

How to mark a function callable from host and device?

Question:

I have bunch of common functions like swap, min, max etc. How to mark them so I could call them both from the host and from the device?

Answer1:

You use __host__ __device__ before the function declaration, like:

__host__ __device__ int min(int A, int B) {return (A<B)?A:B;}

This is documented in the C programming guide <a href="http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#function-type-qualifiers" rel="nofollow">here</a>.

Recommend

  • Loading a TGA File and Using it with OpenGL
  • C++ exception safety paranoia: how much is too much?
  • How to use the File System Events API in Swift?
  • Column Nullability/Optionality: NULL vs NOT NULL
  • What's the benefit of the trailing apostrophe in character literals
  • How do I create shared library using ld?
  • Selection Sort, For Java
  • Android NFC read Tags issue. Activity starts each time on data received
  • openssl handshake failed
  • How to resolve docker host names (/etc/hosts) in containers
  • EF 4.1 DBContext AutoDetectChangesEnabled
  • Less Conflicting Session Manager for Zope 2
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Eclipse MTJ doesn't see Java ME SDK 3.0 devices
  • blade.php method outputting it's result to the form
  • Looking for good analogy/examples for monitor verses semaphore
  • RxJava debounce by arbitrary value
  • Eliminate partial duplicate rows from result set
  • Does Mobilefirst provide a provision to access web services directly?
  • D3 get axis values on zoom event
  • C: Incompatible pointer type initializing
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Custom validator control occupying space even though display set to dynamic
  • JSON response opens as a file, but I can't access it with JavaScript
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Different response to non-authenticated users and AJAX calls
  • Sony Xperia Z Tablet not found by adb
  • output of program is not same as passed argument
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Statically linking a C++ library to a C# process using CLI or any other way
  • How to get next/previous record number?
  • Why winpcap requires both .lib and .dll to run?
  • How do I rollback to a specific git commit
  • Change div Background jquery
  • need help with bizarre java.net.HttpURLConnection behavior
  • How does Linux kernel interrupt the application?
  • apache spark aggregate function using min value
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?