@@ -4636,18 +4636,31 @@ pi_result piKernelCreate(pi_program Program, const char *KernelName,
46364636 return PI_ERROR_UNKNOWN;
46374637 }
46384638
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.
46414645 PI_CALL (piProgramRetain (Program));
46424646 if (IndirectAccessTrackingEnabled)
46434647 // TODO: do piContextRetain without the guard
46444648 PI_CALL (piContextRetain (Program->Context ));
46454649
46464650 // 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+ };
46514664
46524665 return PI_SUCCESS;
46534666}
@@ -4727,13 +4740,8 @@ pi_result piKernelGetInfo(pi_kernel Kernel, pi_kernel_info ParamName,
47274740 return ReturnValue (pi_program{Kernel->Program });
47284741 case PI_KERNEL_INFO_FUNCTION_NAME:
47294742 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 ()));
47374745 } catch (const std::bad_alloc &) {
47384746 return PI_OUT_OF_HOST_MEMORY;
47394747 } catch (...) {
@@ -5086,20 +5094,7 @@ pi_result piextKernelCreateWithNativeHandle(pi_native_handle NativeHandle,
50865094
50875095 auto ZeKernel = pi_cast<ze_kernel_handle_t >(NativeHandle);
50885096 *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 ());
51035098 return PI_SUCCESS;
51045099}
51055100
0 commit comments