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.

computing.cpp 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "hcc_detail/hcc_defs_prologue.h"
  2. #include "megcore.h"
  3. #include "megcore_rocm.h"
  4. #include "./fixture.h"
  5. #include "hip_header.h"
  6. #include "test/common/utils.h"
  7. #include "test/rocm/utils.h"
  8. TEST_F(MegcoreROCM, COMPUTING) {
  9. for (int id = -1; id < std::min(nr_devices(), 2); ++id) {
  10. megcoreDeviceHandle_t devHandle;
  11. megcoreCreateDeviceHandle(&devHandle, megcorePlatformROCM, id, 0);
  12. megcoreActivate(devHandle);
  13. megcoreComputingHandle_t compHandle;
  14. megcoreCreateComputingHandle(&compHandle, devHandle, 0);
  15. megcoreDeviceHandle_t devHandle2;
  16. megcoreGetDeviceHandle(compHandle, &devHandle2);
  17. ASSERT_EQ(devHandle, devHandle2);
  18. unsigned int flags;
  19. megcoreGetComputingFlags(compHandle, &flags);
  20. ASSERT_EQ(0u, flags);
  21. unsigned char *src, *dst;
  22. static const size_t N = 5;
  23. unsigned char src_host[N], dst_host[N];
  24. megcoreMalloc(devHandle, (void**)&src, N);
  25. megcoreMalloc(devHandle, (void**)&dst, N);
  26. megcoreMemset(compHandle, src, 0x0F, N);
  27. megcoreMemset(compHandle, dst, 0xF0, N);
  28. megcoreMemcpy(compHandle, src_host, src, N, megcoreMemcpyDeviceToHost);
  29. megcoreMemcpy(compHandle, dst_host, dst, N, megcoreMemcpyDeviceToHost);
  30. megcoreSynchronize(compHandle);
  31. for (size_t i = 0; i < N; ++i) {
  32. ASSERT_EQ(0x0F, src_host[i]);
  33. ASSERT_EQ(0xF0, dst_host[i]);
  34. }
  35. megcoreMemcpy(compHandle, dst, src, N, megcoreMemcpyDeviceToDevice);
  36. megcoreMemcpy(compHandle, src_host, src, N, megcoreMemcpyDeviceToHost);
  37. megcoreMemcpy(compHandle, dst_host, dst, N, megcoreMemcpyDeviceToHost);
  38. megcoreSynchronize(compHandle);
  39. for (size_t i = 0; i < N; ++i) {
  40. ASSERT_EQ(dst_host[i], src_host[i]);
  41. }
  42. megcoreFree(devHandle, src);
  43. megcoreFree(devHandle, dst);
  44. megcoreDestroyComputingHandle(compHandle);
  45. megcoreDestroyDeviceHandle(devHandle);
  46. }
  47. }
  48. TEST_F(MegcoreROCM, STREAM) {
  49. megcoreDeviceHandle_t devHandle;
  50. megcoreCreateDeviceHandle(&devHandle, megcorePlatformROCM, 0, 0);
  51. megcoreActivate(devHandle);
  52. hipStream_t stream;
  53. hip_check(hipStreamCreateWithFlags(&stream, hipStreamNonBlocking));
  54. megcoreComputingHandle_t compHandle;
  55. megcoreCreateComputingHandleWithROCMStream(&compHandle, devHandle, 0, stream);
  56. {
  57. hipStream_t stream2;
  58. megcoreGetROCMStream(compHandle, &stream2);
  59. ASSERT_EQ(stream, stream2);
  60. }
  61. megcoreDeviceHandle_t devHandle2;
  62. megcoreGetDeviceHandle(compHandle, &devHandle2);
  63. ASSERT_EQ(devHandle, devHandle2);
  64. unsigned int flags;
  65. megcoreGetComputingFlags(compHandle, &flags);
  66. ASSERT_EQ(0u, flags);
  67. unsigned char *src, *dst;
  68. static const size_t N = 5;
  69. unsigned char src_host[N], dst_host[N];
  70. megcoreMalloc(devHandle, (void**)&src, N);
  71. megcoreMalloc(devHandle, (void**)&dst, N);
  72. megcoreMemset(compHandle, src, 0x0F, N);
  73. megcoreMemset(compHandle, dst, 0xF0, N);
  74. megcoreMemcpy(compHandle, src_host, src, N, megcoreMemcpyDeviceToHost);
  75. megcoreMemcpy(compHandle, dst_host, dst, N, megcoreMemcpyDeviceToHost);
  76. megcoreSynchronize(compHandle);
  77. for (size_t i = 0; i < N; ++i) {
  78. ASSERT_EQ(0x0F, src_host[i]);
  79. ASSERT_EQ(0xF0, dst_host[i]);
  80. }
  81. megcoreMemcpy(compHandle, dst, src, N, megcoreMemcpyDeviceToDevice);
  82. megcoreMemcpy(compHandle, src_host, src, N, megcoreMemcpyDeviceToHost);
  83. megcoreMemcpy(compHandle, dst_host, dst, N, megcoreMemcpyDeviceToHost);
  84. megcoreSynchronize(compHandle);
  85. for (size_t i = 0; i < N; ++i) {
  86. ASSERT_EQ(dst_host[i], src_host[i]);
  87. }
  88. megcoreFree(devHandle, src);
  89. megcoreFree(devHandle, dst);
  90. megcoreDestroyComputingHandle(compHandle);
  91. megcoreDestroyDeviceHandle(devHandle);
  92. hip_check(hipStreamDestroy(stream));
  93. }
  94. // vim: syntax=cpp.doxygen