# How to select Serial/TBB/CUDA devices when using the vtkm Accelerators in vtk?

**URL:** https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487
**Category:** Support
**Created:** [January 23, 2020, 6:53pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487 "2020-01-23T18:53:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [January 23, 2020, 6:53pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487/1 "2020-01-23T18:53:35Z")

</div>

Hello,

I’m using the vtkm Accelerators in vtk but I can’t find a way to select which device (Serial/TBB/Cuda) the filters should use.

In vtkm I use the following approach (The code snipped below shows how I select the Cuda device for example)

```
  //vtkm::cont::ScopedRuntimeDeviceTracker(vtkm::cont::DeviceAdapterTagSerial{});
  //vtkm::cont::ScopedRuntimeDeviceTracker(vtkm::cont::DeviceAdapterTagTBB{});
  vtkm::cont::ScopedRuntimeDeviceTracker(vtkm::cont::DeviceAdapterTagCuda{});
  //vtkm::cont::ScopedRuntimeDeviceTracker(vtkm::cont::DeviceAdapterTagOpenMP{});

```

How can I achieve this when using the vtkm Accelerators in vtk?

Thanks,

Doug

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 24, 2020, 2:29pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487/2 "2020-01-24T14:29:23Z")

</div>

You can choose SMP backend (sequential, tbb, …) when you configure your project in CMake using VTK\_SMP\_IMPLEMENTATION\_TYPE CMake variable.

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [January 24, 2020, 9:17pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487/3 "2020-01-24T21:17:03Z")

</div>

Andras,

Thanks for the reply. I can only do this when I build vtk right? I can’t do this on a project by project basis for my projects that are referencing vtk?

Should I think about building two versions of vtk - one one with TBB (No Cuda) and the other with Cuda (No TBB)? And then configuring my application projects against one or the other?

Or is there a better way?

Doug

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 24, 2020, 10:59pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487/4 "2020-01-24T22:59:37Z")

</div>

> [@scotsman60](#):
>
> I can only do this when I build vtk right?

Correct.

> [@scotsman60](#):
>
> Should I think about building two versions of vtk - one one with TBB (No Cuda) and the other with Cuda (No TBB)?

I’m not aware of any incompatibilities between TBB and Cuda, so using TBB and/or Cuda are probably two independent decisions. You cannot change the SMP backend after you have built VTK. I don’t know if you can enable/disable Cuda support in VTK-m at runtime.

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [January 24, 2020, 11:12pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487/5 "2020-01-24T23:12:41Z")

</div>

Thanks Andreas,

Unless I hear a better solution I’m going to create two builds of vtk - one with Cuda and one with TBB and then just create two builds of my projects - one building against vtk\_cuda and the other against vtk\_tbb. Should be a one line change in my cmake file.

I prefer working with the vtkm accelerators in vtk because I can operate directly on vtk data structures and use all of the readers and it’s way easier to display the output compared with vtkm.

Right now I’m trying to compare the serial vtk filters with the TBB and Cuda versions from vtkm so that’s problematic right now because I don’t have the same control of the backend in vtk that I do in vtkm.

So I’d vote for providing this level of control as a short term priority for vtk. Although adding support for the higher order cell types would get my first vote…

Doug

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [January 25, 2020, 12:02pm UTC](https://discourse.vtk.org/t/how-to-select-serial-tbb-cuda-devices-when-using-the-vtkm-accelerators-in-vtk/2487/6 "2020-01-25T12:02:02Z")

</div>

Hello, Douglas,

Maybe you can try something called dynamic loading, when the executable loads a shared library manually during runtime instead of linking against it during build. You can build both versions of VTK, identify which libraries are different and dynamic load them depending on some kind of settings or command-line parameters.

Or, to take a more modern approach, you can create a plug-in infrastructure in your program and write two plug-ins: one with CUDA backend and the other with TBB backend. Then, to choose between them is just a matter of choosing an option in the load screen or something like that.

all the best,

Paulo
