@@ -9,16 +9,20 @@ type Platforms = CPU = 1 | NVidia = 2 | IntelGPU = 3 | AnyGPU = 4
99[<CliPrefix( CliPrefix.DoubleDash) >]
1010[<NoAppSettings>]
1111type ImageProcessingArguments =
12- | [<Mandatory>] Input of string
12+ | Input of string
1313 | Output of string
1414 | Platform of Platforms
15+ | WorkGroupSize of uint
16+ | MatrixSize of uint
1517 with
1618 interface IArgParserTemplate with
1719 member arg.Usage =
1820 match arg with
1921 | Input _ -> " Image to process."
2022 | Output _ -> " File to store result."
2123 | Platform _ -> " Where to run."
24+ | WorkGroupSize _ -> " Work group size."
25+ | MatrixSize _ -> " Number of columns (or rows). We use square matrices."
2226module Main =
2327 //let pathToExamples = "/home/gsv/Projects/TestProj2020/src/ImgProcessing/Examples"
2428 //let inputFolder = System.IO.Path.Combine(pathToExamples, "input")
@@ -32,27 +36,20 @@ module Main =
3236 let main ( argv : string array ) =
3337 let parser = ArgumentParser.Create< ImageProcessingArguments>( programName = " ImageProcessing" )
3438 let results = parser.ParseCommandLine argv
35- let inputFile = results.GetResult( Input, defaultValue = " " )
36- let outputFile = results.GetResult( Output, defaultValue = " out.jpg" )
39+ let input = results.GetResult( Input, defaultValue = " " )
40+ let output = results.GetResult( Output, defaultValue = " out.jpg" )
3741 let platform = results.GetResult( Platform, defaultValue = Platforms.CPU)
38-
42+ let workGroupSize = results.GetResult( WorkGroupSize, defaultValue = 64 u)
43+ let matrixSize = results.GetResult( MatrixSize, defaultValue = 512 u)
44+
3945 let filters = [
4046 ImageProcessing.gaussianBlurKernel
4147 ImageProcessing.gaussianBlurKernel
4248 ImageProcessing.edgesKernel
4349 ]
4450
4551
46- match platform with
47- | Platforms.CPU ->
48- let mutable image = ImageProcessing.loadAs2DArray inputFile
49- printfn $" Device: CPU"
50- let start = System.DateTime.Now
51- for filter in filters do
52- image <- ImageProcessing.applyFilter filter image
53- printfn $" CPU processing time: {(System.DateTime.Now - start).TotalMilliseconds} ms"
54- ImageProcessing.save2DByteArrayAsImage image outputFile
55- | _ ->
52+ let applyFiltersOnGPU =
5653 let device =
5754 match platform with
5855 | Platforms.AnyGPU -> ClDevice.GetFirstAppropriateDevice()
@@ -66,30 +63,39 @@ module Main =
6663 printfn $" Device: %A {device.Name}"
6764
6865 let context = ClContext( device)
69- let applyFiltersOnGPU = ImageProcessing.applyFiltersGPU context 64
70-
71-
66+ ImageProcessing.applyFiltersGPU context 64
67+ (*
68+ match platform with
69+ | Platforms.CPU ->
70+ let mutable image = ImageProcessing.loadAs2DArray input
71+ printfn $"Device: CPU"
7272 let start = System.DateTime.Now
73- let grayscaleImage = ImageProcessing.loadAsImage inputFile
73+ for filter in filters do
74+ image <- ImageProcessing.applyFilter filter image
75+ printfn $"CPU processing time: {(System.DateTime.Now - start).TotalMilliseconds} ms"
76+ ImageProcessing.save2DByteArrayAsImage image output
77+ | _ ->
78+ let start = System.DateTime.Now
79+ let grayscaleImage = ImageProcessing.loadAsImage input
7480 printfn $"Image reading time: {(System.DateTime.Now - start).TotalMilliseconds} ms"
7581
7682 let start = System.DateTime.Now
7783 let result = applyFiltersOnGPU filters grayscaleImage
7884 printfn $"GPU processing time: {(System.DateTime.Now - start).TotalMilliseconds} ms"
79- ImageProcessing.saveImage result outputFile
85+ printfn $"R: %A{result}"
86+ ImageProcessing.saveImage result output
87+ *)
8088
81- (*
8289 let start = System.DateTime.Now
8390
84- Streaming.processAllFiles inputFolder outputFolder [
85- //applyFiltersOnNvGPU filters
86- applyFiltersOnIntelGPU filters
91+ Streaming.processAllFiles input output [
92+ applyFiltersOnGPU filters
8793 ]
8894
8995 printfn
9096 $" TotalTime = %f {(System.DateTime.Now
9197 - start)
9298 .TotalMilliseconds}"
93- *)
99+
94100
95101 0
0 commit comments