# Write a GPU/CPU agnostic package with Flux

**URL:** <https://discourse.julialang.org/t/write-a-gpu-cpu-agnostic-package-with-flux/29734>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [October 10, 2019, 3:26pm UTC](https://discourse.julialang.org/t/write-a-gpu-cpu-agnostic-package-with-flux/29734 "2019-10-10T15:26:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [October 10, 2019, 4:04pm UTC](https://discourse.julialang.org/t/write-a-gpu-cpu-agnostic-package-with-flux/29734/3 "2019-10-10T16:04:36Z")

</div>

Flux exports the function ‘gpu’ which wraps all arrays in CuArrays if cuda is available.

It has a (not exported iirc) function called has\_cuda (or maybe has\_gpu) which it uses to determine if cuda is available. It basically uses the method from this thread to do so [Weak dependence on CUDA packages, 2019 version](https://discourse.julialang.org/t/weak-dependence-on-cuda-packages-2019-version/29033)

---

_[View the full topic](https://discourse.julialang.org/t/write-a-gpu-cpu-agnostic-package-with-flux/29734)._
