You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SessionOptions.cs 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*****************************************************************************
  2. Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. using Google.Protobuf;
  14. using System;
  15. namespace Tensorflow
  16. {
  17. internal sealed class SessionOptions
  18. {
  19. SafeSessionOptionsHandle _handle { get; }
  20. public SessionOptions(string target = "", ConfigProto config = null)
  21. {
  22. _handle = c_api.TF_NewSessionOptions();
  23. c_api.TF_SetTarget(_handle, target);
  24. if (config != null)
  25. SetConfig(config);
  26. }
  27. private unsafe void SetConfig(ConfigProto config)
  28. {
  29. var bytes = config.ToByteArray();
  30. fixed (byte* proto2 = bytes)
  31. {
  32. var status = new Status();
  33. c_api.TF_SetConfig(_handle, (IntPtr)proto2, (ulong)bytes.Length, status);
  34. status.Check(false);
  35. }
  36. }
  37. public static implicit operator SafeSessionOptionsHandle(SessionOptions opt)
  38. {
  39. return opt._handle;
  40. }
  41. }
  42. }