CAL Wrapper (Ready for Testing)

Moderators: slegrand, Site Moderators, PandeGroup

Re: CAL Wrapper (Ready for Testing)

Postby MtM » Sun Dec 12, 2010 1:04 pm

Sorry for not responding sooner.

Code: Select all
Imports System.Runtime.InteropServices

Namespace myCAL
#Region "Enumerations"
    Public Enum CALlanguage
        CAL_LANGUAGE_IL = 1
    End Enum
    Public Enum CALtarget
        CAL_TARGET_600                '/**< R600 GPU ISA */     
        CAL_TARGET_610                '/**< RV610 GPU ISA */   
        CAL_TARGET_630                '/**< RV630 GPU ISA */
        CAL_TARGET_670                ' /**< RV670 GPU ISA */
        CAL_TARGET_7XX                '/**< R700 class GPU ISA */
        CAL_TARGET_770                '/**< RV770 GPU ISA */
        CAL_TARGET_710                '/**< RV710 GPU ISA */
        CAL_TARGET_730                '/**< RV730 GPU ISA */
        CAL_TARGET_CYPRESS            '/**< CYPRESS GPU ISA */
        CAL_TARGET_JUNIPER            '/**< JUNIPER GPU ISA */
        CAL_TARGET_REDWOOD            '/**< REDWOOD GPU ISA */
        CAL_TARGET_CEDAR
    End Enum
    Public Enum CALformat
        CAL_FORMAT_UBYTE_1 = 1
        CAL_FORMAT_UBYTE_2 = 2
        CAL_FORMAT_UBYTE_4 = 3
        CAL_FORMAT_USHORT_1 = 4
        CAL_FORMAT_USHORT_2 = 5
        CAL_FORMAT_USHORT_4 = 6
        CAL_FORMAT_UINT_4 = 7
        CAL_FORMAT_BYTE_4 = 8
        CAL_FORMAT_SHORT_1 = 9
        CAL_FORMAT_SHORT_2 = 10
        CAL_FORMAT_SHORT_4 = 11
        CAL_FORMAT_FLOAT_1 = 12
        CAL_FORMAT_FLOAT_2 = 13
        CAL_FORMAT_FLOAT_4 = 14
        CAL_FORMAT_DOUBLE_1 = 15
        CAL_FORMAT_DOUBLE_2 = 16
        CAL_FORMAT_UINT_1 = 17
        CAL_FORMAT_UINT_2 = 18
        CAL_FORMAT_BYTE_1 = 19
        CAL_FORMAT_BYTE_2 = 20
        CAL_FORMAT_INT_1 = 21
        CAL_FORMAT_INT_2 = 22
        CAL_FORMAT_INT_4 = 23
    End Enum
    Public Enum CALresult
        CAL_RESULT_OK = 0
        CAL_RESULT_ERROR = 1
        CAL_RESULT_INVALID_PARAMETER = 2
        CAL_RESULT_NOT_SUPPORTED = 3
        CAL_RESULT_ALREADY = 4
        CAL_RESULT_NOT_INITIALIZED = 5
        CAL_RESULT_BAD_HANDLE = 6
        CAL_RESULT_BAD_NAME_TYPE = 7
        CAL_RESULT_PENDING = 8
        CAL_RESULT_BUSY = 9
        CAL_RESULT_WARNING = 10
    End Enum
    Public Enum CALboolean
        CAL_FALSE = 0
        CAL_TRUE = 1
    End Enum
    Public Enum CALresallocflags
        CAL_RESALLOC_CACHEABLE = 2
        CAL_RESALLOC_GLOBAL_BUFFER = 1
    End Enum
#End Region

#Region "Structures"

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALfunc
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALfuncInfo
        Public maxScratchRegsNeeded As UInteger
        Public numSharedGPRUser As UInteger
        Public numSharedGPRTotal As UInteger
        Public eCsSetupMode As CALboolean
        Public numThreadPerGroup As UInteger
        Public totalNumThreadGroup As UInteger
        Public wavefrontPerSIMD As UInteger
        Public numWavefrontPerSIMD As UInteger
        Public isMaxNumWavePerSIMD As CALboolean
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALimage
        Public Value As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALname
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALobject
        Public Value As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALprogramGrid
        Public func As CALfunc
        Public gridBlock As CALdomain3D
        Public gridSize As CALdomain3D
        Public flags As UInteger
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALmem
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdevicestatus
        Public struct_size As UInteger
        Public availLocalRAM As UInteger
        Public availUncachedRemoteRAM As UInteger
        Public availCachedRemoteRAM As UInteger
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALmodule
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdeviceinfo
        Public target As CALtarget
        Public maxResource1DWidth As UInteger
        Public maxResource2DWidth As UInteger
        Public maxResource2DHeight As UInteger
    End Structure


    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdeviceattribs
        Public struct_size As UInt32         '/**< Client filled out size of CALdeviceattribs struct */
        Public target As CALtarget            '/**< Asic identifier */
        Public localRAM As UInt32            '/**< Amount of local GPU RAM in megabytes */
        Public uncachedRemoteRAM As UInt32   '/**< Amount of uncached remote GPU memory in megabytes */
        Public cachedRemoteRAM As UInt32     '/**< Amount of cached remote GPU memory in megabytes */
        Public engineClock As UInt32         '/**< GPU device clock rate in megahertz */
        Public memoryClock As UInt32         '/**< GPU memory clock rate in megahertz */
        Public wavefrontSize As UInt32       '/**< Wavefront size */
        Public numberOfSIMD As UInt32        '/**< Number of SIMDs */
        Public doublePrecision As CALboolean    '/**< double precision supported *'/
        Public localDataShare As CALboolean      '/**< local data share supported *'/
        Public globalDataShare As CALboolean     '/**< global data share supported *'/
        Public globalGPR As CALboolean            '/**< global GPR supported *'/
        Public computeShader As CALboolean       '/**< compute shader supported *'/
        Public memExport As CALboolean           '/**< memexport supported *'/
        Public pitch_alignment As UInt32     '/**< Required alignment for calCreateRes allocations (in data elements) *'/
        Public surface_alignment As UInt32   '/**< Required start address alignment for calCreateRes allocations (in bytes) *'/
        Public numberOfUAVs As UInt32        '/**< Number of UAVs */
        Public bUAVMemExport As CALboolean      '/**< Hw only supports mem export to simulate 1 UAV */
        Public b3dProgramGrid As CALboolean      '/**< CALprogramGrid for have height and depth bigger than 1*/
        Public numberOfShaderEngines As UInt32 '/**< Number of shader engines */
        Public targetRevision As UInt32      '/**< Asic family revision */
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdeviceattribs_2
        Public struct_size As UInt32         '/**< Client filled out size of CALdeviceattribs struct */
        Public target As CALtarget            '/**< Asic identifier */
        Public localRAM As UInt32            '/**< Amount of local GPU RAM in megabytes */
        Public uncachedRemoteRAM As UInt32   '/**< Amount of uncached remote GPU memory in megabytes */
        Public cachedRemoteRAM As UInt32     '/**< Amount of cached remote GPU memory in megabytes */
        Public engineClock As UInt32         '/**< GPU device clock rate in megahertz */
        Public memoryClock As UInt32         '/**< GPU memory clock rate in megahertz */
        Public wavefrontSize As UInt32       '/**< Wavefront size */
        Public numberOfSIMD As UInt32        '/**< Number of SIMDs */
        Public doublePrecision As CALboolean    '/**< double precision supported *'/
        Public localDataShare As CALboolean      '/**< local data share supported *'/
        Public globalDataShare As CALboolean     '/**< global data share supported *'/
        Public globalGPR As CALboolean            '/**< global GPR supported *'/
        Public computeShader As CALboolean       '/**< compute shader supported *'/
        Public memExport As CALboolean           '/**< memexport supported *'/
        Public pitch_alignment As UInt32     '/**< Required alignment for calCreateRes allocations (in data elements) *'/
        Public surface_alignment As UInt32   '/**< Required start address alignment for calCreateRes allocations (in bytes) *'/
    End Structure








    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdevice
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdomain
        Public x As UInteger
        Public y As UInteger
        Public width As UInteger
        Public height As UInteger
    End Structure

    <StructLayout(LayoutKind.Sequential)>
    Public Structure CALcontext
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALdomain3D
        Public width As UInteger
        Public height As UInteger
        Public depth As UInteger
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALprogramGridArray
        <MarshalAs(UnmanagedType.LPArray)> _
        Public gridArray As CALprogramGrid()
        Public num As UInteger
        Public flags As UInteger
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALresource
        Public Value As UInt32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CALevent
        Public Value As UInt32
    End Structure

#End Region

    Public Class CALRuntimeX64
        ' Methods
        Public Sub New()
        End Sub
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxCreate(ByVal ctx As CALcontext, ByVal dev As CALdevice) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxDestroy(ByVal ctx As CALcontext) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxFlush(ByVal ctx As CALcontext) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxGetMem(ByVal mem As CALmem, ByVal ctx As CALcontext, ByVal res As CALresource) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxIsEventDone(ByVal ctx As CALcontext, ByVal e As CALevent) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxReleaseMem(ByVal ctx As CALcontext, ByVal mem As CALmem) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxRunProgram(ByVal e As CALevent, ByVal ctx As CALcontext, ByVal func As CALfunc, ByRef domain As CALdomain) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxRunProgramGrid(ByVal e As CALevent, ByVal ctx As CALcontext, ByRef pProgramGrid As CALprogramGrid) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxRunProgramGridArray(ByVal e As CALevent, ByVal ctx As CALcontext, <[In]()> ByVal pGridArray As CALprogramGridArray()) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calCtxSetMem(ByVal ctx As CALcontext, ByVal name As CALname, ByVal mem As CALmem) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calDeviceClose(ByVal dev As CALdevice) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calDeviceGetAttribs(<Out()> ByVal attribs As CALdeviceattribs, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calDeviceGetCount(<Out()> ByVal count As UInt64) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calDeviceGetInfo(<Out()> ByVal info As CALdeviceinfo, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calDeviceGetStatus(<Out()> ByVal status As CALdevicestatus, ByVal device As CALdevice) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calDeviceOpen(ByVal dev As CALdevice, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calGetErrorString() As String
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calGetVersion(<Out()> ByVal major As UInt32, <Out()> ByVal minor As UInt32, <Out()> ByVal imp As UInt32) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calImageFree(ByVal image As CALimage) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calImageRead(ByVal image As CALimage, ByVal buffer As Byte(), ByVal size As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calInit() As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calMemCopy(ByVal e As CALevent, ByVal ctx As CALcontext, ByVal srcMem As CALmem, ByVal dstMem As CALmem, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calModuleGetEntry(ByVal func As CALfunc, ByVal ctx As CALcontext, ByVal [module] As CALmodule, ByVal procName As String) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calModuleGetFuncInfo(ByVal pInfo As CALfuncInfo, ByVal ctx As CALcontext, ByVal [module] As CALmodule, ByVal func As CALfunc) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calModuleGetName(ByVal name As CALname, ByVal ctx As CALcontext, ByVal [module] As CALmodule, ByVal varName As String) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calModuleLoad(ByVal [module] As CALmodule, ByVal ctx As CALcontext, ByVal image As CALimage) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calModuleUnload(ByVal ctx As CALcontext, ByVal [module] As CALmodule) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResAllocLocal1D(ByVal res As CALresource, ByVal dev As CALdevice, ByVal width As UInteger, ByVal format As CALformat, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResAllocLocal2D(ByVal res As CALresource, ByVal dev As CALdevice, ByVal width As UInteger, ByVal height As UInteger, ByVal format As CALformat, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResAllocRemote1D(ByVal res As CALresource, <[In]()> ByVal dev As CALdevice(), ByVal deviceCount As UInteger, ByVal width As UInteger, ByVal format As CALformat, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResAllocRemote2D(ByVal res As CALresource, <[In]()> ByVal dev As CALdevice(), ByVal deviceCount As UInteger, ByVal width As UInteger, ByVal height As UInteger, ByVal format As CALformat, _
  ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResFree(ByVal res As CALresource) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResMap(ByVal pPtr As IntPtr, ByVal pitch As UInteger, ByVal res As CALresource, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calResUnmap(ByVal res As CALresource) As CALresult
        End Function
        <DllImport("aticalrt64")> _
        Public Shared Function calShutdown() As CALresult
        End Function
    End Class

    Public Class CALRuntimeX86
        ' Methods
        Public Sub New()
        End Sub
        <DllImport("aticalrt")> _
        Public Shared Function calCtxCreate(ByVal ctx As CALcontext, ByVal dev As CALdevice) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxDestroy(ByVal ctx As CALcontext) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxFlush(ByVal ctx As CALcontext) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxGetMem(ByVal mem As CALmem, ByVal ctx As CALcontext, ByVal res As CALresource) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxIsEventDone(ByVal ctx As CALcontext, ByVal e As CALevent) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxReleaseMem(ByVal ctx As CALcontext, ByVal mem As CALmem) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxRunProgram(ByVal e As CALevent, ByVal ctx As CALcontext, ByVal func As CALfunc, ByRef domain As CALdomain) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxRunProgramGrid(ByVal e As CALevent, ByVal ctx As CALcontext, ByRef pProgramGrid As CALprogramGrid) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxRunProgramGridArray(ByVal e As CALevent, ByVal ctx As CALcontext, <[In]()> ByVal pGridArray As CALprogramGridArray()) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calCtxSetMem(ByVal ctx As CALcontext, ByVal name As CALname, ByVal mem As CALmem) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calDeviceClose(ByVal dev As CALdevice) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Overloads Shared Function calDeviceGetAttribs(<Out()> ByRef attribs As CALdeviceattribs, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Overloads Shared Function calDeviceGetAttribs(<Out()> ByRef attribs As CALdeviceattribs_2, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calDeviceGetCount(<Out()> ByRef count As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")>
        Public Shared Function calDeviceGetInfo(<Out()> ByRef info As CALdeviceinfo, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calDeviceGetStatus(<Out()> ByVal status As CALdevicestatus, ByVal device As CALdevice) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calDeviceOpen(ByVal dev As CALdevice, ByVal ordinal As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calGetErrorString() As String
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calGetVersion(<Out()> ByRef major As UInt32, <Out()> ByRef minor As UInt32, <Out()> ByRef imp As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calImageFree(ByVal image As CALimage) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calImageRead(ByVal image As CALimage, ByVal buffer As Byte(), ByVal size As UInt32) As CALresult
        End Function
        <DllImport("aticalrt"), CLSCompliant(False)> _
        Public Shared Function calInit() As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calMemCopy(ByVal e As CALevent, ByVal ctx As CALcontext, ByVal srcMem As CALmem, ByVal dstMem As CALmem, ByVal flags As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calModuleGetEntry(ByVal func As CALfunc, ByVal ctx As CALcontext, ByVal [module] As CALmodule, ByVal procName As String) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calModuleGetFuncInfo(ByVal pInfo As CALfuncInfo, ByVal ctx As CALcontext, ByVal [module] As CALmodule, ByVal func As CALfunc) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calModuleGetName(ByVal name As CALname, ByVal ctx As CALcontext, ByVal [module] As CALmodule, ByVal varName As String) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calModuleLoad(ByVal [module] As CALmodule, ByVal ctx As CALcontext, ByVal image As CALimage) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calModuleUnload(ByVal ctx As CALcontext, ByVal [module] As CALmodule) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResAllocLocal1D(ByVal res As CALresource, ByVal dev As CALdevice, ByVal width As UInt32, ByVal format As CALformat, ByVal flags As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResAllocLocal2D(ByVal res As CALresource, ByVal dev As CALdevice, ByVal width As UInteger, ByVal height As UInteger, ByVal format As CALformat, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResAllocRemote1D(ByVal res As CALresource, <[In]()> ByVal dev As CALdevice(), ByVal deviceCount As UInt32, ByVal width As UInt32, ByVal format As CALformat, ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResAllocRemote2D(ByVal res As CALresource, <[In]()> ByVal dev As CALdevice(), ByVal deviceCount As UInt32, ByVal width As UInt32, ByVal height As UInt32, ByVal format As CALformat, _
  ByVal flags As UInteger) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResFree(ByVal res As CALresource) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResMap(ByVal pPtr As IntPtr, ByVal pitch As UInt32, ByVal res As CALresource, ByVal flags As UInt32) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calResUnmap(ByVal res As CALresource) As CALresult
        End Function
        <DllImport("aticalrt")> _
        Public Shared Function calShutdown() As CALresult
        End Function
    End Class

End Namespace


Code: Select all
#Region "CAL"
        Public Structure scalInfo
            Private cResX86 As CALresult, cResX64 As CALresult
            Public bX64 As Boolean, bX86 As Boolean
            Private cError As String
            Public ReadOnly Property calError As String
                Get
                    Return cError
                End Get
            End Property
            Private sRunTime As String
            Public ReadOnly Property Runtime As String
                Get
                    Return sRunTime
                End Get
            End Property
            Public Structure scalDevice
                Public Property Ordinal As UInt32
                Private Info As myCAL.CALdeviceinfo
                Public Sub SetInfo(ByVal dInfo As myCAL.CALdeviceinfo)
                    Info = dInfo
                End Sub
                Public ReadOnly Property DeviceInfo As myCAL.CALdeviceinfo
                    Get
                        Return Info
                    End Get
                End Property
                Private Attributes As Object
                Public Property AttributeStructure As eAttributeStructure
                Public Enum eAttributeStructure
                    [default]
                    Alternate
                End Enum
                Public Overloads Sub SetAttributes(ByVal dAttributes As myCAL.CALdeviceattribs)
                    Attributes = dAttributes
                End Sub
                Public Overloads Sub SetAttributes(ByVal Da2 As myCAL.CALdeviceattribs_2)
                    Attributes = Da2
                End Sub
                Public ReadOnly Property DeviceAttributes As myCAL.CALdeviceattribs
                    Get
                        If TypeOf Attributes Is myCAL.CALdeviceattribs Then Return CType(Attributes, myCAL.CALdeviceattribs)
                    End Get
                End Property
                Public ReadOnly Property DeviceAttributes2 As myCAL.CALdeviceattribs_2
                    Get
                        If TypeOf Attributes Is myCAL.CALdeviceattribs_2 Then Return CType(Attributes, myCAL.CALdeviceattribs_2)
                    End Get
                End Property

                Public Sub Init(ByVal uiOrdinal As UInt32)
                    Ordinal = uiOrdinal
                End Sub
            End Structure
            Private alDevices As ArrayList
            Public ReadOnly Property Devices As ArrayList
                Get
                    Return alDevices
                End Get
            End Property
            Public ReadOnly Property DeviceCount As Int32
                Get
                    Return alDevices.Count
                End Get
            End Property
            Public Sub Init(Optional ByVal fixDisplay As Boolean = False)
                Try
                    alDevices = New ArrayList
                    sRunTime = ""

                    Dim iLoop As Int32 = 0
Retry:
                    Dim bRetry As Boolean = False
                    Try
                        'cResX64 = CALRuntimeX64.calInit
                        cResX86 = CALRuntimeX86.calInit
                    Catch ex As AccessViolationException
                        'REM calInit only works when any nvidia devices are not attached!
                        'Dim sP() As ServiceProcess.ServiceController = ServiceController.GetServices
                        'For Each sService As ServiceController In sP
                        '    If sService.DisplayName = "NVIDIA Display Driver Service" Then
                        '        ' If sService.Status = ServiceControllerStatus.Running Then sService.Stop()
                        '        ' Dim tsWait As TimeSpan = New TimeSpan(0, 0, 0, 1)
                        '        ' sService.WaitForStatus(ServiceControllerStatus.Stopped, tsWait)
                        '    End If
                        'Next
                        'bRetry = True
                        'iLoop += 1
                    End Try
                    'If bRetry And iLoop < 3 Then GoTo Retry

                    bX64 = False '(cResX64 = CALresult.CAL_RESULT_OK Or cResX64 = CALresult.CAL_RESULT_ALREADY)
                    bX86 = (cResX86 = CALresult.CAL_RESULT_OK Or cResX86 = CALresult.CAL_RESULT_ALREADY)
                    If Not bX86 AndAlso Not bX64 Then Return
                    Dim cMa As UInt32, cMi As UInt32, cIm As UInt32
                    If bX86 Then
                        If CALRuntimeX86.calGetVersion(cMa, cMi, cIm) <> CALresult.CAL_RESULT_OK Then
                            SetcalError(eRunTime.X86)
                            GoTo calClose
                        Else
                            sRunTime = cMa.ToString & "." & cMi.ToString & "." & cIm.ToString
                        End If
                    End If
                    If bX64 Then
                        If CALRuntimeX64.calGetVersion(cMa, cMi, cIm) <> CALresult.CAL_RESULT_OK Then
                            SetcalError(eRunTime.X64)
                            GoTo calClose
                        Else
                            sRunTime = cMa.ToString & "." & cMi.ToString & "." & cIm.ToString
                        End If
                    End If
                    cMa = Nothing : cMi = Nothing : cIm = Nothing
                    Dim iCount As UInt32 = 0
                    If bX86 Then
                        Try
                            Dim iCal As Int32 = Get_calCount()
                            If iCal = -1 Then
                                SetcalError(eRunTime.X86)
                                GoTo calClose
                            Else
                                For xInt As UInt32 = 0 To CInt(iCal) - 1
                                    Dim nD As New scalDevice
                                    nD.Init(xInt)
                                    nD.Ordinal = xInt
                                    With nD
                                        Dim dI As CALdeviceinfo
                                        If CALRuntimeX86.calDeviceGetInfo(dI, xInt) <> CALresult.CAL_RESULT_OK Then
                                            SetcalError(eRunTime.X86)
                                            dI = Nothing
                                            GoTo calClose
                                        Else
                                            nD.SetInfo(dI)
                                            dI = Nothing
                                        End If
                                        Dim dA As New myCAL.CALdeviceattribs
                                        dA.struct_size = System.Runtime.InteropServices.Marshal.SizeOf(dA)
                                        Dim mD As New CALdevice
                                        If CALRuntimeX86.calDeviceOpen(mD, xInt) <> CALresult.CAL_RESULT_OK Then
                                            cResX86 = CALRuntimeX86.calDeviceGetAttribs(dA, xInt)
                                            If Not cResX86 = CALresult.CAL_RESULT_OK Then
                                                If cResX86 <> CALresult.CAL_RESULT_INVALID_PARAMETER Then
                                                    SetcalError(eRunTime.X86)
                                                    dA = Nothing
                                                    GoTo calClose
                                                Else
                                                    dA = Nothing
                                                    Dim dA2 As New myCAL.CALdeviceattribs_2
                                                    dA2.struct_size = Marshal.SizeOf(dA2)
                                                    cResX86 = CALRuntimeX86.calDeviceGetAttribs(dA2, xInt)
                                                    If cResX86 <> CALresult.CAL_RESULT_OK Then
                                                        SetcalError(eRunTime.X86)
                                                        dA2 = Nothing
                                                        GoTo calClose
                                                    End If
                                                    nD.SetAttributes(dA2)
                                                    nD.AttributeStructure = scalDevice.eAttributeStructure.Alternate
                                                    dA2 = Nothing
                                                End If
                                            Else
                                                nD.SetAttributes(dA)
                                                nD.AttributeStructure = scalDevice.eAttributeStructure.default
                                                dA = Nothing
                                            End If
                                            CALRuntimeX86.calDeviceClose(mD)
                                        Else
                                            SetcalError(eRunTime.X86)
                                            GoTo calClose
                                        End If

                                    End With
                                    alDevices.Add(nD)
                                Next
                            End If
                        Catch AccesEx As AccessViolationException
                            REM Throw when there are displays active on nvidia?
                            SetcalError(eRunTime.X86)
                        End Try

                    End If
                    If bX64 Then
                        If CALRuntimeX64.calDeviceGetCount(iCount) <> CALresult.CAL_RESULT_OK Then
                            SetcalError(eRunTime.X64)
                            GoTo calClose
                        Else

                        End If
                    End If

calClose:
                    'If bRetry Then
                    '    Dim sP() As ServiceProcess.ServiceController = ServiceController.GetServices
                    '    For Each sService As ServiceController In sP
                    '        If sService.DisplayName = "NVIDIA Display Driver Service" Then
                    '            'If sService.Status = ServiceControllerStatus.Stopped Then sService.Start()
                    '            'Dim tsWait As TimeSpan = New TimeSpan(0, 0, 0, 5)
                    '            'sService.WaitForStatus(ServiceControllerStatus.Running, tsWait)
                    '        End If
                    '    Next
                    'End If
                    Close()
                Catch ex As Exception
                    Close()
                End Try
            End Sub
            Private Enum eRunTime
                X64
                X86
            End Enum
            Private Sub SetcalError(ByVal Runtime As eRunTime)
                Try
                    If Runtime = eRunTime.X64 Then
                        cError = CALRuntimeX64.calGetErrorString
                    Else
                        cError = CALRuntimeX86.calGetErrorString
                    End If
                Catch ex As Exception
                    cError = ex.Message
                End Try
            End Sub
            Private Function Get_calCount() As Int32
                On Error Resume Next
                Dim iCount As Int32 = 0
                If CALRuntimeX86.calDeviceGetCount(iCount) <> CALresult.CAL_RESULT_OK Then
                    SetcalError(eRunTime.X86)
                    Return -1
                End If
                Return iCount
            End Function
            Public Sub Close()
                If bX64 Then
                    cResX64 = CALRuntimeX64.calShutdown
                    bX64 = (cResX64 = CALresult.CAL_RESULT_OK Or cResX64 = CALresult.CAL_RESULT_ALREADY)
                ElseIf bX86 Then
                    cResX86 = CALRuntimeX86.calShutdown
                    bX86 = (cResX86 = CALresult.CAL_RESULT_OK Or cResX86 = CALresult.CAL_RESULT_ALREADY)
                End If

            End Sub
        End Structure
        Public cInfo As New scalInfo
        Private Function cal_Init() As Boolean
            Try
                cInfo.Init()
                If cInfo.bX64 Or cInfo.bX86 Then
                    cInfo.Close()
                End If
                Return cInfo.DeviceCount > 0
            Catch ex As Exception
                'logwindow.writeerror("cal_init",err)
                Return False
            End Try
        End Function
#End Region


This is the relevant part. When I posted last time I was some steps behind what I posted above iirc ( maybe even more then a few steps, might have been using cal.net from gass still ). Which is old, and looks for the older dll's ( amdcrtl vs atictrl ect ).

Cal_init always succeeds, no matter display topology. Calgetruntime also always works but device count and attribute enumeration only works in a mixed environment when ati is the primary display. Nvidia can be present in the system but when it drives a display, the cal runtime keeps throwing errors. I was thinking it is a cal issue, and not my code, at least after I wrote my own wrapper functions, maybe cal just does not like active nvidia drivers. But if that's the case, you should be able to confirm it ( as I would guess you would encounter the same situation unless it's only a windows driver limitation and directly a cal runtime limitation ).

So I treid some things like disabling nvidia hw, do cal detection, re enable nvidia before I threw in the towel as it would be cumbersome.

And about the url for the svn, it was in my signature before I removed it, there is a two week gap between my post and yours.

I stopped working on my project since there is another project which is more actively developed and supported which does almost all the things I wanted, and there is no point in doing something when there is an alternative which is as good as this one, and since ati now ships ocl drivers cal detection isn't crucial to any project I guess but I wouldn't mind having a definitive answer to the question if cal detection should work in my described case or not ( eg, is it my code or is it the runtime itself ).

Cheers in advance, and again sorry for the late reply!

Edit: just noticed there is an url to a repository in my signature, but I'm not sure how long it's been there ( haven't logged on the forum for a long time, idk ).
MtM
 
Posts: 3054
Joined: Fri Jun 27, 2008 2:20 pm
Location: The Netherlands

Previous

Return to unOfficial Linux GPU (WINE wrapper) (3rd party support)

Who is online

Users browsing this forum: No registered users and 1 guest

cron