Open cdeterman opened 5 years ago
Yes, you need to have both define
statements. However, you only need to compile that with nvcc
. That provides an executable that can do CUDA, OpenCL, and the CPU fallback.
As for the usage: The simplest is to create three viennacl::context
objects - one for CUDA, one for OpenCL, one for CPU. Then, you can switch between them via switch_memory_context
, e.g.
viennacl::switch_memory_context(vec, host_context);
See also here: http://viennacl.sourceforge.net/doc/classviennacl_1_1context.html#a88b51d155aee396ef6d8d8a96bd7e90a
This way you can shift data between CUDA, OpenCL, and CPU. Keep in mind, though, that you have to make sure that all objects involved in a computation are on the same memory domain. That is, if you try to add a vector with CUDA data to a vector with OpenCL data, an error will be thrown.
Early next week I will add an example of doing this to the repository.
@karlrupp did you ever have a chance to add the mentioned example?
@karlrupp replied to the issue here that it was possible to use both OpenCL and CUDA backends at runtime. Is there any example of this? I'm a little confused at the moment as the CUDA backend requires the
nvcc
compiler. Is there a repetitive compilation that runs through the files once withnvcc
and then another time withg++
? I would assume that flags for both OpenCL and CUDA would need to be definedAny guidance on how to accomplish using both backends would be valuable.