testInitOpenCL.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <gtest/gtest.h>
  2. #include "Bullet3Common/b3Logging.h"
  3. #include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
  4. TEST(b3OpenCLUtils, getNumPlatforms)
  5. {
  6. int numPlatforms = b3OpenCLUtils::getNumPlatforms();
  7. ASSERT_GT(numPlatforms,0);
  8. }
  9. TEST(b3OpenCLUtils, getSdkVendorName)
  10. {
  11. const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
  12. b3Printf("getSdkVendorName=%s\n",vendorSDK);
  13. ASSERT_FALSE(vendorSDK==NULL);
  14. }
  15. TEST(b3OpenCLUtils, getPlatformInfo)
  16. {
  17. int numPlatforms = b3OpenCLUtils::getNumPlatforms();
  18. ASSERT_GT(numPlatforms,0);
  19. b3Printf("Num Platforms = %d\n", numPlatforms);
  20. for (int i=0;i<numPlatforms;i++)
  21. {
  22. cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
  23. ASSERT_FALSE(platform==NULL);
  24. b3OpenCLPlatformInfo platformInfo;
  25. b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
  26. ASSERT_FALSE(platformInfo.m_platformName==NULL);
  27. ASSERT_FALSE(platformInfo.m_platformVendor==NULL);
  28. ASSERT_FALSE(platformInfo.m_platformVersion==NULL);
  29. }
  30. }
  31. TEST(b3OpenCLUtils, createContextFromPlatform)
  32. {
  33. int numPlatforms = b3OpenCLUtils::getNumPlatforms();
  34. b3Printf("Num Platforms = %d\n", numPlatforms);
  35. cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
  36. int ciErrNum = 0;
  37. for (int i=0;i<numPlatforms;i++)
  38. {
  39. cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
  40. b3OpenCLPlatformInfo platformInfo;
  41. b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
  42. b3Printf("--------------------------------\n");
  43. b3Printf("Platform info for platform nr %d:\n",i);
  44. b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
  45. b3Printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
  46. b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
  47. cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
  48. ASSERT_FALSE(ctx==0);
  49. ASSERT_EQ(CL_SUCCESS,ciErrNum);
  50. clReleaseContext(ctx);
  51. }
  52. }
  53. TEST(b3OpenCLUtils, getDeviceAndQueue)
  54. {
  55. int numPlatforms = b3OpenCLUtils::getNumPlatforms();
  56. b3Printf("Num Platforms = %d\n", numPlatforms);
  57. cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
  58. int ciErrNum = 0;
  59. for (int i=0;i<numPlatforms;i++)
  60. {
  61. cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
  62. b3OpenCLPlatformInfo platformInfo;
  63. b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
  64. b3Printf("--------------------------------\n");
  65. b3Printf("Platform info for platform nr %d:\n",i);
  66. b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
  67. b3Printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
  68. b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
  69. cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
  70. ASSERT_FALSE(ctx==0);
  71. ASSERT_EQ(CL_SUCCESS,ciErrNum);
  72. int numDevices = b3OpenCLUtils::getNumDevices(ctx);
  73. ASSERT_GT(numDevices,0);
  74. b3Printf("Num Devices = %d\n", numDevices);
  75. for (int j=0;j<numDevices;j++)
  76. {
  77. cl_device_id device = b3OpenCLUtils::getDevice(ctx,j);
  78. b3OpenCLDeviceInfo devInfo;
  79. b3OpenCLUtils::getDeviceInfo(device,&devInfo);
  80. ASSERT_GT(devInfo.m_clockFrequency,0);
  81. ASSERT_GT(devInfo.m_addressBits,0);
  82. ASSERT_GT(devInfo.m_computeUnits,0);
  83. ASSERT_GT(devInfo.m_constantBufferSize,0);
  84. ASSERT_FALSE(devInfo.m_deviceName==NULL);
  85. ASSERT_FALSE(devInfo.m_deviceVendor==NULL);
  86. ASSERT_FALSE(devInfo.m_driverVersion==NULL);
  87. ASSERT_GT(devInfo.m_globalMemSize,0);
  88. b3OpenCLUtils::printDeviceInfo(device);
  89. cl_command_queue q = clCreateCommandQueue(ctx, device, 0, &ciErrNum);
  90. ASSERT_FALSE(q==0);
  91. clReleaseCommandQueue(q);
  92. q=0;
  93. }
  94. clReleaseContext(ctx);
  95. }
  96. }