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.

Eager.Context.cs 1.5 kB

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