1 /*
2 * Copyright (c) 2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file cm_group_space.cpp
24 //! \brief Contains Class CmThreadGroupSpace definitions
25 //!
26
27 #include "cm_group_space.h"
28 #include "cm_device_rt.h"
29 #include "cm_kernel.h"
30 #include "cm_mem.h"
31
32 namespace CMRT_UMD
33 {
Create(CmDeviceRT * device,uint32_t index,uint32_t threadSpaceWidth,uint32_t threadSpaceHeight,uint32_t threadSpaceDepth,uint32_t groupSpaceWidth,uint32_t groupSpaceHeight,uint32_t groupSpaceDepth,CmThreadGroupSpace * & threadGroupSpace)34 int32_t CmThreadGroupSpace::Create(CmDeviceRT* device, uint32_t index, uint32_t threadSpaceWidth, uint32_t threadSpaceHeight, uint32_t threadSpaceDepth, uint32_t groupSpaceWidth, uint32_t groupSpaceHeight, uint32_t groupSpaceDepth, CmThreadGroupSpace* & threadGroupSpace)
35 {
36 CM_HAL_MAX_VALUES* halMaxValues = nullptr;
37 CM_HAL_MAX_VALUES_EX* halMaxValuesEx = nullptr;
38 device->GetHalMaxValues(halMaxValues, halMaxValuesEx);
39 if( (threadSpaceWidth == 0) || (threadSpaceHeight == 0) || (threadSpaceDepth == 0) || (groupSpaceWidth == 0)
40 || (groupSpaceHeight == 0) || (groupSpaceDepth==0)
41 || (threadSpaceHeight > MAX_THREAD_SPACE_HEIGHT_PERGROUP)
42 || (threadSpaceWidth > MAX_THREAD_SPACE_WIDTH_PERGROUP)
43 || (threadSpaceDepth > MAX_THREAD_SPACE_DEPTH_PERGROUP)
44 || (threadSpaceHeight * threadSpaceWidth * threadSpaceDepth > halMaxValuesEx->maxUserThreadsPerThreadGroup))
45 {
46 CM_ASSERTMESSAGE("Error: Exceed thread group size limitation.");
47 return CM_INVALID_THREAD_GROUP_SPACE;
48 }
49
50 int32_t result = CM_SUCCESS;
51 threadGroupSpace = new (std::nothrow) CmThreadGroupSpace(device, index, threadSpaceWidth, threadSpaceHeight, threadSpaceDepth, groupSpaceWidth, groupSpaceHeight, groupSpaceDepth);
52 if( threadGroupSpace )
53 {
54 device->m_memObjectCount.threadGroupSpaceCount++;
55
56 result = threadGroupSpace->Initialize( );
57 if( result != CM_SUCCESS )
58 {
59 CmThreadGroupSpace::Destroy( threadGroupSpace);
60 }
61 }
62 else
63 {
64 CM_ASSERTMESSAGE("Error: Failed to create CmThreadGroupSpace due to out of system memory.");
65 result = CM_OUT_OF_HOST_MEMORY;
66 }
67 return result;
68 }
69
Destroy(CmThreadGroupSpace * & threadGroupSpace)70 int32_t CmThreadGroupSpace::Destroy( CmThreadGroupSpace* &threadGroupSpace )
71 {
72 if (threadGroupSpace)
73 {
74 threadGroupSpace->m_device->m_memObjectCount.threadGroupSpaceCount--;
75 }
76 CmSafeDelete( threadGroupSpace );
77 threadGroupSpace = nullptr;
78 return CM_SUCCESS;
79 }
80
GetThreadGroupSpaceSize(uint32_t & threadSpaceWidth,uint32_t & threadSpaceHeight,uint32_t & threadSpaceDepth,uint32_t & groupSpaceWidth,uint32_t & groupSpaceHeight,uint32_t & groupSpaceDepth) const81 int32_t CmThreadGroupSpace::GetThreadGroupSpaceSize(uint32_t & threadSpaceWidth,
82 uint32_t & threadSpaceHeight,
83 uint32_t & threadSpaceDepth,
84 uint32_t & groupSpaceWidth,
85 uint32_t & groupSpaceHeight,
86 uint32_t & groupSpaceDepth) const
87 {
88 threadSpaceWidth = m_threadSpaceWidth;
89 threadSpaceHeight = m_threadSpaceHeight;
90 threadSpaceDepth = m_threadSpaceDepth;
91 groupSpaceWidth = m_groupSpaceWidth;
92 groupSpaceHeight = m_groupSpaceHeight;
93 groupSpaceDepth = m_groupSpaceDepth;
94
95 return CM_SUCCESS;
96 }
97
CmThreadGroupSpace(CmDeviceRT * device,uint32_t index,uint32_t threadSpaceWidth,uint32_t threadSpaceHeight,uint32_t threadSpaceDepth,uint32_t groupSpaceWidth,uint32_t groupSpaceHeight,uint32_t groupSpaceDepth)98 CmThreadGroupSpace::CmThreadGroupSpace( CmDeviceRT* device,
99 uint32_t index,
100 uint32_t threadSpaceWidth,
101 uint32_t threadSpaceHeight,
102 uint32_t threadSpaceDepth,
103 uint32_t groupSpaceWidth,
104 uint32_t groupSpaceHeight,
105 uint32_t groupSpaceDepth) :
106 m_device(device),
107 m_threadSpaceWidth(threadSpaceWidth),
108 m_threadSpaceHeight(threadSpaceHeight),
109 m_threadSpaceDepth(threadSpaceDepth),
110 m_groupSpaceWidth(groupSpaceWidth),
111 m_groupSpaceHeight(groupSpaceHeight),
112 m_groupSpaceDepth(groupSpaceDepth),
113 m_indexInThreadGroupSpaceArray(index)
114 {
115 }
116
CmThreadGroupSpace(CmDeviceRT * device,uint32_t index,uint32_t threadSpaceWidth,uint32_t threadSpaceHeight,uint32_t groupSpaceWidth,uint32_t groupSpaceHeight)117 CmThreadGroupSpace::CmThreadGroupSpace(CmDeviceRT* device,
118 uint32_t index,
119 uint32_t threadSpaceWidth,
120 uint32_t threadSpaceHeight,
121 uint32_t groupSpaceWidth,
122 uint32_t groupSpaceHeight) :
123 m_device(device),
124 m_threadSpaceWidth(threadSpaceWidth),
125 m_threadSpaceHeight(threadSpaceHeight),
126 m_threadSpaceDepth(0),
127 m_groupSpaceWidth(groupSpaceWidth),
128 m_groupSpaceHeight(groupSpaceHeight),
129 m_groupSpaceDepth(0),
130 m_indexInThreadGroupSpaceArray(index)
131 {
132 }
~CmThreadGroupSpace(void)133 CmThreadGroupSpace::~CmThreadGroupSpace( void )
134 {
135 }
136
Initialize(void)137 int32_t CmThreadGroupSpace::Initialize( void )
138 {
139 return CM_SUCCESS;
140 }
141
GetIndexInTGsArray(void)142 uint32_t CmThreadGroupSpace::GetIndexInTGsArray( void )
143 {
144 return m_indexInThreadGroupSpaceArray;
145 }
146
147 #if CM_LOG_ON
Log()148 std::string CmThreadGroupSpace::Log()
149 {
150 std::ostringstream oss;
151
152 oss << "Thread Group Space "
153 << " TsWidth :"<< m_threadSpaceWidth
154 << " TsHeight :" << m_threadSpaceHeight
155 << " TsDepth :" << m_threadSpaceDepth
156 << " GroupSpaceWidth :" <<m_groupSpaceWidth
157 << " GroupSpaceHeight :" <<m_groupSpaceHeight
158 << " GroupSpaceDepth :" << m_groupSpaceDepth
159 << std::endl;
160
161 return oss.str();
162
163 }
164 #endif
165 }
166