Ejemplo n.º 1
0
        public View <TDataType, TExecutionSpace> MakeViewFromPointer <TDataType>(ulong n0,
                                                                                 ulong n1 = ulong.MaxValue,
                                                                                 ulong n2 = ulong.MaxValue,
                                                                                 ulong n3 = ulong.MaxValue,
                                                                                 ulong n4 = ulong.MaxValue,
                                                                                 ulong n5 = ulong.MaxValue,
                                                                                 ulong n6 = ulong.MaxValue,
                                                                                 ulong n7 = ulong.MaxValue)
            where TDataType : struct
        {
            int dataTypeSize = Unsafe.SizeOf <TDataType>();

            DataTypeKind dataType = DataType <TDataType> .GetKind();

            nint viewPtr = KokkosLibrary.IpcMakeViewFromPointer(executionSpaceType, dataType, Pointer, n0, n1, n2, n3, n4, n5, n6, n7);

            ushort rank = (ushort)KokkosLibrary.CalculateRank(n0, n1, n2, n3, n4, n5, n6, n7);

            NdArray ndArray = View <TDataType, TExecutionSpace> .RcpConvert(viewPtr, rank);

            ulong size = KokkosLibrary.CalculateSize(ndArray[0].Dim, ndArray[1].Dim, ndArray[2].Dim, ndArray[3].Dim, ndArray[4].Dim, ndArray[5].Dim, ndArray[6].Dim, ndArray[7].Dim);

            View <TDataType, TExecutionSpace> view = new View <TDataType, TExecutionSpace>(new NativePointer(viewPtr, (ulong)dataTypeSize * size), ndArray);

            return(view);
        }
Ejemplo n.º 2
0
        public static void Initialize(int gpuDeviceId = 0)
        {
            KokkosLibrary.Initialize(Environment.ProcessorCount,
                                     gpuDeviceId);

            //AppDomain.CurrentDomain.ProcessExit += View_Dtor;
        }
Ejemplo n.º 3
0
        public Devices()
        {
            Cpus = new List <CpuDevice>((int)KokkosLibrary.GetNumaCount());

            OperatingSystem os = Environment.OSVersion;

            for (int i = 0; i < (int)KokkosLibrary.GetNumaCount(); ++i)
            {
                Cpus.Add(new CpuDevice(i,
                                       $"{os.Platform:G}",
                                       (int)KokkosLibrary.GetCoresPerNuma(),
                                       (int)KokkosLibrary.GetCoresPerNuma() * (int)KokkosLibrary.GetThreadsPerCore(),
                                       new DeviceArch(RuntimeInformation.ProcessArchitecture == Architecture.X64 ? "x64" : "x86")));
            }

            Gpus = new List <GpuDevice>((int)KokkosLibrary.GetDeviceCount());

            uint gpuId = 0;

            foreach (PhysicalGPU physicalGpu in PhysicalGPU.GetPhysicalGPUs())
            {
                uint gpuVersion = KokkosLibrary.GetComputeCapability(gpuId);

                Gpus.Add(new CudaGpuDevice((int)gpuId,
                                           "Cuda",
                                           physicalGpu.ArchitectInformation.NumberOfCores,
                                           physicalGpu.ArchitectInformation.NumberOfCores,
                                           new DeviceArch(GetCudaDeviceName(gpuVersion), (int)gpuVersion),
                                           physicalGpu.UsageInformation));

                ++gpuId;
            }
        }
Ejemplo n.º 4
0
 private static void RrcTexasDataAdapter_Dtor(object?sender,
                                              EventArgs e)
 {
     if (KokkosLibrary.IsInitialized() || _initialized)
     {
         KokkosLibrary.FinalizeAll();
     }
 }
Ejemplo n.º 5
0
        public static void Initialize(int numCpuThreads,
                                      int gpuDeviceId)
        {
            KokkosLibrary.Initialize(numCpuThreads <= 0 ? Environment.ProcessorCount : numCpuThreads,
                                     gpuDeviceId);

            //AppDomain.CurrentDomain.ProcessExit += View_Dtor;
        }
Ejemplo n.º 6
0
        public InterprocessMemory(string label)
        {
            nint ptr = KokkosLibrary.IpcOpenExisting(executionSpaceType, new NativeString <Serial>(label));

            ulong size = KokkosLibrary.IpcGetSize(executionSpaceType, ptr);

            Pointer = new NativePointer(ptr, size);
        }
Ejemplo n.º 7
0
 private void ReleaseUnmanagedResources()
 {
     if (_isOwner)
     {
         KokkosLibrary.Free(executionSpace,
                            ((NativeStruct *)Instance)->Data);
     }
 }
Ejemplo n.º 8
0
        public void Dispose()
        {
            KokkosLibrary.IpcClose(executionSpaceType, Pointer.Data);
            KokkosLibrary.IpcDestory(executionSpaceType, Pointer.Data);

            Pointer?.Dispose();

            GC.SuppressFinalize(this);
        }
Ejemplo n.º 9
0
        public static bool IsRunning()
        {
            if (KokkosLibrary.IsLoaded)
            {
                return(KokkosLibrary.IsInitialized());
            }

            return(false);
        }
Ejemplo n.º 10
0
        public static ScopeGuard Get(int gpuDeviceId)
        {
            if (!_initialized)
            {
                KokkosLibrary.Initialize(Environment.ProcessorCount, gpuDeviceId);
                _initialized = true;
            }

            return(new ScopeGuard());
        }
Ejemplo n.º 11
0
        public static ScopeGuard Get(InitArguments arguments)
        {
            if (!_initialized)
            {
                KokkosLibrary.Initialize(arguments);
                _initialized = true;
            }

            return(new ScopeGuard());
        }
Ejemplo n.º 12
0
        public static View <double, TExecutionSpace> NearestNeighbor(View <double, TExecutionSpace> latlongdegrees)
        {
            nint result = KokkosLibrary.NearestNeighborDouble(latlongdegrees.Pointer, executionSpace);

            NdArray ndArray = View <double, TExecutionSpace> .RcpConvert(result, 1);

            View <double, TExecutionSpace> neighbors = new View <double, TExecutionSpace>(new NativePointer(result, sizeof(double) * latlongdegrees.Extent(0)), ndArray);

            return(neighbors);
        }
Ejemplo n.º 13
0
        public static ScopeGuard Get(int numCpuThreads,
                                     int gpuDeviceId)
        {
            if (!_initialized)
            {
                KokkosLibrary.Initialize(numCpuThreads, gpuDeviceId);
                _initialized = true;
            }

            return(new ScopeGuard());
        }
Ejemplo n.º 14
0
        public static View <double, TExecutionSpace> Shepard2d(View <double, TExecutionSpace> xd,
                                                               View <double, TExecutionSpace> zd,
                                                               double p,
                                                               View <double, TExecutionSpace> xi)
        {
            nint result = KokkosLibrary.Shepard2dDouble(xd.Pointer, zd.Pointer, p, xi.Pointer, executionSpace);

            NdArray ndArray = View <double, TExecutionSpace> .RcpConvert(result, 1);

            View <double, TExecutionSpace> zi = new View <double, TExecutionSpace>(new NativePointer(result, sizeof(double) * xi.Size()), ndArray);

            return(zi);
        }
Ejemplo n.º 15
0
        public static View <long, TExecutionSpace> GetCountLineEndings(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException();
            }

            char[] chars = File.ReadAllText(filename).ToCharArray();

            long n = chars.LongLength;

            nint result = 0;

            View <char, TExecutionSpace> stringView = new View <char, TExecutionSpace>("stringView", n);

            for (long i = 0; i < n; ++i)
            {
                stringView[i] = chars[i];
            }

            switch (executionSpace)
            {
            case ExecutionSpaceKind.Serial:
            {
                result = KokkosLibrary.CountLineEndingsSerial(stringView.Pointer);

                break;
            }

            case ExecutionSpaceKind.OpenMP:
            {
                result = KokkosLibrary.CountLineEndingsOpenMP(stringView.Pointer);

                break;
            }

            case ExecutionSpaceKind.Cuda:
            {
                result = KokkosLibrary.CountLineEndingsCuda(stringView.Pointer);

                break;
            }
            }

            NdArray ndArray = View <long, TExecutionSpace> .RcpConvert(result, 1);

            View <long, TExecutionSpace> lineEndings = new View <long, TExecutionSpace>(new NativePointer(result, sizeof(long) * n), ndArray);

            return(lineEndings);
        }
Ejemplo n.º 16
0
        public NativeArray(int size)
        {
            _pointer = NativePointer.Allocate(sizeof(NativeStruct),
                                              executionSpace);

            ((NativeStruct *)Instance)->Length = size;

            ((NativeStruct *)Instance)->Data = KokkosLibrary.Allocate(executionSpace,
                                                                      (ulong)(size * elementSize));

            _isOwner = true;

            data_pointer = (T *)((NativeStruct *)Instance)->Data;
        }
Ejemplo n.º 17
0
        public NativeArray(T[] array)
        {
            _pointer = NativePointer.Allocate(sizeof(NativeStruct),
                                              executionSpace);

            _isOwner = true;

            ((NativeStruct *)Instance)->Length = array.Length;

            ((NativeStruct *)Instance)->Data = KokkosLibrary.Allocate(executionSpace,
                                                                      (ulong)(array.Length * elementSize));

            data_pointer = (T *)((NativeStruct *)Instance)->Data;

            if (data_pointer != null)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    data_pointer[i] = array[i];
                }
            }
        }
Ejemplo n.º 18
0
        public static void Initialize(InitArguments arguments)
        {
            KokkosLibrary.Initialize(arguments);

            //AppDomain.CurrentDomain.ProcessExit += View_Dtor;
        }
Ejemplo n.º 19
0
 public InterprocessMemory(nint memoryPtr,
                           ulong size,
                           string label)
 {
     Pointer = new NativePointer(KokkosLibrary.IpcCreateFrom(executionSpaceType, memoryPtr, size, new NativeString <Serial>(label)), size);
 }
Ejemplo n.º 20
0
 public static void Print()
 {
     KokkosLibrary.PrintConfiguration(true);
 }
Ejemplo n.º 21
0
 public nint GetMemoryPointer()
 {
     return(KokkosLibrary.IpcGetMemoryPointer(executionSpaceType, Pointer.Data));
 }
Ejemplo n.º 22
0
 public nint GetDeviceHandle()
 {
     return(KokkosLibrary.IpcGetDeviceHandle(executionSpaceType, Pointer.Data));
 }
Ejemplo n.º 23
0
 public ulong GetSize()
 {
     return(KokkosLibrary.IpcGetSize(executionSpaceType, Pointer.Data));
 }
Ejemplo n.º 24
0
 public static void Shutdown()
 {
     KokkosLibrary.@Finalize();
 }