How to enable php run python script on GPU? [closed]
Asked Answered
A

1

6

In my php website, I call a python script using theano and running on GPU.

However, when calling this python script from php, it seems apache doesn't have any permissions on GPU so the program falls back on CPU, which is far less efficient compared to GPU.

How can I grant apache rights to run programs on GPU?

Acetylate answered 9/5, 2016 at 8:3 Comment(5)
Did you make sure your theano has GPU processing enabled (deeplearning.net/software/theano/tutorial/using_gpu.html)? Also, you may want to check Numba (A just-in-time compiler (from Continuum Analytics) specializing in NumPy) usage of GPU. See drive.google.com/drive/u/0/folders/0Bw5McUt95YdeanU5M0FFUlFsSjg.Soberminded
It may be worth to use a workaround. Start looped script (bash?) from regular user (or cron), that waiting a job (run python script). From php add job (it can be a text file with arguments).Superdreadnought
Also check this: https://mcmap.net/q/1290120/-server-cpu-and-gpu-with-lampFreefloating
Use sudo to call the PHP script. Configure your system so the Apache user can use sudo without a password for this Python script. Done.Clipclop
I agree with @AlexeyRytikov , you should use a workaround, maybe an external bash script.Pierette
V
0

I would split that up, save the requirement as event in some storage (redis for example or even rabbitmq) and listen to that with some daemonized script (cron would be a bad joice since its hard to make it run more often than every minute). The script will update the storage entry with the results and you can access it again in your http stack. You can implement the functionallity via ajax or utilize a usleep command in php to wait for the results. If using a while loop, dont forget to break it after 1 second or something, so the request is not running too long.

Your problem might be the configured user, that executes the php binary - it maybe not permitted to access those binaries on your system. Typically its the www-data user. By adding the www-data user to the necessary group, you might be able to solve it without splitting all up. Have a look at the binary's ownerships and permissions to figure that out.

Vesting answered 6/7, 2017 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.