Ejemplo n.º 1
0
        public static void Example4()
        {
            SharedCollection shared = new SharedCollection();

            for (int i = 0; i < 5; i++)
            {
                Task.Run(() => Console.WriteLine(shared[2]));
            }
        }
        public SharedCollection GetSharedCollection()
        {
            if (_shared == null)
            {
                _shared = new SharedCollection();
            }

            return(_shared);
        }
        public static CollectionContributorDTO FromSharedCollection(SharedCollection sharedCollection)
        {
            var user = UserDtoBuilder.FromApplicationUser(sharedCollection.User).Create();

            return(new CollectionContributorDTO
            {
                CollectionId = sharedCollection.CollectionId,
                EditRights = sharedCollection.EditRights,
                User = user,
                UserId = user.Id
            });
        }
Ejemplo n.º 4
0
        protected SharedCollection ShareCollection(int collectionId, string userId, bool editRights)
        {
            var sharedCollection = new SharedCollection
            {
                CollectionId = collectionId,
                UserId       = userId,
                EditRights   = editRights
            };

            InTransaction(context =>
            {
                context.SharedCollection.Add(sharedCollection);
                context.SaveChanges();
            });
            return(sharedCollection);
        }
Ejemplo n.º 5
0
 public Scenario_01(Scenario_01_WebApplicationFactory factory, ITestOutputHelper output)
 {
     _client = factory.GetClient();
     _shared = factory.GetSharedCollection();
     _output = output;
 }
Ejemplo n.º 6
0
        public static void RunAccelerator(Accelerator accelerator)
        {
            using var context = accelerator.CreateContext();

            var watch = new Stopwatch();

            watch.Start();

            var ilProgram = new ILProgram(context);

            var ilKernel = ilProgram.Compile <Action <Matrix4x4[], Matrix4x4[], uint> >(ExampleKernel);

            Console.WriteLine($"Compile kernel: {watch.ElapsedMilliseconds}ms");

            var source = ilProgram.CompleteSource(ilProgram.Kernels.First());

            File.WriteAllText("kernel.cl", source); // Save source for debugging

            const int size   = 1024 * 100;
            const int rounds = 25;

            var random = new Random();

            var totalFail = 0L;
            var totalGpu  = 0L;
            var totalCpu  = 0L;

            var results = new Matrix4x4[size];

            var data = new Matrix4x4[size];

            using var input = new SharedCollection <Matrix4x4>(context, data, true);

            using var output = new SharedCollection <Matrix4x4>(context, results, true);

            for (var j = 0; j < rounds; j++)
            {
                for (var i = 0; i < size; i++)
                {
                    data[i].M11 = random.Next(1, 1000);
                    data[i].M12 = random.Next(1, 1000);
                    data[i].M13 = random.Next(1, 1000);
                    data[i].M14 = random.Next(1, 1000);
                    data[i].M21 = random.Next(1, 1000);
                    data[i].M22 = random.Next(1, 1000);
                    data[i].M23 = random.Next(1, 1000);
                    data[i].M24 = random.Next(1, 1000);
                    data[i].M31 = random.Next(1, 1000);
                    data[i].M32 = random.Next(1, 1000);
                    data[i].M33 = random.Next(1, 1000);
                    data[i].M34 = random.Next(1, 1000);
                    data[i].M41 = random.Next(1, 1000);
                    data[i].M42 = random.Next(1, 1000);
                    data[i].M43 = random.Next(1, 1000);
                    data[i].M44 = random.Next(1, 1000);
                }

                watch.Restart();

                ilKernel.Invoke(size, input.UPtr, output.UPtr, (UIntPtr)size);

                var gpu = watch.ElapsedMilliseconds;

                watch.Restart();

                for (var i = 0; i < size; i++)
                {
                    var value = data[i];

                    for (var k = 0; k < 100; k++)
                    {
                        value = Multiply(value, value);
                    }

                    data[i] = value;
                }

                var cpu = watch.ElapsedMilliseconds;

                watch.Stop();

                var failed = 0;

                for (var i = 0; i < size; i++)
                {
                    if (!results[i].Equals(data[i]))
                    {
                        failed++;
                    }
                }

                if (failed == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }

                Console.WriteLine(
                    $"[{j + 1:0000}/{rounds:0000}] Kernel succeeded with {Percent(size, failed)} operations at {Percent(cpu, gpu, true)} IL speed!"
                    );

                totalFail += failed;
                totalCpu  += cpu;
                totalGpu  += gpu;

                Console.ResetColor();
            }

            Console.WriteLine(
                $"Ran {rounds} rounds in sets of {size}, total operations: {rounds * size}\n" +
                $"Total success: {Percent(size * rounds, totalFail)} with {totalFail} errors\n" +
                $"Total speed: {Percent(totalCpu, totalGpu, true)} IL speed with {totalCpu}ms CPU-time and {totalGpu}ms GPU-time"
                );

            accelerator.Dispose();
        }