# How to completely execute python code using CUDA

**URL:** <https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020>\
**Category:** Jetson Nano\
**Tags:** cuda, python\
**Created:** [January 30, 2023, 10:31am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020 "2023-01-30T10:31:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulzappcheck890](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pulzappcheck890](https://forums.developer.nvidia.com/u/pulzappcheck890)\
**Post date:** [January 30, 2023, 10:31am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/1 "2023-01-30T10:31:06Z")

</div>

I have been trying to run a facial detection program to be executed on GPU. Unfortunately, the program seems to be executing on the CPU and not on the GPU.

Thanks In advance.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [January 31, 2023, 3:11am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/3 "2023-01-31T03:11:57Z")

</div>

Hi,

Could you share more information about your use case?

Which framework do you use? PyTorch or TensorFlow?  
How do you install the package? Do you install the package with CUDA support?

Have you converted the model to TensorRT?

Thanks.

---

<div class="post-metadata">

**Author:** ![pulzappcheck890](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pulzappcheck890](https://forums.developer.nvidia.com/u/pulzappcheck890)\
**Post date:** [January 31, 2023, 3:56am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/4 "2023-01-31T03:56:16Z")

</div>

Yes, I have installed CUDA support and trying to go with PyTorch.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [February 1, 2023, 6:15am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/5 "2023-02-01T06:15:20Z")

</div>

Hi,

Is your PyTorch built with CUDA enabled?

You can try our prebuilt which is compiled with CUDA support.

> **[Installing PyTorch for Jetson Platform :: NVIDIA Deep Learning Frameworks...](https://docs.nvidia.com/deeplearning/frameworks/install-pytorch-jetson-platform/index.html)**
>
> This guide provides instructions for installing PyTorch for Jetson Platform.

Please notice that the command in the doc is for JetPack 5 users.  
You will need to change it to the JetPack you used manually.

Thanks.

---

<div class="post-metadata">

**Author:** ![pulzappcheck890](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pulzappcheck890](https://forums.developer.nvidia.com/u/pulzappcheck890)\
**Post date:** [February 1, 2023, 6:31am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/6 "2023-02-01T06:31:31Z")

</div>

It throws the error saying :

```auto
AssertionError: Torch not compiled with CUDA enabled

```

And this is the whole error:

```auto
Using cache found in /home/jetson/.cache/torch/hub/pytorch_vision_main
/home/jetson/.cache/torch/hub/pytorch_vision_main/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: ''If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
  warn(
/home/jetson/.cache/torch/hub/pytorch_vision_main/torchvision/models/detection/anchor_utils.py:63: UserWarning: Failed to initialize NumPy: module compiled against API version 0xf but this version of numpy is 0xe (Triggered internally at /root/pytorch/torch/csrc/utils/tensor_numpy.cpp:77.)
  device: torch.device = torch.device("cpu"),
/home/jetson/.cache/torch/hub/pytorch_vision_main/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
/home/jetson/.cache/torch/hub/pytorch_vision_main/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet18_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet18_Weights.DEFAULT` to get the most up-to-date weights.
  warnings.warn(msg)
Traceback (most recent call last):
  File "test.py", line 487, in <module>
    model = model.to('cuda')
  File "/home/jetson/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 989, in to
    return self._apply(convert)
  File "/home/jetson/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 641, in _apply
    module._apply(fn)
  File "/home/jetson/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 664, in _apply
    param_applied = fn(param)
  File "/home/jetson/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 987, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
  File "/home/jetson/.local/lib/python3.8/site-packages/torch/cuda/ __init__.py", line 221, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

```

I will try the method you mentioned as well.

Thanks

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [February 2, 2023, 7:06am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/7 "2023-02-02T07:06:31Z")

</div>

Hi,

Based on the error, the package doesn’t build with CUDA.  
Please let us know if our prebuilt help with your issue.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [March 7, 2023, 3:31am UTC](https://forums.developer.nvidia.com/t/how-to-completely-execute-python-code-using-cuda/241020/9 "2023-03-07T03:31:32Z")

</div>

Closed on March 7, 2023, 3:31am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
