Beispiel #1
0
        public void FreeDevice()
        {
            lock (Sync)
            {
                if (_DeviceData != IntPtr.Zero)
                {
                    if (IsDeviceDirty)
                    {
                        for (int z = 0; z < Dims.Z; z++)
                        {
                            if (!IsHalf)
                            {
                                GPU.CopyDeviceToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(float)), HostData[z], ElementsSliceReal);
                            }
                            else
                            {
                                GPU.CopyDeviceHalfToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(short)), HostData[z], ElementsSliceReal);
                            }
                        }
                    }
                    GPU.FreeDevice(DeviceData);
                    GPU.OnMemoryChanged();
                    _DeviceData   = IntPtr.Zero;
                    IsDeviceDirty = false;
                }

                IsHostDirty = true;
            }
        }
Beispiel #2
0
        public float[][] GetHost(Intent intent)
        {
            lock (Sync)
            {
                if ((intent & Intent.Read) > 0 && IsDeviceDirty)
                {
                    for (int z = 0; z < Dims.Z; z++)
                    {
                        if (!IsHalf)
                        {
                            GPU.CopyDeviceToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(float)), HostData[z], ElementsSliceReal);
                        }
                        else
                        {
                            GPU.CopyDeviceHalfToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(short)), HostData[z], ElementsSliceReal);
                        }
                    }

                    IsDeviceDirty = false;
                }

                if ((intent & Intent.Write) > 0)
                {
                    IsHostDirty   = true;
                    IsDeviceDirty = false;
                }

                return(HostData);
            }
        }
Beispiel #3
0
        public float3[][] GetLastSimulationResults()
        {
            if (d_LastSimulationResult == IntPtr.Zero)
            {
                return(null);
            }

            float[] RawData = new float[NCoarseNodes * 3 * NSimulatedInstances];
            GPU.CopyDeviceToHost(d_LastSimulationResult, RawData, RawData.Length);

            float3[][] Result = new float3[NSimulatedInstances][];
            for (int n = 0; n < NSimulatedInstances; n++)
            {
                Result[n] = Helper.FromInterleaved3(RawData.Skip(n * NCoarseNodes * 3).Take(NCoarseNodes * 3).ToArray());
            }

            return(Result);
        }