File: testInitOpenCL.cpp

package info (click to toggle)
bullet 3.24%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 15,164 kB
  • sloc: cpp: 246,331; lisp: 12,017; ansic: 11,175; python: 630; makefile: 136; sh: 75
file content (111 lines) | stat: -rw-r--r-- 3,739 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"

#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
TEST(b3OpenCLUtils, getNumPlatforms)
{
	int numPlatforms = b3OpenCLUtils::getNumPlatforms();
	ASSERT_GT(numPlatforms, 0);
}

TEST(b3OpenCLUtils, getSdkVendorName)
{
	const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
	b3Printf("getSdkVendorName=%s\n", vendorSDK);
	ASSERT_FALSE(vendorSDK == NULL);
}

TEST(b3OpenCLUtils, getPlatformInfo)
{
	int numPlatforms = b3OpenCLUtils::getNumPlatforms();
	ASSERT_GT(numPlatforms, 0);

	b3Printf("Num Platforms = %d\n", numPlatforms);
	for (int i = 0; i < numPlatforms; i++)
	{
		cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
		ASSERT_FALSE(platform == NULL);

		b3OpenCLPlatformInfo platformInfo;
		b3OpenCLUtils::getPlatformInfo(platform, &platformInfo);
		ASSERT_FALSE(platformInfo.m_platformName == NULL);
		ASSERT_FALSE(platformInfo.m_platformVendor == NULL);
		ASSERT_FALSE(platformInfo.m_platformVersion == NULL);
	}
}

TEST(b3OpenCLUtils, createContextFromPlatform)
{
	int numPlatforms = b3OpenCLUtils::getNumPlatforms();
	b3Printf("Num Platforms = %d\n", numPlatforms);

	cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
	int ciErrNum = 0;

	for (int i = 0; i < numPlatforms; i++)
	{
		cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
		b3OpenCLPlatformInfo platformInfo;
		b3OpenCLUtils::getPlatformInfo(platform, &platformInfo);
		b3Printf("--------------------------------\n");
		b3Printf("Platform info for platform nr %d:\n", i);
		b3Printf("  CL_PLATFORM_VENDOR: \t\t\t%s\n", platformInfo.m_platformVendor);
		b3Printf("  CL_PLATFORM_NAME: \t\t\t%s\n", platformInfo.m_platformName);
		b3Printf("  CL_PLATFORM_VERSION: \t\t\t%s\n", platformInfo.m_platformVersion);

		cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform, deviceType, &ciErrNum);
		ASSERT_FALSE(ctx == 0);
		ASSERT_EQ(CL_SUCCESS, ciErrNum);
		clReleaseContext(ctx);
	}
}

TEST(b3OpenCLUtils, getDeviceAndQueue)
{
	int numPlatforms = b3OpenCLUtils::getNumPlatforms();
	b3Printf("Num Platforms = %d\n", numPlatforms);
	cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
	int ciErrNum = 0;
	for (int i = 0; i < numPlatforms; i++)
	{
		cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
		b3OpenCLPlatformInfo platformInfo;
		b3OpenCLUtils::getPlatformInfo(platform, &platformInfo);
		b3Printf("--------------------------------\n");
		b3Printf("Platform info for platform nr %d:\n", i);
		b3Printf("  CL_PLATFORM_VENDOR: \t\t\t%s\n", platformInfo.m_platformVendor);
		b3Printf("  CL_PLATFORM_NAME: \t\t\t%s\n", platformInfo.m_platformName);
		b3Printf("  CL_PLATFORM_VERSION: \t\t\t%s\n", platformInfo.m_platformVersion);
		cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform, deviceType, &ciErrNum);
		ASSERT_FALSE(ctx == 0);
		ASSERT_EQ(CL_SUCCESS, ciErrNum);
		int numDevices = b3OpenCLUtils::getNumDevices(ctx);
		ASSERT_GT(numDevices, 0);

		b3Printf("Num Devices = %d\n", numDevices);
		for (int j = 0; j < numDevices; j++)
		{
			cl_device_id device = b3OpenCLUtils::getDevice(ctx, j);
			b3OpenCLDeviceInfo devInfo;
			b3OpenCLUtils::getDeviceInfo(device, &devInfo);
			ASSERT_GT(devInfo.m_clockFrequency, 0);
			ASSERT_GT(devInfo.m_addressBits, 0);
			ASSERT_GT(devInfo.m_computeUnits, 0);
			ASSERT_GT(devInfo.m_constantBufferSize, 0);
			ASSERT_FALSE(devInfo.m_deviceName == NULL);
			ASSERT_FALSE(devInfo.m_deviceVendor == NULL);
			ASSERT_FALSE(devInfo.m_driverVersion == NULL);
			ASSERT_GT(devInfo.m_globalMemSize, 0);

			b3OpenCLUtils::printDeviceInfo(device);

			cl_command_queue q = clCreateCommandQueue(ctx, device, 0, &ciErrNum);
			ASSERT_FALSE(q == 0);

			clReleaseCommandQueue(q);
			q = 0;
		}
		clReleaseContext(ctx);
	}
}