-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathkernel.cpp
2366 lines (2005 loc) · 106 KB
/
kernel.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/kernel/kernel.h"
#include "shared/source/built_ins/built_ins.h"
#include "shared/source/command_container/implicit_scaling.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/address_patch.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/bindless_heaps_helper.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/get_info.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/kernel_helpers.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/simd_helper.h"
#include "shared/source/helpers/surface_format_info.h"
#include "shared/source/kernel/implicit_args_helper.h"
#include "shared/source/kernel/kernel_arg_descriptor_extended_vme.h"
#include "shared/source/kernel/local_ids_cache.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/compression_selector.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/source/os_interface/product_helper.h"
#include "shared/source/page_fault_manager/cpu_page_fault_manager.h"
#include "shared/source/program/kernel_info.h"
#include "shared/source/utilities/lookup_array.h"
#include "shared/source/utilities/tag_allocator.h"
#include "opencl/source/accelerators/intel_accelerator.h"
#include "opencl/source/accelerators/intel_motion_estimation.h"
#include "opencl/source/built_ins/builtins_dispatch_builder.h"
#include "opencl/source/cl_device/cl_device.h"
#include "opencl/source/command_queue/cl_local_work_size.h"
#include "opencl/source/command_queue/command_queue.h"
#include "opencl/source/context/context.h"
#include "opencl/source/event/event.h"
#include "opencl/source/gtpin/gtpin_notify.h"
#include "opencl/source/helpers/cl_gfx_core_helper.h"
#include "opencl/source/helpers/cl_validators.h"
#include "opencl/source/helpers/dispatch_info.h"
#include "opencl/source/helpers/get_info_status_mapper.h"
#include "opencl/source/helpers/sampler_helpers.h"
#include "opencl/source/kernel/kernel_info_cl.h"
#include "opencl/source/mem_obj/buffer.h"
#include "opencl/source/mem_obj/image.h"
#include "opencl/source/mem_obj/pipe.h"
#include "opencl/source/memory_manager/mem_obj_surface.h"
#include "opencl/source/program/program.h"
#include "opencl/source/sampler/sampler.h"
#include "patch_list.h"
#include <algorithm>
#include <cstdint>
#include <vector>
using namespace iOpenCL;
namespace NEO {
class Surface;
uint32_t Kernel::dummyPatchLocation = 0xbaddf00d;
Kernel::Kernel(Program *programArg, const KernelInfo &kernelInfoArg, ClDevice &clDeviceArg)
: executionEnvironment(programArg->getExecutionEnvironment()),
program(programArg),
clDevice(clDeviceArg),
kernelInfo(kernelInfoArg) {
program->retain();
program->retainForKernel();
auto &deviceInfo = getDevice().getDevice().getDeviceInfo();
if (isSimd1(kernelInfoArg.kernelDescriptor.kernelAttributes.simdSize)) {
auto &productHelper = getDevice().getProductHelper();
maxKernelWorkGroupSize = productHelper.getMaxThreadsForWorkgroupInDSSOrSS(getHardwareInfo(), static_cast<uint32_t>(deviceInfo.maxNumEUsPerSubSlice), static_cast<uint32_t>(deviceInfo.maxNumEUsPerDualSubSlice));
} else {
maxKernelWorkGroupSize = static_cast<uint32_t>(deviceInfo.maxWorkGroupSize);
}
slmTotalSize = kernelInfoArg.kernelDescriptor.kernelAttributes.slmInlineSize;
}
Kernel::~Kernel() {
delete[] crossThreadData;
crossThreadData = nullptr;
crossThreadDataSize = 0;
if (privateSurface) {
program->peekExecutionEnvironment().memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(privateSurface);
privateSurface = nullptr;
}
for (uint32_t i = 0; i < patchedArgumentsNum; i++) {
if (SAMPLER_OBJ == getKernelArguments()[i].type) {
auto sampler = castToObject<Sampler>(kernelArguments.at(i).object);
if (sampler) {
sampler->decRefInternal();
}
}
}
kernelArgHandlers.clear();
program->releaseForKernel();
program->release();
}
// If dstOffsetBytes is not an invalid offset, then patches dst at dstOffsetBytes
// with src casted to DstT type.
template <typename DstT, typename SrcT>
inline void patch(const SrcT &src, void *dst, CrossThreadDataOffset dstOffsetBytes) {
if (isValidOffset(dstOffsetBytes)) {
DstT *patchLocation = reinterpret_cast<DstT *>(ptrOffset(dst, dstOffsetBytes));
*patchLocation = static_cast<DstT>(src);
}
}
void Kernel::patchWithImplicitSurface(uint64_t ptrToPatchInCrossThreadData, GraphicsAllocation &allocation, const ArgDescPointer &arg) {
if ((nullptr != crossThreadData) && isValidOffset(arg.stateless)) {
auto pp = ptrOffset(crossThreadData, arg.stateless);
patchWithRequiredSize(pp, arg.pointerSize, ptrToPatchInCrossThreadData);
if (debugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
PatchInfoData patchInfoData(ptrToPatchInCrossThreadData, 0u, PatchInfoAllocationType::kernelArg, reinterpret_cast<uint64_t>(crossThreadData), arg.stateless, PatchInfoAllocationType::indirectObjectHeap, arg.pointerSize);
this->patchInfoDataList.push_back(patchInfoData);
}
}
void *ssh = getSurfaceStateHeap();
if (nullptr != ssh) {
void *addressToPatch = reinterpret_cast<void *>(allocation.getGpuAddressToPatch());
size_t sizeToPatch = allocation.getUnderlyingBufferSize();
if (isValidOffset(arg.bindful)) {
auto surfaceState = ptrOffset(ssh, arg.bindful);
Buffer::setSurfaceState(&clDevice.getDevice(), surfaceState, false, false, sizeToPatch, addressToPatch, 0, &allocation, 0, 0,
areMultipleSubDevicesInContext());
} else if (isValidOffset(arg.bindless)) {
auto &gfxCoreHelper = clDevice.getDevice().getGfxCoreHelper();
void *surfaceState = nullptr;
auto surfaceStateSize = gfxCoreHelper.getRenderSurfaceStateSize();
if (clDevice.getDevice().getBindlessHeapsHelper()) {
auto &ssInHeap = allocation.getBindlessInfo();
surfaceState = ssInHeap.ssPtr;
auto patchLocation = ptrOffset(crossThreadData, arg.bindless);
auto patchValue = gfxCoreHelper.getBindlessSurfaceExtendedMessageDescriptorValue(static_cast<uint32_t>(ssInHeap.surfaceStateOffset));
patchWithRequiredSize(reinterpret_cast<uint8_t *>(patchLocation), sizeof(patchValue), patchValue);
} else {
auto index = std::numeric_limits<uint32_t>::max();
const auto &iter = kernelInfo.kernelDescriptor.getBindlessOffsetToSurfaceState().find(arg.bindless);
if (iter != kernelInfo.kernelDescriptor.getBindlessOffsetToSurfaceState().end()) {
index = iter->second;
}
if (index < std::numeric_limits<uint32_t>::max()) {
surfaceState = ptrOffset(ssh, index * surfaceStateSize);
}
}
if (surfaceState) {
Buffer::setSurfaceState(&clDevice.getDevice(), surfaceState, false, false, sizeToPatch, addressToPatch, 0, &allocation, 0, 0,
areMultipleSubDevicesInContext());
}
}
}
}
cl_int Kernel::initialize() {
auto pClDevice = &getDevice();
auto rootDeviceIndex = pClDevice->getRootDeviceIndex();
reconfigureKernel();
auto &hwInfo = pClDevice->getHardwareInfo();
auto &rootDeviceEnvironment = pClDevice->getRootDeviceEnvironment();
auto &gfxCoreHelper = rootDeviceEnvironment.getHelper<GfxCoreHelper>();
auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
auto &kernelDescriptor = kernelInfo.kernelDescriptor;
const auto &implicitArgs = kernelDescriptor.payloadMappings.implicitArgs;
const auto &explicitArgs = kernelDescriptor.payloadMappings.explicitArgs;
auto maxSimdSize = kernelInfo.getMaxSimdSize();
const auto &heapInfo = kernelInfo.heapInfo;
auto localMemSize = static_cast<uint32_t>(clDevice.getDevice().getDeviceInfo().localMemSize);
auto slmTotalSize = this->getSlmTotalSize();
if (slmTotalSize > 0 && localMemSize < slmTotalSize) {
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Size of SLM (%u) larger than available (%u)\n", slmTotalSize, localMemSize);
return CL_OUT_OF_RESOURCES;
}
if (maxSimdSize != 1 && maxSimdSize < gfxCoreHelper.getMinimalSIMDSize()) {
return CL_INVALID_KERNEL;
}
if (kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs) {
pImplicitArgs = std::make_unique<ImplicitArgs>();
*pImplicitArgs = {};
pImplicitArgs->structSize = ImplicitArgs::getSize();
pImplicitArgs->structVersion = 0;
pImplicitArgs->simdWidth = maxSimdSize;
}
auto ret = KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(kernelDescriptor.kernelAttributes, &pClDevice->getDevice());
if (ret == NEO::KernelHelper::ErrorCode::invalidKernel) {
return CL_INVALID_KERNEL;
}
if (ret == NEO::KernelHelper::ErrorCode::outOfDeviceMemory) {
return CL_OUT_OF_RESOURCES;
}
crossThreadDataSize = kernelDescriptor.kernelAttributes.crossThreadDataSize;
// now allocate our own cross-thread data, if necessary
if (crossThreadDataSize) {
crossThreadData = new char[crossThreadDataSize];
if (kernelInfo.crossThreadData) {
memcpy_s(crossThreadData, crossThreadDataSize,
kernelInfo.crossThreadData, crossThreadDataSize);
} else {
memset(crossThreadData, 0x00, crossThreadDataSize);
}
auto crossThread = reinterpret_cast<uint32_t *>(crossThreadData);
auto setArgsIfValidOffset = [&](uint32_t *&crossThreadData, NEO::CrossThreadDataOffset offset, uint32_t value) {
if (isValidOffset(offset)) {
crossThreadData = ptrOffset(crossThread, offset);
*crossThreadData = value;
}
};
setArgsIfValidOffset(maxWorkGroupSizeForCrossThreadData, implicitArgs.maxWorkGroupSize, maxKernelWorkGroupSize);
setArgsIfValidOffset(dataParameterSimdSize, implicitArgs.simdSize, maxSimdSize);
setArgsIfValidOffset(preferredWkgMultipleOffset, implicitArgs.preferredWkgMultiple, maxSimdSize);
setArgsIfValidOffset(parentEventOffset, implicitArgs.deviceSideEnqueueParentEvent, undefined<uint32_t>);
}
// allocate our own SSH, if necessary
sshLocalSize = heapInfo.surfaceStateHeapSize;
if (sshLocalSize) {
pSshLocal = std::make_unique<char[]>(sshLocalSize);
// copy the ssh into our local copy
memcpy_s(pSshLocal.get(), sshLocalSize,
heapInfo.pSsh, heapInfo.surfaceStateHeapSize);
} else if (NEO::KernelDescriptor::isBindlessAddressingKernel(kernelDescriptor)) {
auto surfaceStateSize = static_cast<uint32_t>(gfxCoreHelper.getRenderSurfaceStateSize());
sshLocalSize = kernelDescriptor.kernelAttributes.numArgsStateful * surfaceStateSize;
DEBUG_BREAK_IF(kernelDescriptor.kernelAttributes.numArgsStateful != kernelDescriptor.getBindlessOffsetToSurfaceState().size());
pSshLocal = std::make_unique<char[]>(sshLocalSize);
}
numberOfBindingTableStates = kernelDescriptor.payloadMappings.bindingTable.numEntries;
localBindingTableOffset = kernelDescriptor.payloadMappings.bindingTable.tableOffset;
// patch crossthread data and ssh with inline surfaces, if necessary
auto status = patchPrivateSurface();
if (CL_SUCCESS != status) {
return status;
}
if (isValidOffset(kernelDescriptor.payloadMappings.implicitArgs.globalConstantsSurfaceAddress.stateless) ||
isValidOffset(kernelDescriptor.payloadMappings.implicitArgs.globalConstantsSurfaceAddress.bindless)) {
DEBUG_BREAK_IF(program->getConstantSurface(rootDeviceIndex) == nullptr);
uint64_t constMemory = isBuiltIn ? castToUint64(program->getConstantSurface(rootDeviceIndex)->getUnderlyingBuffer()) : program->getConstantSurface(rootDeviceIndex)->getGpuAddressToPatch();
const auto &arg = kernelDescriptor.payloadMappings.implicitArgs.globalConstantsSurfaceAddress;
patchWithImplicitSurface(constMemory, *program->getConstantSurface(rootDeviceIndex), arg);
}
if (isValidOffset(kernelDescriptor.payloadMappings.implicitArgs.globalVariablesSurfaceAddress.stateless) ||
isValidOffset(kernelDescriptor.payloadMappings.implicitArgs.globalVariablesSurfaceAddress.bindless)) {
DEBUG_BREAK_IF(program->getGlobalSurface(rootDeviceIndex) == nullptr);
uint64_t globalMemory = isBuiltIn ? castToUint64(program->getGlobalSurface(rootDeviceIndex)->getUnderlyingBuffer()) : program->getGlobalSurface(rootDeviceIndex)->getGpuAddressToPatch();
const auto &arg = kernelDescriptor.payloadMappings.implicitArgs.globalVariablesSurfaceAddress;
patchWithImplicitSurface(globalMemory, *program->getGlobalSurface(rootDeviceIndex), arg);
}
if (isValidOffset(kernelDescriptor.payloadMappings.implicitArgs.deviceSideEnqueueDefaultQueueSurfaceAddress.bindful)) {
auto surfaceState = ptrOffset(reinterpret_cast<uintptr_t *>(getSurfaceStateHeap()),
kernelDescriptor.payloadMappings.implicitArgs.deviceSideEnqueueDefaultQueueSurfaceAddress.bindful);
Buffer::setSurfaceState(&pClDevice->getDevice(), surfaceState, false, false, 0, nullptr, 0, nullptr, 0, 0, areMultipleSubDevicesInContext());
}
auto &threadArbitrationPolicy = const_cast<ThreadArbitrationPolicy &>(kernelInfo.kernelDescriptor.kernelAttributes.threadArbitrationPolicy);
if (threadArbitrationPolicy == ThreadArbitrationPolicy::NotPresent) {
threadArbitrationPolicy = static_cast<ThreadArbitrationPolicy>(gfxCoreHelper.getDefaultThreadArbitrationPolicy());
}
if (kernelInfo.kernelDescriptor.kernelAttributes.flags.requiresSubgroupIndependentForwardProgress == true) {
threadArbitrationPolicy = ThreadArbitrationPolicy::RoundRobin;
}
auto &clGfxCoreHelper = rootDeviceEnvironment.getHelper<ClGfxCoreHelper>();
auxTranslationRequired = !program->getIsBuiltIn() && GfxCoreHelper::compressedBuffersSupported(hwInfo) && clGfxCoreHelper.requiresAuxResolves(kernelInfo);
if (debugManager.flags.ForceAuxTranslationEnabled.get() != -1) {
auxTranslationRequired &= !!debugManager.flags.ForceAuxTranslationEnabled.get();
}
if (auxTranslationRequired) {
program->getContextPtr()->setResolvesRequiredInKernels(true);
}
auto numArgs = explicitArgs.size();
slmSizes.resize(numArgs);
this->setInlineSamplers();
bool detectIndirectAccessInKernel = productHelper.isDetectIndirectAccessInKernelSupported(kernelDescriptor, program->getCreatedFromBinary(), program->getIndirectDetectionVersion());
if (debugManager.flags.DetectIndirectAccessInKernel.get() != -1) {
detectIndirectAccessInKernel = debugManager.flags.DetectIndirectAccessInKernel.get() == 1;
}
if (detectIndirectAccessInKernel) {
this->kernelHasIndirectAccess = kernelDescriptor.kernelAttributes.hasNonKernelArgLoad ||
kernelDescriptor.kernelAttributes.hasNonKernelArgStore ||
kernelDescriptor.kernelAttributes.hasNonKernelArgAtomic ||
kernelDescriptor.kernelAttributes.hasIndirectStatelessAccess ||
kernelDescriptor.kernelAttributes.hasIndirectAccessInImplicitArg ||
kernelDescriptor.kernelAttributes.flags.useStackCalls ||
NEO::KernelHelper::isAnyArgumentPtrByValue(kernelDescriptor);
} else {
this->kernelHasIndirectAccess = true;
}
provideInitializationHints();
// resolve the new kernel info to account for kernel handlers
// I think by this time we have decoded the binary and know the number of args etc.
// double check this assumption
bool usingBuffers = false;
kernelArguments.resize(numArgs);
kernelArgHandlers.resize(numArgs);
for (uint32_t i = 0; i < numArgs; ++i) {
storeKernelArg(i, NONE_OBJ, nullptr, nullptr, 0);
// set the argument handler
const auto &arg = explicitArgs[i];
if (arg.is<ArgDescriptor::argTPointer>()) {
if (arg.getTraits().addressQualifier == KernelArgMetadata::AddrLocal) {
kernelArgHandlers[i] = &Kernel::setArgLocal;
} else if (arg.getTraits().typeQualifiers.pipeQual) {
kernelArgHandlers[i] = &Kernel::setArgPipe;
kernelArguments[i].type = PIPE_OBJ;
} else {
kernelArgHandlers[i] = &Kernel::setArgBuffer;
kernelArguments[i].type = BUFFER_OBJ;
usingBuffers = true;
allBufferArgsStateful &= static_cast<uint32_t>(arg.as<ArgDescPointer>().isPureStateful());
}
} else if (arg.is<ArgDescriptor::argTImage>()) {
kernelArgHandlers[i] = &Kernel::setArgImage;
kernelArguments[i].type = IMAGE_OBJ;
usingImages = true;
} else if (arg.is<ArgDescriptor::argTSampler>()) {
if (arg.getExtendedTypeInfo().isAccelerator) {
kernelArgHandlers[i] = &Kernel::setArgAccelerator;
} else {
kernelArgHandlers[i] = &Kernel::setArgSampler;
kernelArguments[i].type = SAMPLER_OBJ;
}
} else {
kernelArgHandlers[i] = &Kernel::setArgImmediate;
}
}
if (usingImages && !usingBuffers) {
usingImagesOnly = true;
}
if (kernelDescriptor.kernelAttributes.numLocalIdChannels > 0) {
initializeLocalIdsCache();
}
return CL_SUCCESS;
}
cl_int Kernel::patchPrivateSurface() {
auto pClDevice = &getDevice();
auto rootDeviceIndex = pClDevice->getRootDeviceIndex();
auto &kernelDescriptor = kernelInfo.kernelDescriptor;
auto perHwThreadPrivateMemorySize = kernelDescriptor.kernelAttributes.perHwThreadPrivateMemorySize;
if (perHwThreadPrivateMemorySize) {
if (!privateSurface) {
privateSurfaceSize = KernelHelper::getPrivateSurfaceSize(perHwThreadPrivateMemorySize, pClDevice->getSharedDeviceInfo().computeUnitsUsedForScratch);
DEBUG_BREAK_IF(privateSurfaceSize == 0);
privateSurface = executionEnvironment.memoryManager->allocateGraphicsMemoryWithProperties(
{rootDeviceIndex,
static_cast<size_t>(privateSurfaceSize),
AllocationType::privateSurface,
pClDevice->getDeviceBitfield()});
if (privateSurface == nullptr) {
return CL_OUT_OF_RESOURCES;
}
}
const auto &privateMemoryAddress = kernelDescriptor.payloadMappings.implicitArgs.privateMemoryAddress;
patchWithImplicitSurface(privateSurface->getGpuAddressToPatch(), *privateSurface, privateMemoryAddress);
}
return CL_SUCCESS;
}
cl_int Kernel::cloneKernel(Kernel *pSourceKernel) {
// copy cross thread data to store arguments set to source kernel with clSetKernelArg on immediate data (non-pointer types)
memcpy_s(crossThreadData, crossThreadDataSize,
pSourceKernel->crossThreadData, pSourceKernel->crossThreadDataSize);
DEBUG_BREAK_IF(pSourceKernel->crossThreadDataSize != crossThreadDataSize);
[[maybe_unused]] auto status = patchPrivateSurface();
DEBUG_BREAK_IF(status != CL_SUCCESS);
// copy arguments set to source kernel with clSetKernelArg or clSetKernelArgSVMPointer
for (uint32_t i = 0; i < pSourceKernel->kernelArguments.size(); i++) {
if (0 == pSourceKernel->getKernelArgInfo(i).size) {
// skip copying arguments that haven't been set to source kernel
continue;
}
switch (pSourceKernel->kernelArguments[i].type) {
case NONE_OBJ:
// all arguments with immediate data (non-pointer types) have been copied in cross thread data
storeKernelArg(i, NONE_OBJ, nullptr, nullptr, pSourceKernel->getKernelArgInfo(i).size);
patchedArgumentsNum++;
kernelArguments[i].isPatched = true;
break;
case SVM_OBJ:
setArgSvm(i, pSourceKernel->getKernelArgInfo(i).size, const_cast<void *>(pSourceKernel->getKernelArgInfo(i).value),
pSourceKernel->getKernelArgInfo(i).svmAllocation, pSourceKernel->getKernelArgInfo(i).svmFlags);
break;
case SVM_ALLOC_OBJ:
setArgSvmAlloc(i, const_cast<void *>(pSourceKernel->getKernelArgInfo(i).value),
(GraphicsAllocation *)pSourceKernel->getKernelArgInfo(i).object,
pSourceKernel->getKernelArgInfo(i).allocId);
break;
case BUFFER_OBJ:
setArg(i, pSourceKernel->getKernelArgInfo(i).size, &pSourceKernel->getKernelArgInfo(i).object);
break;
default:
setArg(i, pSourceKernel->getKernelArgInfo(i).size, pSourceKernel->getKernelArgInfo(i).value);
break;
}
}
// copy additional information other than argument values set to source kernel with clSetKernelExecInfo
for (auto &gfxAlloc : pSourceKernel->kernelSvmGfxAllocations) {
kernelSvmGfxAllocations.push_back(gfxAlloc);
}
for (auto &gfxAlloc : pSourceKernel->kernelUnifiedMemoryGfxAllocations) {
kernelUnifiedMemoryGfxAllocations.push_back(gfxAlloc);
}
if (pImplicitArgs) {
memcpy_s(pImplicitArgs.get(), ImplicitArgs::getSize(), pSourceKernel->getImplicitArgs(), ImplicitArgs::getSize());
}
this->isBuiltIn = pSourceKernel->isBuiltIn;
return CL_SUCCESS;
}
cl_int Kernel::getInfo(cl_kernel_info paramName, size_t paramValueSize,
void *paramValue, size_t *paramValueSizeRet) const {
cl_int retVal;
const void *pSrc = nullptr;
size_t srcSize = GetInfo::invalidSourceSize;
cl_uint numArgs = 0;
const _cl_program *prog;
const _cl_context *ctxt;
cl_uint refCount = 0;
uint64_t nonCannonizedGpuAddress = 0llu;
auto gmmHelper = clDevice.getDevice().getGmmHelper();
switch (paramName) {
case CL_KERNEL_FUNCTION_NAME:
pSrc = kernelInfo.kernelDescriptor.kernelMetadata.kernelName.c_str();
srcSize = kernelInfo.kernelDescriptor.kernelMetadata.kernelName.length() + 1;
break;
case CL_KERNEL_NUM_ARGS:
srcSize = sizeof(cl_uint);
numArgs = static_cast<cl_uint>(kernelInfo.kernelDescriptor.payloadMappings.explicitArgs.size());
pSrc = &numArgs;
break;
case CL_KERNEL_CONTEXT:
ctxt = &program->getContext();
srcSize = sizeof(ctxt);
pSrc = &ctxt;
break;
case CL_KERNEL_PROGRAM:
prog = program;
srcSize = sizeof(prog);
pSrc = &prog;
break;
case CL_KERNEL_REFERENCE_COUNT:
refCount = static_cast<cl_uint>(pMultiDeviceKernel->getRefApiCount());
srcSize = sizeof(refCount);
pSrc = &refCount;
break;
case CL_KERNEL_ATTRIBUTES:
pSrc = kernelInfo.kernelDescriptor.kernelMetadata.kernelLanguageAttributes.c_str();
srcSize = kernelInfo.kernelDescriptor.kernelMetadata.kernelLanguageAttributes.length() + 1;
break;
case CL_KERNEL_BINARY_PROGRAM_INTEL:
pSrc = getKernelHeap();
srcSize = getKernelHeapSize();
break;
case CL_KERNEL_BINARY_GPU_ADDRESS_INTEL:
nonCannonizedGpuAddress = gmmHelper->decanonize(kernelInfo.kernelAllocation->getGpuAddress());
pSrc = &nonCannonizedGpuAddress;
srcSize = sizeof(nonCannonizedGpuAddress);
break;
default:
break;
}
auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize);
retVal = changeGetInfoStatusToCLResultType(getInfoStatus);
GetInfo::setParamValueReturnSize(paramValueSizeRet, srcSize, getInfoStatus);
return retVal;
}
cl_int Kernel::getArgInfo(cl_uint argIndex, cl_kernel_arg_info paramName, size_t paramValueSize,
void *paramValue, size_t *paramValueSizeRet) const {
cl_int retVal;
const void *pSrc = nullptr;
size_t srcSize = GetInfo::invalidSourceSize;
const auto &args = kernelInfo.kernelDescriptor.payloadMappings.explicitArgs;
if (argIndex >= args.size()) {
retVal = CL_INVALID_ARG_INDEX;
return retVal;
}
program->callPopulateZebinExtendedArgsMetadataOnce(clDevice.getRootDeviceIndex());
program->callGenerateDefaultExtendedArgsMetadataOnce(clDevice.getRootDeviceIndex());
const auto &argTraits = args[argIndex].getTraits();
const auto &argMetadata = kernelInfo.kernelDescriptor.explicitArgsExtendedMetadata[argIndex];
cl_kernel_arg_address_qualifier addressQualifier;
cl_kernel_arg_access_qualifier accessQualifier;
cl_kernel_arg_type_qualifier typeQualifier;
switch (paramName) {
case CL_KERNEL_ARG_ADDRESS_QUALIFIER:
addressQualifier = asClKernelArgAddressQualifier(argTraits.getAddressQualifier());
srcSize = sizeof(addressQualifier);
pSrc = &addressQualifier;
break;
case CL_KERNEL_ARG_ACCESS_QUALIFIER:
accessQualifier = asClKernelArgAccessQualifier(argTraits.getAccessQualifier());
srcSize = sizeof(accessQualifier);
pSrc = &accessQualifier;
break;
case CL_KERNEL_ARG_TYPE_QUALIFIER:
typeQualifier = asClKernelArgTypeQualifier(argTraits.typeQualifiers);
srcSize = sizeof(typeQualifier);
pSrc = &typeQualifier;
break;
case CL_KERNEL_ARG_TYPE_NAME:
srcSize = argMetadata.type.length() + 1;
pSrc = argMetadata.type.c_str();
break;
case CL_KERNEL_ARG_NAME:
srcSize = argMetadata.argName.length() + 1;
pSrc = argMetadata.argName.c_str();
break;
default:
break;
}
auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize);
retVal = changeGetInfoStatusToCLResultType(getInfoStatus);
GetInfo::setParamValueReturnSize(paramValueSizeRet, srcSize, getInfoStatus);
return retVal;
}
cl_int Kernel::getWorkGroupInfo(cl_kernel_work_group_info paramName,
size_t paramValueSize, void *paramValue,
size_t *paramValueSizeRet) const {
cl_int retVal = CL_INVALID_VALUE;
const void *pSrc = nullptr;
size_t srcSize = GetInfo::invalidSourceSize;
struct SizeT3 {
size_t val[3];
} requiredWorkGroupSize;
cl_ulong localMemorySize;
const auto &kernelDescriptor = kernelInfo.kernelDescriptor;
size_t preferredWorkGroupSizeMultiple = 0;
cl_ulong scratchSize;
cl_ulong privateMemSize;
size_t maxWorkgroupSize;
cl_uint regCount;
const auto &hwInfo = clDevice.getHardwareInfo();
auto &gfxCoreHelper = this->getGfxCoreHelper();
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
switch (paramName) {
case CL_KERNEL_WORK_GROUP_SIZE:
maxWorkgroupSize = maxKernelWorkGroupSize;
if (debugManager.flags.UseMaxSimdSizeToDeduceMaxWorkgroupSize.get()) {
auto divisionSize = CommonConstants::maximalSimdSize / kernelInfo.getMaxSimdSize();
maxWorkgroupSize /= divisionSize;
}
srcSize = sizeof(maxWorkgroupSize);
pSrc = &maxWorkgroupSize;
break;
case CL_KERNEL_COMPILE_WORK_GROUP_SIZE:
requiredWorkGroupSize.val[0] = kernelDescriptor.kernelAttributes.requiredWorkgroupSize[0];
requiredWorkGroupSize.val[1] = kernelDescriptor.kernelAttributes.requiredWorkgroupSize[1];
requiredWorkGroupSize.val[2] = kernelDescriptor.kernelAttributes.requiredWorkgroupSize[2];
srcSize = sizeof(requiredWorkGroupSize);
pSrc = &requiredWorkGroupSize;
break;
case CL_KERNEL_LOCAL_MEM_SIZE:
localMemorySize = this->getSlmTotalSize();
srcSize = sizeof(localMemorySize);
pSrc = &localMemorySize;
break;
case CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE:
preferredWorkGroupSizeMultiple = kernelInfo.getMaxSimdSize();
if (gfxCoreHelper.isFusedEuDispatchEnabled(hwInfo, kernelDescriptor.kernelAttributes.flags.requiresDisabledEUFusion)) {
preferredWorkGroupSizeMultiple *= 2;
}
srcSize = sizeof(preferredWorkGroupSizeMultiple);
pSrc = &preferredWorkGroupSizeMultiple;
break;
case CL_KERNEL_SPILL_MEM_SIZE_INTEL:
scratchSize = kernelDescriptor.kernelAttributes.spillFillScratchMemorySize;
srcSize = sizeof(scratchSize);
pSrc = &scratchSize;
break;
case CL_KERNEL_PRIVATE_MEM_SIZE:
privateMemSize = gfxCoreHelper.getKernelPrivateMemSize(kernelDescriptor);
srcSize = sizeof(privateMemSize);
pSrc = &privateMemSize;
break;
case CL_KERNEL_EU_THREAD_COUNT_INTEL:
srcSize = sizeof(cl_uint);
pSrc = &this->getKernelInfo().kernelDescriptor.kernelAttributes.numThreadsRequired;
break;
case CL_KERNEL_REGISTER_COUNT_INTEL:
regCount = kernelDescriptor.kernelAttributes.numGrfRequired;
srcSize = sizeof(cl_uint);
pSrc = ®Count;
break;
default:
break;
}
auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize);
retVal = changeGetInfoStatusToCLResultType(getInfoStatus);
GetInfo::setParamValueReturnSize(paramValueSizeRet, srcSize, getInfoStatus);
return retVal;
}
cl_int Kernel::getSubGroupInfo(cl_kernel_sub_group_info paramName,
size_t inputValueSize, const void *inputValue,
size_t paramValueSize, void *paramValue,
size_t *paramValueSizeRet) const {
size_t numDimensions = 0;
size_t wgs = 1;
auto maxSimdSize = static_cast<size_t>(kernelInfo.getMaxSimdSize());
auto maxRequiredWorkGroupSize = static_cast<size_t>(kernelInfo.getMaxRequiredWorkGroupSize(getMaxKernelWorkGroupSize()));
auto largestCompiledSIMDSize = static_cast<size_t>(kernelInfo.getMaxSimdSize());
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
if ((paramName == CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT) ||
(paramName == CL_KERNEL_MAX_NUM_SUB_GROUPS) ||
(paramName == CL_KERNEL_COMPILE_NUM_SUB_GROUPS)) {
if (clDevice.areOcl21FeaturesEnabled() == false) {
return CL_INVALID_OPERATION;
}
}
if ((paramName == CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR) ||
(paramName == CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR)) {
if (!inputValue) {
return CL_INVALID_VALUE;
}
if (inputValueSize % sizeof(size_t) != 0) {
return CL_INVALID_VALUE;
}
numDimensions = inputValueSize / sizeof(size_t);
if (numDimensions == 0 ||
numDimensions > static_cast<size_t>(clDevice.getDeviceInfo().maxWorkItemDimensions)) {
return CL_INVALID_VALUE;
}
}
if (paramName == CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT) {
if (!paramValue) {
return CL_INVALID_VALUE;
}
if (paramValueSize % sizeof(size_t) != 0) {
return CL_INVALID_VALUE;
}
numDimensions = paramValueSize / sizeof(size_t);
if (numDimensions == 0 ||
numDimensions > static_cast<size_t>(clDevice.getDeviceInfo().maxWorkItemDimensions)) {
return CL_INVALID_VALUE;
}
}
switch (paramName) {
case CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR: {
return changeGetInfoStatusToCLResultType(info.set<size_t>(maxSimdSize));
}
case CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR: {
for (size_t i = 0; i < numDimensions; i++) {
wgs *= ((size_t *)inputValue)[i];
}
return changeGetInfoStatusToCLResultType(
info.set<size_t>((wgs / maxSimdSize) + std::min(static_cast<size_t>(1), wgs % maxSimdSize))); // add 1 if WGS % maxSimdSize != 0
}
case CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT: {
auto subGroupsNum = *(size_t *)inputValue;
auto workGroupSize = subGroupsNum * largestCompiledSIMDSize;
// return workgroup size in first dimension, the rest shall be 1 in positive case
if (workGroupSize > maxRequiredWorkGroupSize) {
workGroupSize = 0;
}
// If no work group size can accommodate the requested number of subgroups, return 0 in each element of the returned array.
switch (numDimensions) {
case 1:
return changeGetInfoStatusToCLResultType(info.set<size_t>(workGroupSize));
case 2:
struct SizeT2 {
size_t val[2];
} workGroupSize2;
workGroupSize2.val[0] = workGroupSize;
workGroupSize2.val[1] = (workGroupSize > 0) ? 1 : 0;
return changeGetInfoStatusToCLResultType(info.set<SizeT2>(workGroupSize2));
default:
struct SizeT3 {
size_t val[3];
} workGroupSize3;
workGroupSize3.val[0] = workGroupSize;
workGroupSize3.val[1] = (workGroupSize > 0) ? 1 : 0;
workGroupSize3.val[2] = (workGroupSize > 0) ? 1 : 0;
return changeGetInfoStatusToCLResultType(info.set<SizeT3>(workGroupSize3));
}
}
case CL_KERNEL_MAX_NUM_SUB_GROUPS: {
// round-up maximum number of subgroups
return changeGetInfoStatusToCLResultType(info.set<size_t>(Math::divideAndRoundUp(maxRequiredWorkGroupSize, largestCompiledSIMDSize)));
}
case CL_KERNEL_COMPILE_NUM_SUB_GROUPS: {
return changeGetInfoStatusToCLResultType(info.set<size_t>(static_cast<size_t>(kernelInfo.kernelDescriptor.kernelMetadata.compiledSubGroupsNumber)));
}
case CL_KERNEL_COMPILE_SUB_GROUP_SIZE_INTEL: {
return changeGetInfoStatusToCLResultType(info.set<size_t>(kernelInfo.kernelDescriptor.kernelMetadata.requiredSubGroupSize));
}
default:
return CL_INVALID_VALUE;
}
}
const void *Kernel::getKernelHeap() const {
return kernelInfo.heapInfo.pKernelHeap;
}
size_t Kernel::getKernelHeapSize() const {
return kernelInfo.heapInfo.kernelHeapSize;
}
void Kernel::substituteKernelHeap(void *newKernelHeap, size_t newKernelHeapSize) {
KernelInfo *pKernelInfo = const_cast<KernelInfo *>(&kernelInfo);
void **pKernelHeap = const_cast<void **>(&pKernelInfo->heapInfo.pKernelHeap);
*pKernelHeap = newKernelHeap;
auto &heapInfo = pKernelInfo->heapInfo;
heapInfo.kernelHeapSize = static_cast<uint32_t>(newKernelHeapSize);
pKernelInfo->isKernelHeapSubstituted = true;
auto memoryManager = executionEnvironment.memoryManager.get();
auto currentAllocationSize = pKernelInfo->kernelAllocation->getUnderlyingBufferSize();
bool status = false;
auto &rootDeviceEnvironment = clDevice.getRootDeviceEnvironment();
auto &helper = rootDeviceEnvironment.getHelper<GfxCoreHelper>();
size_t isaPadding = helper.getPaddingForISAAllocation();
if (currentAllocationSize >= newKernelHeapSize + isaPadding) {
auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
auto useBlitter = productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *pKernelInfo->getGraphicsAllocation());
status = MemoryTransferHelper::transferMemoryToAllocation(useBlitter,
clDevice.getDevice(), pKernelInfo->getGraphicsAllocation(), 0, newKernelHeap,
static_cast<size_t>(newKernelHeapSize));
} else {
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(pKernelInfo->kernelAllocation);
pKernelInfo->kernelAllocation = nullptr;
status = pKernelInfo->createKernelAllocation(clDevice.getDevice(), isBuiltIn);
}
UNRECOVERABLE_IF(!status);
}
bool Kernel::isKernelHeapSubstituted() const {
return kernelInfo.isKernelHeapSubstituted;
}
uint64_t Kernel::getKernelId() const {
return kernelInfo.kernelId;
}
void Kernel::setKernelId(uint64_t newKernelId) {
KernelInfo *pKernelInfo = const_cast<KernelInfo *>(&kernelInfo);
pKernelInfo->kernelId = newKernelId;
}
uint32_t Kernel::getStartOffset() const {
return this->startOffset;
}
Context &Kernel::getContext() const {
return program->getContext();
}
void Kernel::setStartOffset(uint32_t offset) {
this->startOffset = offset;
}
void *Kernel::getSurfaceStateHeap() const {
return pSshLocal.get();
}
size_t Kernel::getDynamicStateHeapSize() const {
return kernelInfo.heapInfo.dynamicStateHeapSize;
}
const void *Kernel::getDynamicStateHeap() const {
return kernelInfo.heapInfo.pDsh;
}
size_t Kernel::getSurfaceStateHeapSize() const {
return sshLocalSize;
}
size_t Kernel::getNumberOfBindingTableStates() const {
return numberOfBindingTableStates;
}
void Kernel::resizeSurfaceStateHeap(void *pNewSsh, size_t newSshSize, size_t newBindingTableCount, size_t newBindingTableOffset) {
pSshLocal.reset(static_cast<char *>(pNewSsh));
sshLocalSize = static_cast<uint32_t>(newSshSize);
numberOfBindingTableStates = newBindingTableCount;
localBindingTableOffset = newBindingTableOffset;
}
void Kernel::markArgPatchedAndResolveArgs(uint32_t argIndex) {
if (!kernelArguments[argIndex].isPatched) {
patchedArgumentsNum++;
kernelArguments[argIndex].isPatched = true;
}
if (program->getContextPtr() && getContext().getRootDeviceIndices().size() > 1u && Kernel::isMemObj(kernelArguments[argIndex].type) && kernelArguments[argIndex].object) {
auto argMemObj = castToObjectOrAbort<MemObj>(reinterpret_cast<cl_mem>(kernelArguments[argIndex].object));
auto memObj = argMemObj->getHighestRootMemObj();
auto migrateRequiredForArg = memObj->getMultiGraphicsAllocation().requiresMigrations();
if (migratableArgsMap.find(argIndex) == migratableArgsMap.end() && migrateRequiredForArg) {
migratableArgsMap.emplace(argIndex, memObj);
} else if (migrateRequiredForArg) {
migratableArgsMap[argIndex] = memObj;
} else {
migratableArgsMap.erase(argIndex);
}
}
}
cl_int Kernel::setArg(uint32_t argIndex, size_t argSize, const void *argVal) {
cl_int retVal = CL_SUCCESS;
bool updateExposedKernel = true;
auto argWasUncacheable = false;
if (kernelInfo.builtinDispatchBuilder != nullptr) {
updateExposedKernel = kernelInfo.builtinDispatchBuilder->setExplicitArg(argIndex, argSize, argVal, retVal);
}
if (updateExposedKernel) {
if (argIndex >= kernelArgHandlers.size()) {
return CL_INVALID_ARG_INDEX;
}
argWasUncacheable = kernelArguments[argIndex].isStatelessUncacheable;
auto argHandler = kernelArgHandlers[argIndex];
retVal = (this->*argHandler)(argIndex, argSize, argVal);
}
if (retVal == CL_SUCCESS) {
auto argIsUncacheable = kernelArguments[argIndex].isStatelessUncacheable;
statelessUncacheableArgsCount += (argIsUncacheable ? 1 : 0) - (argWasUncacheable ? 1 : 0);
markArgPatchedAndResolveArgs(argIndex);
}
return retVal;
}
cl_int Kernel::setArg(uint32_t argIndex, uint32_t argVal) {
return setArg(argIndex, sizeof(argVal), &argVal);
}
cl_int Kernel::setArg(uint32_t argIndex, uint64_t argVal) {
return setArg(argIndex, sizeof(argVal), &argVal);
}
cl_int Kernel::setArg(uint32_t argIndex, cl_mem argVal) {
return setArg(argIndex, sizeof(argVal), &argVal);
}
cl_int Kernel::setArg(uint32_t argIndex, cl_mem argVal, uint32_t mipLevel) {
auto retVal = setArgImageWithMipLevel(argIndex, sizeof(argVal), &argVal, mipLevel);
if (retVal == CL_SUCCESS) {
markArgPatchedAndResolveArgs(argIndex);
}
return retVal;
}
void *Kernel::patchBufferOffset(const ArgDescPointer &argAsPtr, void *svmPtr, GraphicsAllocation *svmAlloc) {
if (isUndefinedOffset(argAsPtr.bufferOffset)) {
return svmPtr;
}
void *ptrToPatch = svmPtr;
if (svmAlloc != nullptr) {
ptrToPatch = reinterpret_cast<void *>(svmAlloc->getGpuAddressToPatch());
}
constexpr uint32_t minimumAlignment = 4;
ptrToPatch = alignDown(ptrToPatch, minimumAlignment);
UNRECOVERABLE_IF(ptrDiff(svmPtr, ptrToPatch) != static_cast<uint32_t>(ptrDiff(svmPtr, ptrToPatch)));
uint32_t offsetToPatch = static_cast<uint32_t>(ptrDiff(svmPtr, ptrToPatch));
patch<uint32_t, uint32_t>(offsetToPatch, getCrossThreadData(), argAsPtr.bufferOffset);
return ptrToPatch;
}
cl_int Kernel::setArgSvm(uint32_t argIndex, size_t svmAllocSize, void *svmPtr, GraphicsAllocation *svmAlloc, cl_mem_flags svmFlags) {
const auto &argAsPtr = getKernelInfo().kernelDescriptor.payloadMappings.explicitArgs[argIndex].as<ArgDescPointer>();
auto patchLocation = ptrOffset(getCrossThreadData(), argAsPtr.stateless);
patchWithRequiredSize(patchLocation, argAsPtr.pointerSize, reinterpret_cast<uintptr_t>(svmPtr));
void *ptrToPatch = patchBufferOffset(argAsPtr, svmPtr, svmAlloc);
if (isValidOffset(argAsPtr.bindful)) {
auto surfaceState = ptrOffset(getSurfaceStateHeap(), argAsPtr.bindful);
Buffer::setSurfaceState(&getDevice().getDevice(), surfaceState, false, false, svmAllocSize + ptrDiff(svmPtr, ptrToPatch), ptrToPatch, 0, svmAlloc, svmFlags, 0,
areMultipleSubDevicesInContext());
} else if (isValidOffset(argAsPtr.bindless)) {
auto &gfxCoreHelper = this->getGfxCoreHelper();
auto surfaceStateSize = gfxCoreHelper.getRenderSurfaceStateSize();
auto ssIndex = getSurfaceStateIndexForBindlessOffset(argAsPtr.bindless);
if (ssIndex < std::numeric_limits<uint32_t>::max()) {
auto surfaceState = ptrOffset(getSurfaceStateHeap(), ssIndex * surfaceStateSize);
Buffer::setSurfaceState(&getDevice().getDevice(), surfaceState, false, false, svmAllocSize + ptrDiff(svmPtr, ptrToPatch), ptrToPatch, 0, svmAlloc, svmFlags, 0,
areMultipleSubDevicesInContext());
}
}
storeKernelArg(argIndex, SVM_OBJ, nullptr, svmPtr, sizeof(void *), svmAlloc, svmFlags);
if (!kernelArguments[argIndex].isPatched) {
patchedArgumentsNum++;
kernelArguments[argIndex].isPatched = true;
}
if (svmPtr != nullptr && isBuiltIn == false) {
this->anyKernelArgumentUsingSystemMemory |= true;
}
return CL_SUCCESS;
}
cl_int Kernel::setArgSvmAlloc(uint32_t argIndex, void *svmPtr, GraphicsAllocation *svmAlloc, uint32_t allocId) {
DBG_LOG_INPUTS("setArgBuffer svm_alloc", svmAlloc);
const auto &argAsPtr = getKernelInfo().kernelDescriptor.payloadMappings.explicitArgs[argIndex].as<ArgDescPointer>();
auto patchLocation = ptrOffset(getCrossThreadData(), argAsPtr.stateless);
patchWithRequiredSize(patchLocation, argAsPtr.pointerSize, reinterpret_cast<uintptr_t>(svmPtr));
auto &kernelArgInfo = kernelArguments[argIndex];
bool disableL3 = false;
bool forceNonAuxMode = false;
const bool isAuxTranslationKernel = (AuxTranslationDirection::none != auxTranslationDirection);
auto &rootDeviceEnvironment = getDevice().getRootDeviceEnvironment();
auto &clGfxCoreHelper = rootDeviceEnvironment.getHelper<ClGfxCoreHelper>();