Vulkan compute with Python with VkInline and think about GPU machine learning and more

background

At least with Colab + Tesla P100 I could use Vulkan.

https://qiita.com/syoyo/items/3956e98e4a607cde6cb2

(How about V100 or A100?)

Try VkInline, which can call the Vulkan compute kernel inline from python, like a cupy.

https://github.com/fynv/VkInline

You will need the Vulkan 1.2 driver. (Currently, only RADV (AMD OSS (?) Linux Vulkan driver) or Windows Adrenalin driver supports 1.2?)

VkInline

The license is Anti 996 license (Companies that ignore the Labor Standards Act, such as 9:09 (21:00), 6 days a week, should not use anti-996 licensed software)

https://github.com/996icu/996.ICU

Build

There is no particular problem, and if you follow the procedure, it will be smooth.

Execution environment setup

I can go about.

This time, I confirmed the operation with RX5700 (Navi) with RADV driver.

Note using Vulkan (compute kernel) with RADV with ROCm https://qiita.com/syoyo/items/ce3943757281acbdba49

move

Let's run test_compute.py.

// from VkInline test_compute.py
import VkInline as vki
import numpy as np

# interface with numpy
harr = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype='float32')
darr = vki.device_vector_from_numpy(harr)
print(darr.to_host())

# GLSL data type
print(darr.name_view_type())

harr2 = np.array([6,7,8,9,10], dtype='int32')
darr2 = vki.device_vector_from_numpy(harr2)

# kernel with auto parameters, launched twice with different types
kernel = vki.Computer(['arr_in', 'arr_out', 'k'],
'''
void main()
{
    uint id = gl_GlobalInvocationID.x;
    if (id >= get_size(arr_in)) return;
    set_value(arr_out, id, get_value(arr_in, id)*k);
}
''')

darr_out = vki.SVVector('float', 5)
kernel.launch(1,128, [darr, darr_out, vki.SVFloat(10.0)])
print (darr_out.to_host())

darr_out = vki.SVVector('int', 5)
kernel.launch(1,128, [darr2, darr_out, vki.SVInt32(5)])
print (darr_out.to_host())

# create a vector from python list with GLSL type specified
darr3 = vki.device_vector_from_list([3.0, 5.0, 7.0, 9.0 , 11.0], 'float')
print(darr3.to_host())
[1. 2. 3. 4. 5.]
Comb_bb4c7639fd354507
[10. 20. 30. 40. 50.]
[30 35 40 45 50]
[ 3.  5.  7.  9. 11.]

:tada:

Outlook

I'm surprised that it works smoothly without any problems! You can expect it, but there are various issues to make an application such as machine learning from here.

TODO

Recommended Posts

Vulkan compute with Python with VkInline and think about GPU machine learning and more
Machine learning with Python! Preparation
Beginning with Python machine learning
What I learned about AI and machine learning using Python (4)
Machine learning with python (1) Overall classification
"Scraping & machine learning with Python" Learning memo
[Machine learning] Try running Spark MLlib with Python and make recommendations
"Gaussian process and machine learning" Gaussian process regression implemented only with Python numpy
Amplify images for machine learning with python
Machine learning with python (2) Simple regression analysis
A story about machine learning with Kyasuket
[Shakyo] Encounter with Python for machine learning
Personal notes and links about machine learning ① (Machine learning)
Python and machine learning environment construction (macOS)
Build AI / machine learning environment with Python
A story about automating online mahjong (Mahjong Soul) with OpenCV and machine learning
[Python] Easy introduction to machine learning with python (SVM)
Machine learning starting with Python Personal memorandum Part2
Machine learning starting with Python Personal memorandum Part1
Think about depth-priority and width-priority searches in Python
[Python] Collect images with Icrawler for machine learning [1000 images]
I started machine learning with Python Data preprocessing
Machine Learning with docker (40) with anaconda (40) "Hands-On Data Science and Python Machine Learning" By Frank Kane
Python learning notes for machine learning with Chainer Chapters 11 and 12 Introduction to Pandas Matplotlib
Build a Python machine learning environment with a container
Until you create a machine learning environment with Python on Windows 7 and run it
What I learned about AI / machine learning using Python (1)
Getting Started with python3 # 2 Learn about types and variables
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Run a machine learning pipeline with Cloud Dataflow (Python)
Easy machine learning with scikit-learn and flask ✕ Web app
Python learning memo for machine learning by Chainer Chapters 1 and 2
What I learned about AI / machine learning using Python (3)
Build a machine learning application development environment with Python
Summary of the basic flow of machine learning with Python
Practical machine learning with Scikit-Learn and TensorFlow-TensorFlow gave up-
What I learned about AI / machine learning using Python (2)
Set up python and machine learning libraries on Ubuntu
Talk about improving machine learning algorithm bottlenecks with Cython
Learning Python with ChemTHEATER 03
"Object-oriented" learning with python
Learning Python with ChemTHEATER 05-1
Think yaml with python
Learning Python with ChemTHEATER 02
Learning Python with ChemTHEATER 01
Machine learning A story about people who are not familiar with GBDT using GBDT in Python
A story about developing a machine learning model while managing experiments and models with Azure Machine Learning + MLflow
[Machine learning] Start Spark with iPython Notebook and try MLlib
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
I started machine learning with Python Clustering & Dimension Compression & Visualization
Create a python machine learning model relearning mechanism with mlflow
Machine learning to learn with Nogizaka46 and Keyakizaka46 Part 1 Introduction
Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)
Easy deep learning web app with NNC and Python + Flask
Programming with Python and Tkinter
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
About python objects and classes
About Python variables and objects
Think about architecture in python
Reinforcement learning starting with Python