Exemple #1
0
 public static DateTime ToDateTime(this timespec ts)
 {
     if (ts.IsNow() || ts.IsOmit())
     {
         throw new InvalidOperationException("Cannot convert meta value to DateTime");
     }
     return(new DateTime(UnixEpochTicks + TimeSpan.TicksPerSecond * ts.tv_sec + ts.tv_nsec / 100, DateTimeKind.Utc));
 }
        public static DateTimeOffset ToDTO(this timespec spec)
        {
            var s = spec.tv_sec;
            var n = spec.tv_nsec;

            var dto = DateTimeOffset.FromUnixTimeSeconds(s);

            dto.AddMilliseconds(n / 1000.0);

            return(dto);
        }
        public static timespec GetTimeSpec(this DateTimeOffset dto)
        {
            var ms = dto.ToUnixTimeMilliseconds();

            var t = new timespec()
            {
                tv_sec  = ms / 1000L,
                tv_nsec = (long_t)((ms % 1000L) * 1000L)
            };

            return(t);
        }
        private static void Nanosleep(int ns)
        {
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                throw new PlatformNotSupportedException("Only in Mono/Unix");
            }

            timespec rqtp = new timespec
            {
                tv_sec  = new IntPtr(0),
                tv_nsec = new IntPtr(ns)
            };

            timespec rmtp = new timespec();

            nanosleep(ref rqtp, ref rmtp);
        }
        public unsafe static PosixResult IoGetEvents(aio_context_t ctx, int min_nr, int nr, io_event *events, int timeoutMs)
        {
            timespec timeout    = default(timespec);
            bool     hasTimeout = timeoutMs >= 0;

            if (hasTimeout)
            {
                timeout.tv_sec  = timeoutMs / 1000;
                timeout.tv_nsec = 1000 * (timeoutMs % 1000);
            }
            int rv;

            do
            {
                rv = io_getevents(ctx, min_nr, nr, events, hasTimeout ? &timeout : null);
            } while (rv < 0 && errno == EINTR);

            return(PosixResult.FromReturnValue(rv));
        }
        public override int UpdateTimestamps(ReadOnlySpan <byte> path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef, Guid fileGuid)
        {
            path = base.TransformPath(path);

            if (debug)
            {
                Console.WriteLine($"NeoFS::UpdateTimestamps()");
            }

            timespec[] timeList = new timespec[2];
            timeList[0].tv_sec  = atime.tv_sec;
            timeList[0].tv_nsec = atime.tv_nsec;
            timeList[1].tv_sec  = mtime.tv_sec;
            timeList[1].tv_nsec = mtime.tv_nsec;

            fixed(timespec *timeA = &timeList[0])
            {
                var res = LibC.utimensat(0, toBp(path), timeA, 0);

                if (res < 0)
                    return(-LibC.errno); }
            }
Exemple #7
0
    static int Main()
    {
        vector <case_t> cases = read_test_cases();

        vector <layer_t> layers = new vector <layer_t>();

        conv_layer_t layer1 = new conv_layer_t(1, 5, 8, cases[0].data.size); // 28 * 28 * 1 -> 24 * 24 * 8
                                                                             //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                                                                             //ORIGINAL LINE: relu_layer_t * layer2 = new relu_layer_t(layer1->out.size);
        relu_layer_t layer2 = new relu_layer_t(new point_t([email protected]));
        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: pool_layer_t * layer3 = new pool_layer_t(2, 2, layer2->out.size);
        pool_layer_t layer3 = new pool_layer_t(2, 2, new point_t([email protected])); // 24 * 24 * 8 -> 12 * 12 * 8

        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: conv_layer_t * layer4 = new conv_layer_t(1, 3, 10, layer3->out.size);
        conv_layer_t layer4 = new conv_layer_t(1, 3, 10, new point_t([email protected])); // 12 * 12 * 6 -> 10 * 10 * 10
                                                                                         //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                                                                                         //ORIGINAL LINE: relu_layer_t * layer5 = new relu_layer_t(layer4->out.size);
        relu_layer_t layer5 = new relu_layer_t(new point_t([email protected]));
        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: pool_layer_t * layer6 = new pool_layer_t(2, 2, layer5->out.size);
        pool_layer_t layer6 = new pool_layer_t(2, 2, new point_t([email protected])); // 10 * 10 * 10 -> 5 * 5 * 10

        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: fc_layer_t * layer7 = new fc_layer_t(layer6->out.size, 10);
        fc_layer_t layer7 = new fc_layer_t(new point_t([email protected]), 10); // 4 * 4 * 16 -> 10

        layers.push_back((layer_t)layer1);
        layers.push_back((layer_t)layer2);
        layers.push_back((layer_t)layer3);
        layers.push_back((layer_t)layer4);
        layers.push_back((layer_t)layer5);
        layers.push_back((layer_t)layer6);
        layers.push_back((layer_t)layer7);



        float amse = 0F;
        int   ic   = 0;

        for (int ep = 0; ep < 100000;)
        {
            foreach (case_t t in cases)
            {
                float xerr = train(layers, t.data.functorMethod, [email protected]);
                amse += xerr;

                ep++;
                ic++;

                if (ep % 1000 == 0)
                {
                    Console.Write("case ");
                    Console.Write(ep);
                    Console.Write(" err=");
                    Console.Write(amse / ic);
                    Console.Write("\n");
                }

                // if ( GetAsyncKeyState( VK_F1 ) & 0x8000 )
                // {
                //     printf( "err=%.4f%\n", amse / ic  );
                //     goto end;
                // }
            }
        }
        // end:



        while (true)
        {
            uint8_t[] data = read_file("test.ppm");

            if (data != null)
            {
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                //ORIGINAL LINE: uint8_t * usable = data;
                uint8_t[] usable = new uint8_t(data);

                while ((uint32_t)usable != 0x0A353532)
                {
                    usable++;
                }

                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                //#pragma pack(push, 1)
                //C++ TO C# CONVERTER TODO TASK: C# does not allow declaring types within methods:
                //			struct RGB
                //			{
                //				uint8_t r, g, b;
                //			};
                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                //#pragma pack(pop)

                RGB[] rgb = (RGB)usable;

                tensor_t <float> image = new tensor_t <float>(28, 28, 1);
                for (int i = 0; i < 28; i++)
                {
                    for (int j = 0; j < 28; j++)
                    {
                        RGB rgb_ij = rgb[i * 28 + j];
                        image.functorMethod(j, i, 0) = ((((float)rgb_ij.r + rgb_ij.g + rgb_ij.b) / (3.0f * 255.0f)));
                    }
                }

                forward(layers, image.functorMethod);
                tensor_t <float> @out = layers.back().@out;
                for (int i = 0; i < 10; i++)
                {
                    Console.Write("[{0:D}] {1:f}\n", i, @out.functorMethod(i, 0, 0) * 100.0f);
                }

                data = null;
            }

            timespec wait = new timespec();
            wait.tv_sec  = 1;
            wait.tv_nsec = 0;
            nanosleep(wait, null);
        }
        return(0);
    }
Exemple #8
0
        public static int linux_sys_futex_wait(int helper_pid, uint handle, int op, Pointer shadowAddr, int val, timespec ts, uint bitset)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_FUTEX_WAIT);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, op);
            SetMR(4, shadowAddr.ToUInt32());
            SetMR(5, val);
            SetMR(6, ts.tv_sec);
            SetMR(7, ts.tv_nsec);
            SetMR(8, bitset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 9, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);

            return(l4_stub_ipc_error(res) != 0 ? -1 : 0);
        }
 public override int UpdateTimestamps(ReadOnlySpan <byte> path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef)
 => UpdateTimestamps(ToString(path), ref atime, ref mtime, fiRef);
Exemple #10
0
 public static bool IsOmit(this timespec ts)
 => ts.tv_nsec == UTIME_OMIT;
        public override int UpdateTimestamps(ReadOnlySpan <byte> path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef)
        {
            if (verbosity > 5)
            {
                Console.WriteLine($"UpdateTimestamps {path.GetString()} atime={atime.ToDTO()} mtime={mtime.ToDTO()}");
            }

            int error = 0, level = 0;
            var procs = ProcPath(path, ref error, ref level);

            if (error != 0)
            {
                return(-LibC.ENOENT);
            }

            var ent = procs.Pop();

            if (ent.Item2 == null)
            {
                return(-LibC.ENOENT);
            }

            var rec = ent.Item2;

            var update = new UpdateDefinitionBuilder <NeoAssets.Mongo.NeoVirtFS>()
                         .Set(rec => rec.Stat.st_atim, atime.ToDTO())
                         .Set(rec => rec.Stat.st_mtim, mtime.ToDTO());

            var result = NeoVirtFSCol.UpdateOne(Builders <NeoAssets.Mongo.NeoVirtFS> .Filter.Eq(x => x._id, rec._id), update);

            return(0);
        }
Exemple #12
0
        public static int linux_sys_futex_wait(int helper_pid, uint handle, int op, Pointer shadowAddr, int val, timespec ts, uint bitset)
        {
            SetMR(0, (int)Type.EXPRESSOS_OP_FUTEX_WAIT);
            SetMR(1, helper_pid);
            SetMR(2, handle);
            SetMR(3, op);
            SetMR(4, shadowAddr.ToUInt32());
            SetMR(5, val);
            SetMR(6, ts.tv_sec);
            SetMR(7, ts.tv_nsec);
            SetMR(8, bitset);

            var tag = new Msgtag((int)IPCTag.EXPRESSOS_IPC, 9, 0, 0);
            var res = l4_ipc_send(ArchGlobals.LinuxServerTid, tag, Timeout.Never);
            return l4_stub_ipc_error(res) != 0 ? -1 : 0;
        }
Exemple #13
0
 private extern static void nanosleep(ref timespec rqtp, ref timespec rmtp);
Exemple #14
0
 public static void nanosleep(timespec req, timespec rem)
 {
     Sleep((uint)(req.tv_sec * 1000) + (uint)(req.tv_nsec != 0 ? req.tv_nsec / 1000000 : 0));
 }
Exemple #15
0
 public static extern unsafe int kevent64(int kq, kevent64_s* changelist, int nchanges, kevent64_s* eventlist, int nevents, uint flags, timespec* timeout);
Exemple #16
0
 public static extern int nanosleep(ref timespec req, ref timespec rem);
Exemple #17
0
 public static extern int nanosleep(ref timespec request, IntPtr nullptr);
Exemple #18
0
 public static bool IsNow(this timespec ts)
 => ts.tv_nsec == UTIME_NOW;
Exemple #19
0
 public static extern int clock_gettime(int clockid, out timespec tp);
Exemple #20
0
 public static extern int clock_getres(int clockid, out timespec res);
Exemple #21
0
 public static extern int clock_nanosleep(int clockid, int flags, ref timespec request, IntPtr nullptr);
 protected virtual int UpdateTimestamps(string path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef)
 => - ENOSYS;
 public static extern int nanosleep(ref timespec req, ref timespec rem);
 private static extern int clock_gettime(clockid_t clk_id, out timespec tp);
 public virtual int UpdateTimestamps(ReadOnlySpan <byte> path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef)
 => - ENOSYS;
 public override int UpdateTimestamps(ReadOnlySpan <byte> path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef)
 {
     return(base.UpdateTimestamps(path, ref atime, ref mtime, fiRef));
 }
 public override int UpdateTimestamps(ReadOnlySpan <byte> path, ref timespec atime, ref timespec mtime, FuseFileInfoRef fiRef)
 {
     Console.WriteLine("UpdateTimestamps -> " + Encoding.UTF8.GetString(path));
     return(0);
 }