Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / RigidBodyGpuPipeline / opencl / primitives / AdlTest / main.cpp
1 /*
2 Copyright (c) 2012 Advanced Micro Devices, Inc.  
3
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose, 
7 including commercial applications, and to alter it and redistribute it freely, 
8 subject to the following restrictions:
9
10 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14 //Originally written by Takahiro Harada
15
16
17 #include <stdio.h>
18
19 #include <Adl/Adl.h>
20 #include <AdlPrimitives/Math/Math.h>
21
22 #include "UnitTests.h"
23 #include "RadixSortBenchmark.h"
24 #include "LaunchOverheadBenchmark.h"
25
26
27 #undef NUM_TESTS
28
29
30 struct ConstBuffer
31 {
32         float4 m_a;
33         float4 m_b;
34         float4 m_c;
35 };
36
37 int main()
38 {
39         if(0)
40         {       //      radix sort test
41                 Device* deviceHost;
42                 Device* deviceGPU;
43                 {
44                         DeviceUtils::Config cfg;
45
46                 // Choose AMD or NVidia
47 #ifdef CL_PLATFORM_AMD
48         cfg.m_vendor = DeviceUtils::Config::VD_AMD;
49 #endif
50
51 #ifdef CL_PLATFORM_INTEL
52         cfg.m_vendor = DeviceUtils::Config::VD_INTEL;
53 #endif
54
55 #ifdef CL_PLATFORM_NVIDIA
56         cfg.m_vendor = adl::DeviceUtils::Config::VD_NV;
57 #endif
58                         deviceGPU = DeviceUtils::allocate( TYPE_DX11, cfg );
59                         deviceHost = DeviceUtils::allocate( TYPE_HOST, cfg );
60                 }
61
62                 {
63                 int maxSize = 512*20;
64                 int size = maxSize;
65
66                 HostBuffer<SortData> buf0( deviceHost, maxSize );
67                 HostBuffer<SortData> buf1( deviceHost, maxSize );
68                 Buffer<SortData> buf2( deviceGPU, maxSize );
69
70                 RadixSort<TYPE_HOST>::Data* dataH = RadixSort<TYPE_HOST>::allocate( deviceHost, maxSize, RadixSortBase::SORT_STANDARD );
71                 RadixSort<TYPE_DX11>::Data* dataC = RadixSort<TYPE_DX11>::allocate( deviceGPU, maxSize, RadixSortBase::SORT_ADVANCED );
72
73                 {
74                         size = NEXTMULTIPLEOF( size, 512 );
75
76                         for(int i=0; i<size; i++) buf0[i] = SortData( getRandom(0,0xfff), i );
77                         buf2.write( buf0.m_ptr, size );
78                         DeviceUtils::waitForCompletion( deviceGPU );
79
80                         RadixSort<TYPE_HOST>::execute( dataH, buf0, size );
81                         RadixSort<TYPE_DX11>::execute( dataC, buf2, size );
82
83                         buf2.read( buf1.m_ptr, size );
84                         DeviceUtils::waitForCompletion( deviceGPU );
85                         for(int i=0; i<size; i++) ADLASSERT( buf0[i].m_value == buf1[i].m_value && buf0[i].m_key == buf1[i].m_key );
86                 }
87
88                 RadixSort<TYPE_HOST>::deallocate( dataH );
89                 RadixSort<TYPE_DX11>::deallocate( dataC );
90                 }
91
92                 DeviceUtils::deallocate( deviceHost );
93                 DeviceUtils::deallocate( deviceGPU );
94         }
95
96         if(0)
97         {
98                 launchOverheadBenchmark();
99         }
100
101         if(0)
102         {
103                 radixSortBenchmark<TYPE_DX11>();
104         }
105
106         if(0)
107         {
108                 radixSortBenchmark<TYPE_CL>();
109         }
110
111         if(1)
112         {
113                 runAllTest();
114         }
115         printf("End, press <enter>\n");
116         getchar();
117 }
118