public override void Forward(Gpu gpu, BufferField temporaryOutput, ref BufferField output) { var ow = output.Width; var oh = output.Height; var oc = output.Channels; var obuf = output.Buffer; var tobuf = temporaryOutput.Buffer; gpu.For(0, output.Length, n => { int c = (int)(n / (ow * oh)); int l = n - c * (ow * oh); int y = (int)(l / ow); int x = l - y * ow; obuf[c][x, y] = tobuf[c][x, y]; }); }
public void ActivationForward() { Tensor x = CreateRandomTensor(400, 1200); Tensor.Like(x, out Tensor y1); CpuDnn.ActivationForward(x, ActivationFunctions.Sigmoid, y1); Gpu gpu = Gpu.Default; using (DeviceMemory <float> x_gpu = gpu.AllocateDevice(x), y_gpu = gpu.AllocateDevice <float>(x.Size)) { Dnn.Get(gpu).ActivationForward(x.Entities, x.Length, x_gpu.Ptr, y_gpu.Ptr, ActivationFunctions.Sigmoid); y_gpu.CopyToHost(y1.Entities, y1.Length, out Tensor y2); Assert.IsTrue(y1.ContentEquals(y2)); Tensor.Free(x, y1, y2); } }
private static double[] NewMethod(Gpu gpu, int[] arg1, int[] arg2, int Length, int rand) { var result = new double[Length]; gpu.LongFor(0, Length, i => { /* for (var k = 0; k < 10000; ++k) * { * * * result[i] = arg1[k]+arg2[k]; * }*/ }); return(result); }
public void CopyToRows() { float[] test = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Tensor.NewZeroed(3, 10, out Tensor tensor); Gpu gpu = Gpu.Default; using (DeviceMemory <float> m_gpu = gpu.AllocateDevice(test)) { m_gpu.CopyTo(tensor, 5, 3); } float[,] expected = { { 0, 0, 0, 0, 0, 1, 2, 3, 0, 0 }, { 0, 0, 0, 0, 0, 4, 5, 6, 0, 0 }, { 0, 0, 0, 0, 0, 7, 8, 9, 0, 0 } }; Assert.IsTrue(tensor.ToArray2D().ContentEquals(expected)); }
public void Check_For_Successful_Implementation_Of_Method_UnloadProducts() { Product product = new HardDrive(4.5); var productsCount = 3; for (int i = 1; i <= productsCount; i++) { this.vehicle.LoadProduct(product); } var lastProductInTrunk = new Gpu(2.5); this.vehicle.LoadProduct(lastProductInTrunk); var unloadProduct = vehicle.Unload(); Assert.AreSame(lastProductInTrunk, unloadProduct); }
static Scope CreateScopeFromGameInfo(GameInfo gameInfo) { var scope = new Scope(new SentryOptions { AttachStacktrace = false, ReportAssemblies = false, }); var contexts = scope.Contexts; contexts.Clear( ); contexts["runtime"] = new Runtime { Name = gameInfo.Runtime, }; var gpu = gameInfo.Gpu; contexts["gpu"] = new Gpu { Id = gpu.Id, ApiType = gpu.GraphicsDeviceType, MemorySize = gpu.MemorySize, MultiThreadedRendering = gpu.MultiThreaded, Name = gpu.Name, VendorId = gpu.VendorId, VendorName = gpu.VendorName, Version = gpu.Version, }; contexts["app"] = new App { Name = gameInfo.AppName, Version = gameInfo.GameVersion, }; contexts["os"] = new Sentry.Protocol.OperatingSystem( ) { RawDescription = gameInfo.OperatingSystem }; return(scope); }
public Form1() { InitializeComponent(); gpu = Gpu.Default; typeof(Form1).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, this, new object[] { true }); string[] files = Directory.GetFiles(Path.Combine(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..")), @"Images\"), "*.bmp", SearchOption.AllDirectories); allDigits = new Digit[files.Length]; for (int i = 0; i < files.Length; i++) { allDigits[i] = new Digit(files[i]); } layersizes = new[] { 137, 57, 24, 10 }; allNeuronWeights = new double[populationSize][][][]; allNeurons = new Neuron[populationSize][][]; allInputs = new double[populationSize][][]; for (int i = 0; i < populationSize; i++) { allNeuronWeights[i] = new double[layersizes.Length][][]; for (int j = 0; j < layersizes.Length; j++) { allNeuronWeights[i][j] = new double[layersizes[j]][]; allNeuronWeights[i][j][0] = new double[784]; for (int k = 1; k < layersizes[j]; k++) { allNeuronWeights[i][j][k] = new double[layersizes[k - 1]]; } } } R = new Random(); population = new NeuralNetwork[populationSize]; for (int i = 0; i < populationSize; i++) { population[i] = new NeuralNetwork(i, allNeuronWeights, allNeurons, allInputs); } updatePopulationTimer = new Timer() { Enabled = true, Interval = 1 }; updatePopulationTimer.Tick += UpdatePopulation; scores.Add(10); }
public async void GetAsync_EntityInDatabase_RecordFoundWithCorrectValues() { var connection = PersistenceTestingHelper.SetupSqLiteDb(); try { // Arrange var frequency = 1500; var memory = 4000; using (var contextToPopulateData = PersistenceTestingHelper.CreateDbContextForSqLite(connection)) { var entity = new Gpu() { ID = 1, Frequency = frequency, Memory = memory }; contextToPopulateData.Gpu.Add(entity); contextToPopulateData.SaveChanges(); } var logger = new Mock <ILogger>().Object; var mapper = new AutoMapperConfiguration().GetIMapper(); // using a different to make sure data is fetched from the db and not coming from the contextToPopulateData using (var databaseContext = PersistenceTestingHelper.CreateDbContextForSqLite(connection)) { var uow = new UnitOfWork(databaseContext, logger); var service = new GpuService(uow, mapper, logger); // Act var result = await service.GetAsync(); // Assert result.Should().NotBeNull(); result.Frequency.Should().Be(frequency); result.Memory.Should().Be(memory); } } finally { connection.Close(); } }
public void GenerateData(ComputersEntities data, IRandomGenerator random, int count) { var vendorIds = data.Vendors .Select(x => x.VendorId) .ToList(); for (var i = 0; i < count; i++) { var gpu = new Gpu { MemoryInGb = random.GetRandomNumber(1, 32), VendorId = vendorIds[random.GetRandomNumber(0, vendorIds.Count - 1)], Model = random.GetRandomString(random.GetRandomNumber(1, 30)), Type = i % 3 == 0 ? "internal" : "external" }; data.Gpus.Add(gpu); } }
public static void Alea(Gpu gpu, Real[] matrix, Real[] vector, int m, int n) { using (var cudaMatrix = gpu.AllocateDevice(matrix)) using (var cudaVector = gpu.AllocateDevice(vector)) { var timer = Stopwatch.StartNew(); var gridSizeX = Util.DivUp(n, 32); var gridSizeY = Util.DivUp(m, 8); var lp = new LaunchParam(new dim3(gridSizeX, gridSizeY), new dim3(32, 8)); gpu.Launch(AleaKernel, lp, cudaMatrix.Ptr, cudaVector.Ptr, m, n); gpu.Synchronize(); Util.PrintPerformance(timer, "AddVector.Alea", 3, m, n); Gpu.Copy(cudaMatrix, matrix); } }
public override void Back(Gpu gpu, BufferField sigma, BufferField temporaryOutput, ref BufferField temporarySigma) { var tsw = temporarySigma.Width; var tsh = temporarySigma.Height; var tsc = temporarySigma.Channels; var tsbuf = temporarySigma.Buffer; var sbuf = sigma.Buffer; gpu.For(0, temporarySigma.Length, n => { int c = (int)(n / (tsw * tsh)); int l = n - c * (tsw * tsh); int y = (int)(l / tsw); int x = l - y * tsw; tsbuf[c][x, y] = sbuf[c][x, y]; }); }
private static void RunAddVector(Gpu aleaGpu, CudaAccelerator ilGpu) { const int m = 2 * 24 * 12; const int n = 2 * 25600 - 1; var matrixM = new Real[m * n]; var matrixC = new Real[m * n]; var vector = new Real[n]; Benchmark.Run(Loops, () => AddVector.Initialise(matrixM, vector, m, n), () => AddVector.Initialise(matrixC, vector, m, n), () => AssertAreEqual(matrixM, matrixC, m, n), () => AddVector.Managed(matrixM, vector, m, n), #if USE_ALEA () => AddVector.Alea(aleaGpu, matrixC, vector, m, n), #endif () => AddVector.IlGpu(ilGpu, matrixC, vector, m, n)); }
public System(IntPtr renderer, Cpu cpu, Gpu gpu, Ram ram, Keyboard keyboard) { IsRunning = true; _cpu = cpu; _gpu = gpu; _ram = ram; _keyboard = keyboard; _renderer = renderer; _timestep = 1.0 / 60.0; _previouslyRecordedTime = Sdl.GetTicks() / 1000.0; _accumulator = 0.0; _frameTime = 0.0; }
public void TestVanTrunkReturnsCorrectCollection() { Vehicle van = new Van(); Product hardDrive = new HardDrive(120); Product gpu = new Gpu(100); Product ram = new Ram(40); List <Product> products = new List <Product>() { hardDrive, gpu, ram, }; van.LoadProduct(hardDrive); van.LoadProduct(gpu); van.LoadProduct(ram); CollectionAssert.AreEqual(van.Trunk, products, "Added items should be the same."); }
private float[,] GetInputSamplesCpu <T>(IntPtr samples, int channels, int length) where T : struct { var result = new float[channels, length / channels]; try { var devSamples = GetDevInputSamples <T>(length); var devOutput = GetDevNormSamples(channels, length / channels); Gpu.CopyToDevice(samples, 0, devSamples, 0, length); Gpu.Launch(AudioProc.THREAD_COUNT, 1, string.Format("GetSamples{0}", typeof(T).Name), devSamples, devOutput); Gpu.CopyFromDevice(devOutput, result); } catch (Exception ex) { Trace.WriteLine(ex.Message); return(null); } return(result); }
public static Computer GenerateEmptyComponentsComputer() { var memory = new Memory(); var disk = new Disk(); var processor = new Processor(); var motherBoard = new MotherBoard(); var gpu = new Gpu(); var computer = new Computer { Memories = new[] { memory }, Disks = new[] { disk }, Processor = processor, MotherBoard = motherBoard, Gpus = new[] { gpu } }; return(computer); }
public void RunShaderOnAllDevices() { foreach (GraphicsDevice gpu in Gpu.EnumerateDevices()) { using (ReadWriteBuffer <float> buffer = gpu.AllocateReadWriteBuffer <float>(100)) { Action <ThreadIds> action = id => buffer[id.X] = id.X; gpu.For(100, action); float[] array = buffer.GetData(); float[] expected = Enumerable.Range(0, 100).Select(i => (float)i).ToArray(); Assert.IsTrue(array.AsSpan().ContentEquals(expected)); } gpu.Dispose(); } }
public void Run(string[] args) { if (args.Length >= 1) { int.TryParse(args[0], out items); } if (args.Length >= 2 && int.TryParse(args[1], out int loopDuationInSeconds)) { loopDuration = TimeSpan.FromSeconds(loopDuationInSeconds); } if (args.Length >= 3) { bool.TryParse(args[2], out copyBack); } try { Console.WriteLine($"Test with {items} items, duration ={loopDuration},copy back ={copyBack}"); Console.Write("Testing with CPU "); Console.WriteLine($"{runCpuTest(items, loopDuration)}"); foreach (var item in Gpu.EnumerateDevices()) { Console.Write($"Testing with ComputeSharp [{item.Name}] "); Console.WriteLine($"{runComputeSharpTest(items, loopDuration, item, copyBack)}"); } using (Context c = new Context()) { c.EnableAlgorithms(); foreach (var item in Accelerator.Accelerators) { using (var acc = Accelerator.Create(c, item)) { Console.Write($"Testing with ILGPU [{acc.Name}-{item.AcceleratorType}] "); Console.WriteLine($"{runILGPUTest(items, loopDuration, acc, copyBack)}"); } } } } catch (Exception ex) { Console.WriteLine(ex); } }
public void AllocateDeviceRows() { float[,] source = { { 0, 0, 0, 0, 0, 1, 2, 3, 0, 0 }, { 0, 0, 0, 0, 0, 4, 5, 6, 0, 0 }, { 0, 0, 0, 0, 0, 7, 8, 9, 0, 0 } }; Tensor.From(source, out Tensor tensor); Gpu gpu = Gpu.Default; using (DeviceMemory <float> m_gpu = gpu.AllocateDevice(tensor, 5, 3)) { float[] copy = Gpu.CopyToHost(m_gpu), expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Assert.IsTrue(copy.ContentEquals(expected)); } }
public void Process(Gpu gpu, Property.PoolingProperty.PoolType type, BufferField sigma, BufferField map, int reduction, int expansion, ref BufferField propagater) { switch (type) { case Property.PoolingProperty.PoolType.Max: Max(gpu, sigma, map, reduction, expansion, ref propagater); break; case Property.PoolingProperty.PoolType.Min: Min(gpu, sigma, map, reduction, expansion, ref propagater); break; case Property.PoolingProperty.PoolType.Average: Average(gpu, sigma, map, reduction, expansion, ref propagater); break; default: break; } }
public ICollection <Gpu> getGpusFromExcel(XLWorkbook workBook) { ICollection <Gpu> result = new List <Gpu>(); var worksheet = workBook.Worksheet("Відеокарти"); foreach (IXLRow row in worksheet.RowsUsed().Skip(1)) { var item = new Gpu(); //item.Id = int.Parse(row.Cell(1).Value.ToString()); item.Name = row.Cell(2).Value.ToString(); item.CoreNumber = int.Parse(row.Cell(3).Value.ToString()); item.Clock = int.Parse(row.Cell(4).Value.ToString()); item.MemorySize = int.Parse(row.Cell(5).Value.ToString()); item.MemorySpeed = int.Parse(row.Cell(6).Value.ToString()); item.Price = int.Parse(row.Cell(7).Value.ToString()); item.InterfaceId = int.Parse(row.Cell(8).Value.ToString()); result.Add(item); } return(result); }
public void ActivationBackward() { Tensor x = CreateRandomTensor(400, 1200), dy = CreateRandomTensor(400, 1200); Tensor.Like(x, out Tensor dx1); CpuDnn.ActivationBackward(x, dy, ActivationFunctions.SigmoidPrime, dx1); Gpu gpu = Gpu.Default; using (DeviceMemory <float> x_gpu = gpu.AllocateDevice(x), dy_gpu = gpu.AllocateDevice(dy)) { Dnn.Get(gpu).ActivationBackward(x.Entities, x.Length, x_gpu.Ptr, dy_gpu.Ptr, ActivationFunctions.SigmoidPrime, dy_gpu.Ptr); dy_gpu.CopyToHost(dy.Entities, dy.Length, out Tensor dx2); Assert.IsTrue(dx1.ContentEquals(dx2)); Tensor.Free(x, dy, dx1, dx2); } }
public void Process(Gpu gpu, Property.PoolingProperty.PoolType type, BufferField input, int reduction, int expansion, ref BufferField map, ref BufferField output) { switch (type) { case Property.PoolingProperty.PoolType.Max: Max(gpu, input, reduction, expansion, ref map, ref output); break; case Property.PoolingProperty.PoolType.Min: Min(gpu, input, reduction, expansion, ref map, ref output); break; case Property.PoolingProperty.PoolType.Average: Average(gpu, input, reduction, expansion, ref map, ref output); break; default: break; } }
public static List <PriceSourceItem> GetPrice(Gpu gpu, PriceSource priceSource) { Guard.AgainstFalse <ArgumentNullException>(!string.IsNullOrWhiteSpace(gpu.Asin)); List <PriceSourceItem> priceSourceItems = new List <PriceSourceItem>(); AmazonEndpoint? amazonEndpoint = null; if (priceSource != null) { WriteLine($"Getting Price From {priceSource?.Name ?? "NULL"} For GPU {gpu.Name}"); amazonEndpoint = PriceSourceTypeHelper.ToAmazonEndpoint(priceSource.PriceSourceType); } List <PriceSourceItem> result = Amazon.AmazonService.SearchItemLookupOperation(gpu.Asin, amazonEndpoint); result.ForEach(p => p.PriceSourceId = priceSource.Id); priceSourceItems.AddRange(result); return(priceSourceItems); }
public void Successful_Implementation_Method_UnloadVehicle() { int slot = 0; var currentVehicle = this.storage.GetVehicle(slot); var expectedUnloadedProductCount = 3; var unloadedProductCount = 0; var product = new Gpu(2); for (int i = 0; i <= 2; i++) { currentVehicle.LoadProduct(product); } this.storage.UnloadVehicle(0); unloadedProductCount = this.storage.Products.Count(); Assert.That(expectedUnloadedProductCount, Is.EqualTo(unloadedProductCount)); }
public static unsafe void gemm_ongpu(int ta, int tb, int m, int n, int k, float alpha, float[] a, int lda, float[] b, int ldb, float beta, float[] c, int ldc) { using (var gpuA = Gpu.Default.AllocateDevice(a.ToArray())) using (var gpuB = Gpu.Default.AllocateDevice(b.ToArray())) using (var gpuC = Gpu.Default.AllocateDevice(c.ToArray())) { var handle = CudaUtils.blas_handle(); CudaUtils.SafeCall(CuBlas.cublasSgemm_v2(handle, (tb != 0 ? cublasOperation_t.CUBLAS_OP_T : cublasOperation_t.CUBLAS_OP_N), (ta != 0 ? cublasOperation_t.CUBLAS_OP_T : cublasOperation_t.CUBLAS_OP_N), n, m, k, &alpha, (float *)gpuB.Handle, ldb, (float *)gpuA.Handle, lda, &beta, (float *)gpuC.Handle, ldc)); a = Gpu.CopyToHost(gpuA); b = Gpu.CopyToHost(gpuB); c = Gpu.CopyToHost(gpuC); } }
// I'm sure memory management is far from optimal! // Helpers private static T ReduceHelper <T>(T[] array, Func <T, T, T> op, Action <deviceptr <T>, int, T[], Func <T, T, T> > kernel, Func <int, LaunchParam> launchParamsFactory) { if (array.Length < CpuThreashold) { return(array.AsParallel().Aggregate(op)); } var gpu = Gpu.Default; var arrayLength = array.Length; var arrayMemory = gpu.ArrayGetMemory(array, true, false); var arrayDevPtr = new deviceptr <T>(arrayMemory.Handle); while (true) { var launchParams = launchParamsFactory(arrayLength); var resultLength = launchParams.GridDim.x; var resultDevice = gpu.Allocate <T>(resultLength); // I'm allowed to use the CPU. if (arrayLength < CpuThreashold) { using (var m = arrayMemory as Memory <T>) { return(Gpu.CopyToHost(m).AsParallel().Aggregate(op)); } } // ReSharper disable once AccessToModifiedClosure // ReSharper disable once AccessToModifiedClosure gpu.Launch(() => kernel(arrayDevPtr, arrayLength, resultDevice, op), launchParams); // I should be able to dispose at this point! // This is a symptom I did something stupid! //arrayMemory.Dispose(); arrayLength = resultLength; arrayMemory = gpu.ArrayGetMemory(resultDevice, true, false); arrayDevPtr = new deviceptr <T>(arrayMemory.Handle); } }
// Fixed Block Size! internal static Image Render3(int width, int height) { var resultLength = ColorComponents * width * height; var resultMemory = Gpu.Default.AllocateDevice <byte>(resultLength); var resultDevPtr = new deviceptr <byte>(resultMemory.Handle); var lp = new LaunchParam(256, 256); Gpu.Default.Launch(() => { var i = blockDim.x * blockIdx.x + threadIdx.x; while (ColorComponents * i < resultLength) { ComputeRippleAtOffset(resultDevPtr, i, width, height); i += gridDim.x * blockDim.x; } }, lp); return(BitmapUtility.FromByteArray(Gpu.CopyToHost(resultMemory), width, height)); }
public static void RunGpu() { var n = GetData(out var x, out var y); var result = new float[n]; var gpu = Gpu.Default; var xDevice = gpu.Allocate <float>(n); var yDevice = gpu.Allocate <float>(n); var resultDevice = gpu.Allocate <float>(n); Gpu.Copy(x, xDevice); Gpu.Copy(y, yDevice); var lp = new LaunchParam(16, 256); gpu.Launch(Kernel, lp, resultDevice, xDevice, yDevice); Gpu.Copy(resultDevice, result); Gpu.Free(xDevice); Gpu.Free(yDevice); Gpu.Free(resultDevice); }
public IActionResult Edit(int?id, [Bind("GpuId,Model,Manufacturer,Price,Memory")] Gpu gpu) { if (id != gpu.GpuId) { return(NotFound()); } if (ModelState.IsValid) { var image = Request.Form.Files.GetFile("image"); if (image != null) { _driveService.DeleteFile(Request.Form["ImgUrl"]); gpu.ImgUrl = _driveService.UploadFile(image); } _service.Update(gpu); return(RedirectToAction(nameof(Index))); } return(View(gpu)); }
public void GeListSync(Gpu.GpuProcessor.SyncTypeEnum SyncType, Action NotifyOnceCallback) { //Console.WriteLine("GeListSync"); if (SyncType != Gpu.GpuProcessor.SyncTypeEnum.ListDone) throw new NotImplementedException(); lock (this) { Status2.CallbackOnStateOnce(Status2Enum.Free, () => { NotifyOnceCallback(); }); } //Status.CallbackOnStateOnce(StatusEnum.Done, NotifyOnceCallback); /* CallbackOnStateOnce Console.WriteLine("Waiting for DONE"); Status.WaitForState(StatusEnum.Done); Console.WriteLine("Ended Waiting for DONE"); */ }