Workaround for Problem with No GPU support on SetiAstro Cosmic Clarity Scripts

I posted, earlier this week, a post about GPU support not working with the SetiAstroCosmicClarity scripts. I was talking with SetiAstro who asked if it would work on my system using their standalone application, and it did, flawlessly. A sharpening job that took 15-30 minutes defaulting to using CPU rather than my GPU, could be done in the standalone in 10 seconds or less.

I have been puzzling about this problem and inquiring on the SetiAstro discord channel, and it seems that something in Siril’s venv, possibly the tensorflow library, inhibits the ability to use the GPU. And it’s different for many GPUs, drivers, etc.

I don’t know how to do anything with that, and I presume that this thorny issue is occupying a good bit of the Siril dev team’s time. I, myself, wouldn’t know where to begin.

However, in the meantime I thought it would be fun to create a python script that would open a user-selected fits file on the user’s drive, copy it to the SetiAstro input directory, run the standalone SA sharpen script with GPU support selectable and operational, and then copy it back to the directory where the user-selected fits file came from. Running this script allows me to circumvent all the annoying back-and-forth file copy operations I would have to do to run the standlaone operation. I’m pretty pleased with it.

Of course, this script cannot be run within Siril because you’re back to the venv problem again. I think it would run but not use GPU in all cases.

The only configuration is a small .ini file containing a few items that can be set once and forgotten.

If anyone is interested, I could tidy this up and make it available somewhere. Of course, none of this would be necessary of Siril 1.4.4 is going to have a fix for this issue.

It’s a bit odd because Cosmic Clarity is provided as a set of frozen executables that use their own inbuilt python interpreter and include their own dependencies. However, if it works for you from the command line but not from Siril then perhaps the frozen executables aren’t perfectly isolated.

Does CC work from a command line if you activate the venv with source venv/bin/activate (or equivalent) and then run it?

Please could you test the attached experimental version of the CC script? Functionally it is exactly the same, but it strips out any venv-related environment variables that could be contaminating CC (PYTHONPATH, PYTHONHOME, VIRTUAL_ENV) which might solve the problem. This should ensure that it runs exactly as it would run from the command line outside the venv.

CC_denoise_test.py (14.8 KB)

If this works for you I’ll update all the CC scripts in the same way.

Sorry for no reply earlier. I hadn’t been on this forum for a few days.

The test denoise script runs without complaints about GPU but it seems much slower than the sharpening script run standalone, about the same speed as the sharpening script from siril. It took seven minutes.

Running the denoise script standalone took maybe 10 seconds. So even if the denoise script doesn’t complain, it’s not using GPU. I have determined that when the sharpen script complains, it’s CosmicClarity that’s doing the complaining, not Siril.

The setiastro folks say they think the problem may be Siril’s use of tensorflow. I have no idea if Siril is using tensorflow or not.

As for this:

Does CC work from a command line if you activate the venv with source venv/bin/activate (or equivalent) and then run it?

I’m not sure of the point of this test. CC already works from the command line without it. What directory do you want me to be in when I do that test?

The Siril script doesn’t use tensorflow, and Siril doesn’t use it internally at all either. All the script does is call CosmicClarity, which is a standalone program and is supposed to contain all its dependencies (it’s a “frozen package” which should contain its own python interpreter and all its dependencies, and basically not care about anything else). Clearly if it needs tensorflow it can get it when run standalone.

The starting point is, there should be zero difference calling it from the command line and calling it from Siril. Since there clearly is a difference for you (though not one I can recreate - it runs happily on my system with my GPU) then we need to find out why. Possibly

So, the first thing is to test whether being run inside Siril’s venv is the reason. You can activate the venv as described, and then when you run it from the command line it will have all the same environment variables as when it is being run by the script.

If it fails when run from the command line but with the venv active, then we will know it is the fact of being run from inside the venv that makes it fail and I can look for more ways to hide the venv from it. If it works, then we are back to head scratching.

I don’t think it matters what directory you’re in. Copy a file to the input directory inside your CC folder so it has something to work on, and just run it.

What is the forum you’re in touch with SetiAstro on? If this test doesn’t give any clues it might be useful for me to be able to talk to Franklin directly.

it’s their Discord channel.
What directory you’re in does matter if the command is source venv/bin/activate, no? I didn’t initially know whose venv you wanted me to activate, but I now see that you want me to activate Siril’s venv.