Skip to content

Commit 7330f98

Browse files
Refactor bindAvailable
Related-To: NEO-5316 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent e448527 commit 7330f98

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ class DrmMockCustom : public Drm {
337337
ioctl_expected.contextCreate = static_cast<int>(NEO::HwHelper::get(NEO::defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*NEO::defaultHwInfo).size());
338338
ioctl_expected.contextDestroy = ioctl_expected.contextCreate.load();
339339
createVirtualMemoryAddressSpace(NEO::HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
340+
isVmBindAvailable();
341+
reset();
340342
}
341343
int getErrno() override {
342344
return errnoValue;

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,8 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountZer
17381738
auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize);
17391739

17401740
auto retVal = CL_SUCCESS;
1741+
this->mock->createParamsHandle = 0;
1742+
this->mock->createParamsSize = 0;
17411743

17421744
cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR;
17431745
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
@@ -1784,6 +1786,9 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountNon
17841786

17851787
auto retVal = CL_SUCCESS;
17861788

1789+
this->mock->createParamsHandle = 0;
1790+
this->mock->createParamsSize = 0;
1791+
17871792
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
17881793
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
17891794
std::unique_ptr<Image> dstImage(Image::create(
@@ -1828,6 +1833,8 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhen1DarrayImageIsBeingCreated
18281833
auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize);
18291834

18301835
auto retVal = CL_SUCCESS;
1836+
this->mock->createParamsHandle = 0;
1837+
this->mock->createParamsSize = 0;
18311838

18321839
cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR;
18331840
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);

opencl/test/unit_test/os_interface/linux/drm_mock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ using namespace NEO;
2929
// Mock DRM class that responds to DRM_IOCTL_I915_GETPARAMs
3030
class DrmMock : public Drm {
3131
public:
32+
using Drm::bindAvailable;
3233
using Drm::checkQueueSliceSupport;
3334
using Drm::classHandles;
3435
using Drm::engineInfo;
@@ -86,6 +87,9 @@ class DrmMock : public Drm {
8687

8788
void setDeviceID(int deviceId) { this->deviceId = deviceId; }
8889
void setDeviceRevID(int revisionId) { this->revisionId = revisionId; }
90+
void setBindAvailable() {
91+
this->bindAvailable = true;
92+
}
8993

9094
static const int mockFd = 33;
9195

shared/source/os_interface/linux/drm_buffer_object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int bindBOsWithinContext(BufferObject *const boToPin[], size_t numberOfBos, OsCo
225225
int BufferObject::pin(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) {
226226
auto retVal = 0;
227227

228-
if (this->drm->isBindAvailable()) {
228+
if (this->drm->isVmBindAvailable()) {
229229
retVal = bindBOsWithinContext(boToPin, numberOfBos, osContext, vmHandleId);
230230
} else {
231231
StackVec<drm_i915_gem_exec_object2, maxFragmentsCount + 1> execObject(numberOfBos + 1);

shared/source/os_interface/linux/drm_neo.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <cerrno>
2222
#include <fcntl.h>
2323
#include <memory>
24+
#include <mutex>
2425
#include <string>
2526
#include <sys/ioctl.h>
2627
#include <unistd.h>
@@ -111,6 +112,7 @@ class Drm {
111112
return requirePerContextVM;
112113
}
113114

115+
bool isVmBindAvailable();
114116
MOCKABLE_VIRTUAL bool registerResourceClasses();
115117

116118
MOCKABLE_VIRTUAL uint32_t registerResource(ResourceClass classType, void *data, size_t size);
@@ -143,13 +145,6 @@ class Drm {
143145
static Drm *create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
144146
static void overrideBindSupport(bool &useVmBind);
145147

146-
bool isBindAvailable() {
147-
return this->bindAvailable;
148-
}
149-
void setBindAvailable() {
150-
this->bindAvailable = true;
151-
}
152-
153148
protected:
154149
int getQueueSliceCount(drm_i915_gem_context_param_sseu *sseu);
155150
std::string generateUUID();
@@ -159,6 +154,7 @@ class Drm {
159154
bool nonPersistentContextsSupported = false;
160155
bool requirePerContextVM = false;
161156
bool bindAvailable = false;
157+
std::once_flag checkBindOnce;
162158
std::unique_ptr<HwDeviceId> hwDeviceId;
163159
int deviceId = 0;
164160
int revisionId = 0;

shared/source/os_interface/linux/drm_query.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ int Drm::unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObj
5858
return 0;
5959
}
6060

61+
bool Drm::isVmBindAvailable() {
62+
return this->bindAvailable;
63+
}
64+
6165
} // namespace NEO

shared/source/os_interface/linux/drm_query_dg1.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ int Drm::unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObj
6767
return 0;
6868
}
6969

70+
bool Drm::isVmBindAvailable() {
71+
return this->bindAvailable;
72+
}
73+
7074
} // namespace NEO

0 commit comments

Comments
 (0)