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.

CApi.Eager.Context.cs 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Tensorflow;
  4. using Tensorflow.Eager;
  5. namespace TensorFlowNET.UnitTest.NativeAPI
  6. {
  7. public partial class CApiEagerTest
  8. {
  9. /// <summary>
  10. /// TEST(CAPI, Context)
  11. /// </summary>
  12. [TestMethod]
  13. public void Context()
  14. {
  15. using var status = c_api.TF_NewStatus();
  16. static SafeContextHandle NewContext(SafeStatusHandle status)
  17. {
  18. using var opts = c_api.TFE_NewContextOptions();
  19. return c_api.TFE_NewContext(opts, status);
  20. }
  21. IntPtr devices;
  22. using (var ctx = NewContext(status))
  23. {
  24. devices = c_api.TFE_ContextListDevices(ctx, status);
  25. EXPECT_EQ(TF_OK, TF_GetCode(status), TF_Message(status));
  26. }
  27. EXPECT_EQ(TF_OK, TF_GetCode(status), TF_Message(status));
  28. int num_devices = c_api.TF_DeviceListCount(devices);
  29. EXPECT_GE(num_devices, 1, TF_Message(status));
  30. for (int i = 0; i < num_devices; ++i)
  31. {
  32. EXPECT_NE("", c_api.TF_DeviceListName(devices, i, status), TF_Message(status));
  33. EXPECT_EQ(TF_OK, TF_GetCode(status), TF_Message(status));
  34. }
  35. c_api.TF_DeleteDeviceList(devices);
  36. }
  37. }
  38. }