示例#1
0
        public async stt::Task GetRequestObjectAsync()
        {
            moq::Mock <AcceleratorTypes.AcceleratorTypesClient> mockGrpcClient = new moq::Mock <AcceleratorTypes.AcceleratorTypesClient>(moq::MockBehavior.Strict);
            GetAcceleratorTypeRequest request = new GetAcceleratorTypeRequest
            {
                Zone            = "zone255f4ea8",
                AcceleratorType = "accelerator_type68a25f42",
                Project         = "projectaa6ff846",
            };
            AcceleratorType expectedResponse = new AcceleratorType
            {
                Id   = "id74b70bb8",
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                Zone = "zone255f4ea8",
                CreationTimestamp       = "creation_timestamp235e59a1",
                Description             = "description2cf9da67",
                SelfLink                = "self_link7e87f12d",
                Deprecated              = new DeprecationStatus(),
                MaximumCardsPerInstance = 739769688,
            };

            mockGrpcClient.Setup(x => x.GetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AcceleratorType>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AcceleratorTypesClient client = new AcceleratorTypesClientImpl(mockGrpcClient.Object, null);
            AcceleratorType        responseCallSettings = await client.GetAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            AcceleratorType responseCancellationToken = await client.GetAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public async stt::Task GetAcceleratorTypeResourceNamesAsync()
        {
            moq::Mock <Tpu.TpuClient> mockGrpcClient = new moq::Mock <Tpu.TpuClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAcceleratorTypeRequest request = new GetAcceleratorTypeRequest
            {
                AcceleratorTypeName = AcceleratorTypeName.FromProjectLocationAcceleratorType("[PROJECT]", "[LOCATION]", "[ACCELERATOR_TYPE]"),
            };
            AcceleratorType expectedResponse = new AcceleratorType
            {
                AcceleratorTypeName = AcceleratorTypeName.FromProjectLocationAcceleratorType("[PROJECT]", "[LOCATION]", "[ACCELERATOR_TYPE]"),
                Type = "typee2cc9d59",
            };

            mockGrpcClient.Setup(x => x.GetAcceleratorTypeAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AcceleratorType>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            TpuClient       client = new TpuClientImpl(mockGrpcClient.Object, null);
            AcceleratorType responseCallSettings = await client.GetAcceleratorTypeAsync(request.AcceleratorTypeName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            AcceleratorType responseCancellationToken = await client.GetAcceleratorTypeAsync(request.AcceleratorTypeName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
示例#3
0
文件: Device.cs 项目: Nnelg/ILGPU
 /// <summary>
 /// Prints general header information that should appear at the top.
 /// </summary>
 /// <param name="writer">The target text writer to write to.</param>
 protected virtual void PrintHeader(TextWriter writer)
 {
     writer.Write("Device: ");
     writer.WriteLine(Name);
     writer.Write("  Accelerator Type:                        ");
     writer.WriteLine(AcceleratorType.ToString());
 }
示例#4
0
 /// <summary>
 /// Constructs a new accelerator.
 /// </summary>
 /// <param name="context">The target context.</param>
 /// <param name="type">The target accelerator type.</param>
 internal Accelerator(Context context, AcceleratorType type)
 {
     Context         = context ?? throw new ArgumentNullException(nameof(context));
     AcceleratorType = type;
     InitGC();
     memoryCache = new MemoryBufferCache(this);
 }
        /// <summary>
        /// <para>prepares devices and compiles kernels in the kernel string</para>
        /// <para>does optionally pipelined kernel execution load balancing between multiple devices</para>
        /// </summary>
        /// <param name="cpuGpu">AcceleratorType.CPU|AcceleratorType.GPU or similar</param>
        /// <param name="kernelString">something like: @"multi-line C# string that has multiple kernel definitions"</param>
        /// <param name="numberofCPUCoresToUseAsDeviceFission">AcceleratorType.CPU uses number of threads for an N-core CPU(between 1 and N-1)(-1 means N-1)</param>
        /// <param name="numberOfGPUsToUse">AcceleratorType.GPU uses number of GPUs equal to this parameter. Between 1 and N(-1 means N)</param>
        /// <param name="stream">devices that share RAM with CPU will not do extra copies. Devices that don't share RAM will directly access RAM and reduce number of copies</param>
        /// <param name="noPipelining">disables extra command queue allocation, can't enable driver-driven pipelining later. Useful for device to device pipelining with many stages.</param>
        public ClNumberCruncher(AcceleratorType cpuGpu, string kernelString,
                                int numberofCPUCoresToUseAsDeviceFission = -1,
                                int numberOfGPUsToUse = -1, bool stream = true, bool noPipelining = false)
        {
            bool defaultQueue = false;

            if (kernelString.Contains("enqueue_kernel("))
            {
                defaultQueue = true;
            }
            repeatCount            = 1;
            numberOfErrorsHappened = 0;
            StringBuilder cpuGpu_ = new StringBuilder("");

            if (((int)cpuGpu & ((int)AcceleratorType.CPU)) > 0)
            {
                cpuGpu_.Append("cpu ");
            }
            if (((int)cpuGpu & ((int)AcceleratorType.GPU)) > 0)
            {
                cpuGpu_.Append("gpu ");
            }
            if (((int)cpuGpu & ((int)AcceleratorType.ACC)) > 0)
            {
                cpuGpu_.Append("acc ");
            }

            List <string> kernelNames_ = new List <string>();

            // extracting patterns kernel _ _ _ void _ _ name _ _ (
            string          kernelVoidRegex = "(kernel[\\s]+void[\\s]+[a-zA-Z\\d_]+[^\\(])";
            Regex           regex           = new Regex(kernelVoidRegex);
            MatchCollection match           = regex.Matches(kernelString);

            for (int i = 0; i < match.Count; i++)
            {
                // extracting name
                Regex           rgx = new Regex("([\\s]+[a-zA-Z\\d_]+)");
                MatchCollection mc  = rgx.Matches(match[i].Value.Trim());
                kernelNames_.Add(mc[mc.Count - 1].Value.Trim());
            }
            if (kernelNames_.Count == 0)
            {
                Console.WriteLine("Error: no kernel definitions are found in string. Kernel string: \n" + kernelString);
                errorNotification = 1;
                return;
            }
            numberCruncher = new Cores(cpuGpu_.ToString(), kernelString, kernelNames_.ToArray(), defaultQueue, 256,
                                       numberOfGPUsToUse, stream, numberofCPUCoresToUseAsDeviceFission, noPipelining);
            if (numberCruncher.errorCode() != 0)
            {
                errorMessage_ = numberCruncher.errorMessage();
                Console.WriteLine(numberCruncher.errorMessage());
                errorNotification = numberCruncher.errorCode();
                numberCruncher.dispose();
                numberOfErrorsHappened++;
                return;
            }
        }
 bool GetAccelerator(AcceleratorType t, out AcceleratorId aid)
 {
     aid = Accelerator.Accelerators.Where(id => id.AcceleratorType == t).FirstOrDefault();
     if (aid.AcceleratorType != t)
     {
         Console.WriteLine(@"There is accelerator present of the desired type.  Doing nothing.");
     }
     return(aid.AcceleratorType == t);
 }
示例#7
0
 /// <summary>
 /// Constructs a new device specializer.
 /// </summary>
 /// <param name="acceleratorType">The accelerator type.</param>
 /// <param name="warpSize">The warp size (if any).</param>
 /// <param name="intPointerType">The native integer pointer type.</param>
 public AcceleratorSpecializer(
     AcceleratorType acceleratorType,
     int?warpSize,
     PrimitiveType intPointerType)
 {
     AcceleratorType = acceleratorType;
     WarpSize        = warpSize;
     IntPointerType  = intPointerType;
 }
示例#8
0
 /// <summary>
 /// Constructs a new accelerator id.
 /// </summary>
 /// <param name="type">The accelerator type.</param>
 /// <param name="deviceId">The referenced device id.</param>
 public AcceleratorId(AcceleratorType type, int deviceId)
 {
     if (deviceId < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(deviceId));
     }
     AcceleratorType = type;
     DeviceId        = deviceId;
 }
示例#9
0
 /// <summary>
 /// Constructs a new device specializer.
 /// </summary>
 /// <param name="acceleratorType">The accelerator type.</param>
 /// <param name="warpSize">The warp size (if any).</param>
 /// <param name="intPointerType">The native integer pointer type.</param>
 /// <param name="enableAssertions">True, if the assertions are enabled.</param>
 public AcceleratorSpecializer(
     AcceleratorType acceleratorType,
     int?warpSize,
     PrimitiveType intPointerType,
     bool enableAssertions)
 {
     AcceleratorType  = acceleratorType;
     WarpSize         = warpSize;
     IntPointerType   = intPointerType;
     EnableAssertions = enableAssertions;
 }
示例#10
0
 public FileRunner(CodeFile code, OutputTabs output, AcceleratorType type, int OptimizationLevel, Action onRunStop, Action framebufferSwap, Action <TimeSpan, double> onTimersUpdate)
 {
     this.code              = code;
     this.output            = output;
     this.type              = type;
     this.OptimizationLevel = OptimizationLevel;
     this.onRunStop         = onRunStop;
     this.framebufferSwap   = framebufferSwap;
     this.onTimersUpdate    = onTimersUpdate;
     timer = new FrameTimer();
 }
 /// <summary>
 /// Returns a user-friendly name for an accelerator type.
 /// </summary>
 /// <param name="acceleratorType">The accelerator to return a name for.</param>
 /// <returns>A user friendly name.</returns>
 /// <remarks>
 /// Adapted from https://codereview.stackexchange.com/questions/157871/method-that-returns-description-attribute-of-enum-value.</remarks>
 public static string ToFriendlyName(this AcceleratorType acceleratorType)
 {
     return
         (acceleratorType
          .GetType()
          .GetMember(acceleratorType.ToString())
          .FirstOrDefault()
          ?.GetCustomAttribute <DescriptionAttribute>()
          ?.Description
          ?? acceleratorType.ToString());
 }
示例#12
0
 /// <summary>Snippet for Get</summary>
 public void Get()
 {
     // Snippet: Get(string, string, string, CallSettings)
     // Create client
     AcceleratorTypesClient acceleratorTypesClient = AcceleratorTypesClient.Create();
     // Initialize request argument(s)
     string project         = "";
     string zone            = "";
     string acceleratorType = "";
     // Make the request
     AcceleratorType response = acceleratorTypesClient.Get(project, zone, acceleratorType);
     // End snippet
 }
示例#13
0
        /// <summary>
        /// Constructs a new accelerator.
        /// </summary>
        /// <param name="context">The target context.</param>
        /// <param name="type">The target accelerator type.</param>
        internal Accelerator(Context context, AcceleratorType type)
        {
            Context         = context ?? throw new ArgumentNullException(nameof(context));
            AcceleratorType = type;

            AutomaticBufferDisposalEnabled = !context.HasFlags(
                ContextFlags.DisableAutomaticBufferDisposal);
            AutomaticKernelDisposalEnabled = !context.HasFlags(
                ContextFlags.DisableAutomaticKernelDisposal);
            InitKernelCache();
            InitGC();

            memoryCache = new MemoryBufferCache(this);
        }
示例#14
0
        public void Initialize(AcceleratorType acceleratorType, double[,] independents, double[] dependants)
        {
            Context = new Context();
            List <AcceleratorId> acceleratorIds    = Accelerator.Accelerators.Where(x => x.AcceleratorType == acceleratorType).ToList();
            List <double[, ]>    splitIndependents = SplitArray(independents, acceleratorIds.Count);
            List <double[]>      splitDependants   = SplitArray(dependants, acceleratorIds.Count);

            for (int gpuIndex = 0; gpuIndex < acceleratorIds.Count; gpuIndex++)
            {
                GPUManager gpuManager = new GPUManager();
                gpuManager.Initialize(Context, acceleratorIds[gpuIndex], splitIndependents[gpuIndex], splitDependants[gpuIndex]);
                GPUManagers.Add(gpuManager);
            }
            TotalIndependentsRows = splitDependants.Select(x => x.Length).Sum();
        }
示例#15
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetAsync()
        {
            // Snippet: GetAsync(string, string, string, CallSettings)
            // Additional: GetAsync(string, string, string, CancellationToken)
            // Create client
            AcceleratorTypesClient acceleratorTypesClient = await AcceleratorTypesClient.CreateAsync();

            // Initialize request argument(s)
            string project         = "";
            string zone            = "";
            string acceleratorType = "";
            // Make the request
            AcceleratorType response = await acceleratorTypesClient.GetAsync(project, zone, acceleratorType);

            // End snippet
        }
示例#16
0
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetAcceleratorTypeRequest, CallSettings)
     // Create client
     AcceleratorTypesClient acceleratorTypesClient = AcceleratorTypesClient.Create();
     // Initialize request argument(s)
     GetAcceleratorTypeRequest request = new GetAcceleratorTypeRequest
     {
         Zone            = "",
         AcceleratorType = "",
         Project         = "",
     };
     // Make the request
     AcceleratorType response = acceleratorTypesClient.Get(request);
     // End snippet
 }
示例#17
0
        public static string getDesc(AcceleratorType type)
        {
            switch (type)
            {
            case AcceleratorType.Default:
            case AcceleratorType.CPU:
                return(CPUAccelerator.CPUAccelerators.FirstOrDefault().ToString());

            case AcceleratorType.Cuda:
                return(CudaAccelerator.CudaAccelerators.FirstOrDefault().ToString());

            case AcceleratorType.OpenCL:
                return(CLAccelerator.AllCLAccelerators.FirstOrDefault().ToString());
            }

            return("");
        }
示例#18
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetAcceleratorTypeRequest, CallSettings)
            // Additional: GetAsync(GetAcceleratorTypeRequest, CancellationToken)
            // Create client
            AcceleratorTypesClient acceleratorTypesClient = await AcceleratorTypesClient.CreateAsync();

            // Initialize request argument(s)
            GetAcceleratorTypeRequest request = new GetAcceleratorTypeRequest
            {
                Zone            = "",
                AcceleratorType = "",
                Project         = "",
            };
            // Make the request
            AcceleratorType response = await acceleratorTypesClient.GetAsync(request);

            // End snippet
        }
示例#19
0
        public void GetAcceleratorTypeResourceNames()
        {
            moq::Mock <Tpu.TpuClient> mockGrpcClient = new moq::Mock <Tpu.TpuClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAcceleratorTypeRequest request = new GetAcceleratorTypeRequest
            {
                AcceleratorTypeName = AcceleratorTypeName.FromProjectLocationAcceleratorType("[PROJECT]", "[LOCATION]", "[ACCELERATOR_TYPE]"),
            };
            AcceleratorType expectedResponse = new AcceleratorType
            {
                AcceleratorTypeName = AcceleratorTypeName.FromProjectLocationAcceleratorType("[PROJECT]", "[LOCATION]", "[ACCELERATOR_TYPE]"),
                Type = "typee2cc9d59",
            };

            mockGrpcClient.Setup(x => x.GetAcceleratorType(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            TpuClient       client   = new TpuClientImpl(mockGrpcClient.Object, null);
            AcceleratorType response = client.GetAcceleratorType(request.AcceleratorTypeName);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#20
0
 public void Run(double[,] independents, double[] dependants, int maxNodesPerExpression, AcceleratorType acceleratorType, List <Node> startExpressions, List <Transform> transforms)
 {
     if (IsRunning)
     {
         return;
     }
     IsRunning = true;
     if (UseSymCalculate)
     {
         Independents = ToJagged(independents);
         Dependants   = dependants;
     }
     else
     {
         GPUsManager.Initialize(acceleratorType, independents, dependants);
     }
     MaxNodesPerExpression = maxNodesPerExpression;
     ModelManager.MaxNodesPerExpression = maxNodesPerExpression;
     ModelManager.CorrelationItems      = Correlation.ComputeRankedCorrelationItems(independents, dependants);
     ModelManager.Run(independents.GetUpperBound(1) + 1, startExpressions, transforms);
     IsRunning = false;
 }
示例#21
0
 /// <summary>
 /// Constructs a new device specializer.
 /// </summary>
 /// <param name="acceleratorType">The accelerator type.</param>
 /// <param name="warpSize">The warp size (if any).</param>
 public AcceleratorSpecializer(AcceleratorType acceleratorType, int?warpSize)
 {
     AcceleratorType = acceleratorType;
     WarpSize        = warpSize;
 }
示例#22
0
 /// <summary>
 /// Constructs a new accelerator id.
 /// </summary>
 /// <param name="type">The accelerator type.</param>
 protected AcceleratorId(AcceleratorType type)
 {
     AcceleratorType = type;
 }
示例#23
0
 /// <summary>
 /// Constructs a new kernel accelerator.
 /// </summary>
 /// <param name="context">The target context.</param>
 /// <param name="type">The target accelerator type.</param>
 protected KernelAccelerator(Context context, AcceleratorType type)
     : base(context, type)
 {
 }
示例#24
0
 /// <summary>
 /// Constructs a new device type attribute.
 /// </summary>
 /// <param name="acceleratorType">
 /// The accelerator type of the annotated device.
 /// </param>
 public DeviceTypeAttribute(AcceleratorType acceleratorType)
 {
     AcceleratorType = acceleratorType;
 }