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.

Context.cs 1.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. namespace Tensorflow.Eager
  3. {
  4. public class Context : DisposableObject
  5. {
  6. public const int GRAPH_MODE = 0;
  7. public const int EAGER_MODE = 1;
  8. public int default_execution_mode;
  9. public string device_name = "";
  10. bool _initialized = false;
  11. public Context(ContextOptions opts, Status status)
  12. {
  13. _handle = c_api.TFE_NewContext(opts, status);
  14. status.Check(true);
  15. }
  16. public void ensure_initialized()
  17. {
  18. if (_initialized)
  19. return;
  20. _initialized = true;
  21. }
  22. /// <summary>
  23. /// Dispose any unmanaged resources related to given <paramref name="handle"/>.
  24. /// </summary>
  25. protected sealed override void DisposeUnmanagedResources(IntPtr handle)
  26. => c_api.TFE_DeleteContext(_handle);
  27. public bool executing_eagerly() => true;
  28. public static implicit operator IntPtr(Context ctx)
  29. => ctx._handle;
  30. public static implicit operator TFE_Context(Context ctx)
  31. => new TFE_Context(ctx._handle);
  32. }
  33. }