topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 26, 2024, 7:31 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Run software on GPU to compress images?  (Read 2885 times)

nickodemos

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 145
    • View Profile
    • Donate to Member
Run software on GPU to compress images?
« on: January 10, 2023, 10:50 AM »
I compress PNG images with GitHub - fhanau/Efficient-Compression-Tool: Fast and effective C++ file optimizer as this is the best compressor I have found. As with any software that compresses a file, it takes time. I was wondering if there was a way to offload the compressing to the GPU to see if there is an increase in speed.

« Last Edit: January 10, 2023, 01:35 PM by Deozaan, Reason: make subject more descriptive »

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: Run software on GPU to compress images?
« Reply #1 on: January 10, 2023, 07:51 PM »
You'd probably have to find a program that uses OpenCL.

ECT doesn't seem to cause much CPU load, typically less than %20 on my machine so you could speed things up by running concurrent tasks.

Example:
Code: Text [Select]
  1. .\timeit.exe .\ect.exe -9 .\20221224-topaz-denoise.png
  2. Processed 1 file
  3. Saved 1.95MB out of 12.34MB (15.7650%)
  4.  
  5. Version Number:   Windows NT 6.2 (Build 9200)
  6. Exit Time:        12:32 am, Wednesday, January 11 2023
  7. Elapsed Time:     0:01:28.952
  8. Process Time:     0:01:28.937

Five concurrent processes on the same file, (five different names):
Code: Text [Select]
  1. .\timeit.exe .\ect.exe -9 .\20221224-topaz-denoise(x).png
  2. Processed 1 file
  3. Saved 1.95MB out of 12.34MB (15.7650%)
  4.  
  5. Version Number:   Windows NT 6.2 (Build 9200)
  6. Exit Time:        12:39 am, Wednesday, January 11 2023
  7. Elapsed Time:     0:01:42.891
  8. Process Time:     0:01:42.703

Time to process increased by 14 seconds, (this was the same for all processes give or take a few ms), CPU utilization was still under 60% so still plenty left for doing other things.

So for the cost of an extra 14 seconds I got a 5 fold increase in files processed, files had the same properties of course but it should still scale similarly.

nickodemos

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 145
    • View Profile
    • Donate to Member
Re: Run software on GPU to compress images?
« Reply #2 on: January 10, 2023, 10:38 PM »
The issue is that I can not script so if you are willing to help with a script to process all png files in the current directory with ECT then it would be appreciated.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: Run software on GPU to compress images?
« Reply #3 on: January 11, 2023, 05:31 AM »
The below tested ok on my machine, there's a lot of comments which should make it easy to understand.

Basically:
  • Grabs list of PNGs in directory
  • Splits list into number of cmd files along with formatting for ect.exe
  • Executes cmd files

NOTES:
  • Edit in the full path to ect.exe - see comments
  • Edit in your ect.exe options - see comments
  • I only run PowerShell 7+ so that's what I tested it on

You'll see a CLI window open for each cmd file running along with output from ect.exe in each, they close as each cmd file finishes.

Code: PowerShell [Select]
  1. <#
  2. RunEct.ps1
  3.  
  4. Open a PowerShell console:
  5.  
  6. path\to\RunEct.ps1 <path of PNG files> [-Threads <x>]
  7.  
  8. Default number of threads is 4
  9.  
  10. Examples:
  11.  
  12. .\RunEct.ps1 d:\png-images
  13. d:\RunEct.ps1 "f:\png images" -Threads 8
  14.  
  15. #>
  16.  
  17. param(
  18.   [Parameter(Mandatory=$true)][string]$Path,
  19.   [int]$Threads = 4
  20. )
  21.  
  22. # Full path to ect.exe
  23. $ectPath = "R:\ect.exe"
  24. # Options for ect.exe
  25. $ectOpts = "-9"
  26.  
  27. # Get the system TEMP path
  28. $tempPath = [System.IO.Path]::GetTempPath()
  29.  
  30. # Get all PNG files within the directory
  31. $files = (Get-ChildItem "$($Path)/*" -Include *.png)
  32.  
  33. # Collect the file names into a list
  34. $fileNames = $files.Name
  35. # Get the number of files
  36. $numberOfFiles = $fileNames.Count
  37. # Set the number of cmd files to the number of required threads to run
  38. # and set number of files per list
  39. $numberOfLists = $Threads
  40. $filesPerList = [Math]::Ceiling($numberOfFiles / $numberOfLists)
  41.  
  42. # Create a list to hold the cmd file names
  43. $cmdFiles = @()
  44. # Split the number of files between the number of lists
  45. for ($i = 0; $i -lt $numberOfLists; $i++) {
  46.   $startIndex = $i * $filesPerList
  47.   $endIndex = $startIndex + $filesPerList - 1
  48.   $list = $fileNames[$startIndex..$endIndex]
  49. # Create a temp cmd file
  50.   $filePath = [System.IO.Path]::Combine($tempPath, "ectTempFile$($i).cmd")
  51.   New-Item -Path $filePath -ItemType File -Force
  52. # Add it to the cmd file list
  53.   $cmdFiles += $filePath
  54. # Output that list of files to the cmd file with formatting to run ect.exe on each
  55.   $list | ForEach-Object {
  56.     "$($ectPath) $($ectOpts) `"$($_)`""
  57.   } | Set-Content -Path $filePath
  58. }
  59.  
  60. # Change current location to input path
  61. Push-Location $Path
  62.  
  63. # Execute each cmd file
  64. $cmdFiles | ForEach-Object {
  65. # Remove the hash (#) in the line below to have all output to the PowerShell console
  66.     Start-Process cmd.exe -ArgumentList "/c $($_)" #-NoNewWindow
  67. }
  68.  
  69. # Jump back to original path
  70. Pop-Location

Each ECT process causes ~10% CPU load on my Ryzen 5 5600X.
2023-01-12 13_08_30-Task Manager.pngRun software on GPU to compress images?
« Last Edit: January 11, 2023, 08:12 PM by 4wd »