Skip to content

Commit c60e4af

Browse files
Revert "Change residency vector to set"
This reverts commit 29c3c71. Change-Id: I68e80e0f23b1f2deda4cc94d3cf17ea215fe1c9e
1 parent 345afd1 commit c60e4af

File tree

6 files changed

+50
-48
lines changed

6 files changed

+50
-48
lines changed

opencl/source/os_interface/linux/drm_command_stream.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "drm/i915_drm.h"
1313

14-
#include <unordered_set>
1514
#include <vector>
1615

1716
namespace NEO {
@@ -56,7 +55,7 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
5655
void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency);
5756
void exec(const BatchBuffer &batchBuffer, uint32_t drmContextId);
5857

59-
std::unordered_set<BufferObject *> residency;
58+
std::vector<BufferObject *> residency;
6059
std::vector<drm_i915_gem_exec_object2> execObjectsStorage;
6160
Drm *drm;
6261
gemCloseWorkerMode gemCloseWorkerOperationMode;

opencl/source/os_interface/linux/drm_command_stream.inl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ void DrmCommandStreamReceiver<GfxFamily>::exec(const BatchBuffer &batchBuffer, u
8080
}
8181

8282
int err = bb->exec(static_cast<uint32_t>(alignUp(batchBuffer.usedSize - batchBuffer.startOffset, 8)),
83-
batchBuffer.startOffset,
84-
engineFlag | I915_EXEC_NO_RELOC,
83+
batchBuffer.startOffset, engineFlag | I915_EXEC_NO_RELOC,
8584
batchBuffer.requiresCoherency,
8685
drmContextId,
87-
this->residency.begin(),
88-
this->residency.size(),
86+
this->residency.data(), this->residency.size(),
8987
this->execObjectsStorage.data());
9088
UNRECOVERABLE_IF(err != 0);
9189

@@ -95,7 +93,15 @@ void DrmCommandStreamReceiver<GfxFamily>::exec(const BatchBuffer &batchBuffer, u
9593
template <typename GfxFamily>
9694
void DrmCommandStreamReceiver<GfxFamily>::makeResident(BufferObject *bo) {
9795
if (bo) {
98-
residency.insert(bo);
96+
if (bo->peekIsReusableAllocation()) {
97+
for (auto bufferObject : this->residency) {
98+
if (bufferObject == bo) {
99+
return;
100+
}
101+
}
102+
}
103+
104+
residency.push_back(bo);
99105
}
100106
}
101107

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ TEST_F(DrmBufferObjectTest, exec) {
6565
mock->ioctl_res = 0;
6666

6767
drm_i915_gem_exec_object2 execObjectsStorage = {};
68-
BufferObject *residencyBo;
69-
auto ret = bo->exec(0, 0, 0, false, 1, &residencyBo, 0u, &execObjectsStorage);
68+
auto ret = bo->exec(0, 0, 0, false, 1, nullptr, 0u, &execObjectsStorage);
7069
EXPECT_EQ(mock->ioctl_res, ret);
7170
EXPECT_EQ(0u, mock->execBuffer.flags);
7271
}
@@ -76,8 +75,7 @@ TEST_F(DrmBufferObjectTest, exec_ioctlFailed) {
7675
mock->ioctl_res = -1;
7776
mock->errnoValue = EFAULT;
7877
drm_i915_gem_exec_object2 execObjectsStorage = {};
79-
BufferObject *residencyBo;
80-
EXPECT_EQ(EFAULT, bo->exec(0, 0, 0, false, 1, &residencyBo, 0u, &execObjectsStorage));
78+
EXPECT_EQ(EFAULT, bo->exec(0, 0, 0, false, 1, nullptr, 0u, &execObjectsStorage));
8179
}
8280

8381
TEST_F(DrmBufferObjectTest, setTiling_success) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test {
133133
}
134134

135135
template <typename GfxFamily>
136-
const std::unordered_set<BufferObject *> &getResidencyVector() const {
136+
const std::vector<BufferObject *> &getResidencyVector() const {
137137
return static_cast<const TestedDrmCommandStreamReceiver<GfxFamily> *>(csr)->residency;
138138
}
139139

shared/source/os_interface/linux/drm_buffer_object.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77

88
#include "shared/source/os_interface/linux/drm_buffer_object.h"
99

10+
#include "shared/source/helpers/aligned_memory.h"
1011
#include "shared/source/helpers/debug_helpers.h"
1112
#include "shared/source/os_interface/linux/drm_memory_manager.h"
13+
#include "shared/source/os_interface/linux/drm_neo.h"
1214
#include "shared/source/os_interface/linux/os_time_linux.h"
1315
#include "shared/source/utilities/stackvec.h"
1416

17+
#include "drm/i915_drm.h"
18+
1519
#include <errno.h>
1620
#include <fcntl.h>
21+
#include <map>
1722
#include <stdarg.h>
23+
#include <string.h>
1824
#include <sys/ioctl.h>
1925
#include <sys/mman.h>
2026
#include <sys/syscall.h>
@@ -94,6 +100,30 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_
94100
execObject.rsvd2 = 0;
95101
}
96102

103+
int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, BufferObject *const residency[], size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage) {
104+
for (size_t i = 0; i < residencyCount; i++) {
105+
residency[i]->fillExecObject(execObjectsStorage[i], drmContextId);
106+
}
107+
this->fillExecObject(execObjectsStorage[residencyCount], drmContextId);
108+
109+
drm_i915_gem_execbuffer2 execbuf{};
110+
execbuf.buffers_ptr = reinterpret_cast<uintptr_t>(execObjectsStorage);
111+
execbuf.buffer_count = static_cast<uint32_t>(residencyCount + 1u);
112+
execbuf.batch_start_offset = static_cast<uint32_t>(startOffset);
113+
execbuf.batch_len = alignUp(used, 8);
114+
execbuf.flags = flags;
115+
execbuf.rsvd1 = drmContextId;
116+
117+
int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
118+
if (ret == 0) {
119+
return 0;
120+
}
121+
122+
int err = this->drm->getErrno();
123+
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(I915_GEM_EXECBUFFER2) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
124+
return err;
125+
}
126+
97127
int BufferObject::pin(BufferObject *const boToPin[], size_t numberOfBos, uint32_t drmContextId) {
98128
reinterpret_cast<uint32_t *>(this->gpuAddress)[0] = 0x05000000;
99129
reinterpret_cast<uint32_t *>(this->gpuAddress)[1] = 0x00000000;

shared/source/os_interface/linux/drm_buffer_object.h

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66
*/
77

88
#pragma once
9-
#include "shared/source/debug_settings/debug_settings_manager.h"
10-
#include "shared/source/helpers/aligned_memory.h"
11-
#include "shared/source/os_interface/linux/drm_neo.h"
12-
13-
#include "drm/i915_drm.h"
14-
159
#include <atomic>
1610
#include <cstddef>
17-
#include <cstdio>
1811
#include <stdint.h>
19-
#include <string.h>
20-
#include <sys/ioctl.h>
12+
13+
struct drm_i915_gem_exec_object2;
14+
struct drm_i915_gem_relocation_entry;
2115

2216
namespace NEO {
2317

@@ -35,8 +29,7 @@ class BufferObject {
3529

3630
MOCKABLE_VIRTUAL int pin(BufferObject *const boToPin[], size_t numberOfBos, uint32_t drmContextId);
3731

38-
template <typename Iterator>
39-
int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, Iterator begin, size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage);
32+
int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, BufferObject *const residency[], size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage);
4033

4134
int wait(int64_t timeoutNs);
4235
bool close();
@@ -54,6 +47,7 @@ class BufferObject {
5447
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
5548
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
5649
uint64_t peekUnmapSize() const { return unmapSize; }
50+
bool peekIsReusableAllocation() const { return this->isReused; }
5751

5852
protected:
5953
Drm *drm = nullptr;
@@ -75,29 +69,4 @@ class BufferObject {
7569

7670
uint64_t unmapSize = 0;
7771
};
78-
79-
template <typename Iterator>
80-
inline int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, Iterator begin, size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage) {
81-
for (size_t i = 0; i < residencyCount; ++i) {
82-
(*begin++)->fillExecObject(execObjectsStorage[i], drmContextId);
83-
}
84-
this->fillExecObject(execObjectsStorage[residencyCount], drmContextId);
85-
86-
drm_i915_gem_execbuffer2 execbuf{};
87-
execbuf.buffers_ptr = reinterpret_cast<uintptr_t>(execObjectsStorage);
88-
execbuf.buffer_count = static_cast<uint32_t>(residencyCount + 1u);
89-
execbuf.batch_start_offset = static_cast<uint32_t>(startOffset);
90-
execbuf.batch_len = alignUp(used, 8);
91-
execbuf.flags = flags;
92-
execbuf.rsvd1 = drmContextId;
93-
94-
int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
95-
if (ret == 0) {
96-
return 0;
97-
}
98-
99-
int err = this->drm->getErrno();
100-
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(I915_GEM_EXECBUFFER2) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
101-
return err;
102-
}
10372
} // namespace NEO

0 commit comments

Comments
 (0)