'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports Matrox.MatroxImagingLibrary
Namespace MAppBenchmark
Public Structure PROC_PARAM
Public MilSourceImage As MIL_ID
Public MilDestinationImage As MIL_ID
End Structure
Public Class Program
Private Shared ReadOnly IMAGE_FILE As String = MIL.M_IMAGE_PATH & "LargeWafer.mim"
Private Const ROTATE_ANGLE As Integer = -15
Private Const MINIMUM_BENCHMARK_TIME As Double = 1.0
Private Const ESTIMATION_NB_LOOP As Integer = 5
Private Const DEFAULT_NB_LOOP As Integer = 100
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilDisplayImage As MIL_ID = MIL.M_NULL
Dim MilSystemOwnerApplication As MIL_ID = MIL.M_NULL
Dim MilSystemCurrentThreadId As MIL_ID = MIL.M_NULL
Dim ProcessingParam As New PROC_PARAM()
Dim TimeAllCores As Double = 0.0
Dim TimeAllCoresNoCS As Double = 0.0
Dim TimeOneCore As Double = 0.0
Dim FPSAllCores As Double = 0.0
Dim FPSAllCoresNoCS As Double = 0.0
Dim FPSOneCore As Double = 0.0
Dim NbCoresUsed As MIL_INT = 0
Dim NbCoresUsedNoCS As MIL_INT = 0
Dim UseGPUSystem As Boolean = False
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MsysInquire(MilSystem, MIL.M_OWNER_APPLICATION, MilSystemOwnerApplication)
MIL.MsysInquire(MilSystem, MIL.M_CURRENT_THREAD_ID, MilSystemCurrentThreadId)
If MIL.MsysInquire(MilSystem, MIL.M_SYSTEM_TYPE, MIL.M_NULL) = MIL.M_SYSTEM_GPU_TYPE Then
UseGPUSystem = True
End If
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilDisplayImage)
MIL.MdispSelect(MilDisplay, MilDisplayImage)
ProcessingInit(MilSystem, ProcessingParam)
Console.WriteLine()
Console.WriteLine("PROCESSING FUNCTION BENCHMARKING:")
Console.WriteLine("---------------------------------")
Console.WriteLine()
Console.WriteLine("This program times a processing function under ")
Console.WriteLine("different conditions.")
Console.WriteLine("Press <Enter> to start.")
Console.WriteLine()
Console.ReadKey()
Console.WriteLine("PROCESSING TIME FOR {0}x{1}:", _
MIL.MbufInquire(ProcessingParam.MilDestinationImage, MIL.M_SIZE_X, MIL.M_NULL), _
MIL.MbufInquire(ProcessingParam.MilDestinationImage, MIL.M_SIZE_Y, MIL.M_NULL))
Console.WriteLine("------------------------------")
Console.WriteLine()
If Not UseGPUSystem Then
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_MP_USE, MIL.M_DEFAULT, MIL.M_ENABLE, MIL.M_NULL)
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_CORE_SHARING, MIL.M_DEFAULT, MIL.M_ENABLE, MIL.M_NULL)
MIL.MthrInquireMp(MilSystemCurrentThreadId, MIL.M_CORE_NUM_EFFECTIVE, MIL.M_DEFAULT, MIL.M_DEFAULT, NbCoresUsed)
If (NbCoresUsed > 1) Then
Benchmark(ProcessingParam, TimeAllCores, FPSAllCores)
MIL.MbufCopy(ProcessingParam.MilDestinationImage, MilDisplayImage)
Console.WriteLine("Using multi-processing ({0,3} CPU cores): {1,5:0.000} ms ({2,6:0.0} fps)", NbCoresUsed, TimeAllCores, FPSAllCores)
End If
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_MP_USE, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL)
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_CORE_SHARING, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL)
'
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_MP_USE, MIL.M_DEFAULT, MIL.M_ENABLE, MIL.M_NULL)
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_CORE_SHARING, MIL.M_DEFAULT, MIL.M_DISABLE, MIL.M_NULL)
MIL.MthrInquireMp(MilSystemCurrentThreadId, MIL.M_CORE_NUM_EFFECTIVE, MIL.M_DEFAULT, MIL.M_DEFAULT, NbCoresUsedNoCS)
If (NbCoresUsedNoCS <> NbCoresUsed) Then
Benchmark(ProcessingParam, TimeAllCoresNoCS, FPSAllCoresNoCS)
MIL.MbufCopy(ProcessingParam.MilDestinationImage, MilDisplayImage)
Console.WriteLine("Using multi-processing ({0,3} CPU cores): {1,5:0.000} ms ({2,6:0.0} fps), no Hyper-Thread.", NbCoresUsedNoCS, TimeAllCoresNoCS, FPSAllCoresNoCS)
End If
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_MP_USE, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL)
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_CORE_SHARING, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL)
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_MP_USE, MIL.M_DEFAULT, MIL.M_DISABLE, MIL.M_NULL)
Benchmark(ProcessingParam, TimeOneCore, FPSOneCore)
MIL.MbufCopy(ProcessingParam.MilDestinationImage, MilDisplayImage)
Console.WriteLine("Without multi-processing ( 1 CPU core ): {0,5:0.000} ms ({1,6:0.0} fps)", TimeOneCore, FPSOneCore)
Console.WriteLine()
MIL.MappControlMp(MilSystemOwnerApplication, MIL.M_MP_USE, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL)
If (NbCoresUsed > 1) Then
Console.WriteLine("Benchmark is {0:0.0} times faster with multi-processing.", TimeOneCore / TimeAllCores)
Console.WriteLine()
End If
If (NbCoresUsedNoCS <> NbCoresUsed) Then
Console.WriteLine("Benchmark is {0:0.0} times faster with multi-processing and no Hyper-Thread.", TimeOneCore / TimeAllCoresNoCS)
Console.WriteLine()
End If
Else
Benchmark(ProcessingParam, TimeAllCores, FPSAllCores)
MIL.MbufCopy(ProcessingParam.MilDestinationImage, MilDisplayImage)
Console.WriteLine("Using GPU: {0,5:0.000} ms ({1,6:0.0} fps)", TimeAllCores, FPSAllCores)
End If
Console.WriteLine("Press <Enter> to end.")
Console.ReadKey()
ProcessingFree(ProcessingParam)
MIL.MdispSelect(MilDisplay, MIL.M_NULL)
MIL.MbufFree(MilDisplayImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
Private Shared Sub Benchmark(ByRef ProcParamPtr As PROC_PARAM, ByRef Time As Double, ByRef FramesPerSecond As Double)
Dim EstimatedNbLoop As MIL_INT = DEFAULT_NB_LOOP
Dim StartTime As Double = 0
Dim EndTime As Double = 0
Dim MinTime As Double = 0
Dim n As MIL_INT
MIL.MthrWait(MIL.M_DEFAULT, MIL.M_THREAD_WAIT, CType(MIL.M_NULL, IntPtr))
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, StartTime)
ProcessingExecute(ProcParamPtr)
MIL.MthrWait(MIL.M_DEFAULT, MIL.M_THREAD_WAIT, CType(MIL.M_NULL, IntPtr))
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, EndTime)
MinTime = EndTime - StartTime
For n = 0 To ESTIMATION_NB_LOOP - 1
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, StartTime)
ProcessingExecute(ProcParamPtr)
MIL.MthrWait(MIL.M_DEFAULT, MIL.M_THREAD_WAIT, CType(MIL.M_NULL, IntPtr))
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, EndTime)
Time = EndTime - StartTime
MinTime = If((Time < MinTime), Time, MinTime)
Next n
If MinTime > 0 Then
EstimatedNbLoop = CType(MINIMUM_BENCHMARK_TIME / MinTime, MIL_INT) + 1
End If
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, StartTime)
For n = 0 To EstimatedNbLoop - 1
ProcessingExecute(ProcParamPtr)
Next n
MIL.MthrWait(MIL.M_DEFAULT, MIL.M_THREAD_WAIT, CType(MIL.M_NULL, IntPtr))
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ, EndTime)
Time = EndTime - StartTime
FramesPerSecond = CType(EstimatedNbLoop, Double) / Time
Time = Time * 1000 / CType(EstimatedNbLoop, Double)
End Sub
Private Shared Sub ProcessingInit(ByVal MilSystem As MIL_ID, ByRef ProcParamPtr As PROC_PARAM)
Dim SizeBand As MIL_INT = MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_BAND, CType(MIL.M_NULL, IntPtr))
Dim SizeX As MIL_INT = MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_X, CType(MIL.M_NULL, IntPtr))
Dim SizeY As MIL_INT = MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_Y, CType(MIL.M_NULL, IntPtr))
Dim SizeBit As MIL_INT = MIL.MbufDiskInquire(IMAGE_FILE, MIL.M_SIZE_BIT, CType(MIL.M_NULL, IntPtr))
MIL.MbufAllocColor(MilSystem, SizeBand, SizeX, SizeY, SizeBit + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ProcParamPtr.MilSourceImage)
MIL.MbufLoad(IMAGE_FILE, ProcParamPtr.MilSourceImage)
MIL.MbufAllocColor(MilSystem, SizeBand, SizeX, SizeY, SizeBit + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ProcParamPtr.MilDestinationImage)
End Sub
Private Shared Sub ProcessingExecute(ByRef ProcParamPtr As PROC_PARAM)
MIL.MimRotate(ProcParamPtr.MilSourceImage, ProcParamPtr.MilDestinationImage, ROTATE_ANGLE, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_BILINEAR + MIL.M_OVERSCAN_CLEAR)
End Sub
Private Shared Sub ProcessingFree(ByRef ProcParamPtr As PROC_PARAM)
MIL.MbufFree(ProcParamPtr.MilSourceImage)
MIL.MbufFree(ProcParamPtr.MilDestinationImage)
End Sub
End Class
End Namespace