示例#1
0
        public void Should_ListDeviceReturnDevices()
        {
            using (var graph = new TFGraph())
                using (var session = new TFSession(graph)) {
                    var devices = session.ListDevices();

                    Assert.True(devices.Any());
                }
        }
        public TensorProcessor(byte[] model, string device = "/CPU:0")
        {
            _graph = new TFGraph();
            var options = new TFImportGraphDefOptionsExt();

            //options.SetDefaultDevice(device);
            _graph.Import(model, options);

            TFSessionOptions TFOptions = new TFSessionOptions();

            unsafe
            {
                byte[] GPUConfig = { 0x38, 0x1 };

                fixed(void *ptr = &GPUConfig[0])
                {
                    TFOptions.SetConfig(new IntPtr(ptr), GPUConfig.Length);
                }
            }
            _session = new TFSession(_graph, TFOptions);

            Console.WriteLine($"=> Session for {device} created with: {String.Join(',', _session.ListDevices().Select(x => x.Name).ToList())}");
        }