@@ -4636,18 +4636,31 @@ pi_result piKernelCreate(pi_program Program, const char *KernelName,
4636
4636
return PI_ERROR_UNKNOWN;
4637
4637
}
4638
4638
4639
- // Update the refcount of the program and context to show it's used by this
4640
- // kernel.
4639
+ PI_CALL ((*RetKernel)->initialize ());
4640
+ return PI_SUCCESS;
4641
+ }
4642
+
4643
+ pi_result _pi_kernel::initialize () {
4644
+ // Retain the program and context to show it's used by this kernel.
4641
4645
PI_CALL (piProgramRetain (Program));
4642
4646
if (IndirectAccessTrackingEnabled)
4643
4647
// TODO: do piContextRetain without the guard
4644
4648
PI_CALL (piContextRetain (Program->Context ));
4645
4649
4646
4650
// Set up how to obtain kernel properties when needed.
4647
- (*RetKernel)->ZeKernelProperties .Compute =
4648
- [ZeKernel](ze_kernel_properties_t &Properties) {
4649
- ZE_CALL_NOCHECK (zeKernelGetProperties, (ZeKernel, &Properties));
4650
- };
4651
+ ZeKernelProperties.Compute = [this ](ze_kernel_properties_t &Properties) {
4652
+ ZE_CALL_NOCHECK (zeKernelGetProperties, (ZeKernel, &Properties));
4653
+ };
4654
+
4655
+ // Cache kernel name.
4656
+ ZeKernelName.Compute = [this ](std::string &Name) {
4657
+ size_t Size = 0 ;
4658
+ ZE_CALL_NOCHECK (zeKernelGetName, (ZeKernel, &Size, nullptr ));
4659
+ char *KernelName = new char [Size];
4660
+ ZE_CALL_NOCHECK (zeKernelGetName, (ZeKernel, &Size, KernelName));
4661
+ Name = KernelName;
4662
+ delete[] KernelName;
4663
+ };
4651
4664
4652
4665
return PI_SUCCESS;
4653
4666
}
@@ -4727,13 +4740,8 @@ pi_result piKernelGetInfo(pi_kernel Kernel, pi_kernel_info ParamName,
4727
4740
return ReturnValue (pi_program{Kernel->Program });
4728
4741
case PI_KERNEL_INFO_FUNCTION_NAME:
4729
4742
try {
4730
- size_t Size = 0 ;
4731
- ZE_CALL (zeKernelGetName, (Kernel->ZeKernel , &Size, nullptr ));
4732
- char *KernelName = new char [Size];
4733
- ZE_CALL (zeKernelGetName, (Kernel->ZeKernel , &Size, KernelName));
4734
- pi_result Res = ReturnValue (static_cast <const char *>(KernelName));
4735
- delete[] KernelName;
4736
- return Res;
4743
+ std::string &KernelName = *Kernel->ZeKernelName .operator ->();
4744
+ return ReturnValue (static_cast <const char *>(KernelName.c_str ()));
4737
4745
} catch (const std::bad_alloc &) {
4738
4746
return PI_OUT_OF_HOST_MEMORY;
4739
4747
} catch (...) {
@@ -5086,20 +5094,7 @@ pi_result piextKernelCreateWithNativeHandle(pi_native_handle NativeHandle,
5086
5094
5087
5095
auto ZeKernel = pi_cast<ze_kernel_handle_t >(NativeHandle);
5088
5096
*Kernel = new _pi_kernel (ZeKernel, OwnNativeHandle, Program);
5089
-
5090
- // Update the refcount of the program and context to show it's used by this
5091
- // kernel.
5092
- PI_CALL (piProgramRetain (Program));
5093
- if (IndirectAccessTrackingEnabled)
5094
- // TODO: do piContextRetain without the guard
5095
- PI_CALL (piContextRetain (Program->Context ));
5096
-
5097
- // Set up how to obtain kernel properties when needed.
5098
- (*Kernel)->ZeKernelProperties .Compute =
5099
- [ZeKernel](ze_kernel_properties_t &Properties) {
5100
- ZE_CALL_NOCHECK (zeKernelGetProperties, (ZeKernel, &Properties));
5101
- };
5102
-
5097
+ PI_CALL ((*Kernel)->initialize ());
5103
5098
return PI_SUCCESS;
5104
5099
}
5105
5100
0 commit comments