Пример #1
0
        public bool AddDependency(Applier applier)
        {
            ThrowIfNotAllocated();

            if (!applier.IsAllocated)
            {
                throw new ArgumentException("The Applier is not allocated.");
            }

            var r = plaidml.__Internal.PlaidmlAddComposerDependency(this, applier);

            if (r)
            {
                Dependencies.Add(applier);
            }
            else
            {
                ReportApiCallError("plaidml_add_composer_dependency");
            }

            return(r);
        }
Пример #2
0
        public Invoker(Context ctx, Function f, DeviceTensor[] input, DeviceTensor[] output) : base(ctx)
        {
            _ptr = plaidml.__Internal.PlaidmlAllocInvoker(_context, f);
            if (_ptr.IsZero())
            {
                ReportApiCallError("plaidml_alloc_invoker");
                return;
            }

            IsAllocated = true;

            var r = false;

            for (int i = 0; i < input.Length; i++)
            {
                r = plaidml.__Internal.PlaidmlSetInvokerInput(this, input[i].Name, input[i]);
                if (!r)
                {
                    ReportApiCallError("plaidml_set_invoker_input");
                    break;
                }
            }

            if (r)
            {
                InputTensorsSet = true;
                InputTensors    = input;
            }
            else
            {
                InputTensorsSet = false;
                return;
            }

            for (int i = 0; i < output.Length; i++)
            {
                r = plaidml.__Internal.PlaidmlSetInvokerOutput(this, output[i].Name, output[i]);
                if (!r)
                {
                    ReportApiCallError("plaidml_set_invoker_output");
                    break;
                }
            }

            if (r)
            {
                OutputTensorsSet = true;
                OutputTensor     = output[0];
            }
            else
            {
                OutputTensorsSet = false;
                return;
            }

            Applier = new Applier(_context, f);
            foreach (DeviceTensor t in InputTensors)
            {
                Applier.AddInputValue(t);
            }

            OutputValue = Applier.AddOutputValue(OutputTensor.Name);
        }