2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2023-04-24 19:05:30 +02:00
|
|
|
|
|
|
|
|
#ifdef WITH_HIPRT
|
|
|
|
|
|
|
|
|
|
# include "device/hiprt/queue.h"
|
|
|
|
|
|
|
|
|
|
# include "device/hip/graphics_interop.h"
|
|
|
|
|
# include "device/hip/kernel.h"
|
|
|
|
|
# include "device/hiprt/device_impl.h"
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
# include "kernel/device/hiprt/globals.h"
|
|
|
|
|
|
2023-04-24 19:05:30 +02:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
HIPRTDeviceQueue::HIPRTDeviceQueue(HIPRTDevice *device)
|
|
|
|
|
: HIPDeviceQueue((HIPDevice *)device), hiprt_device_(device)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HIPRTDeviceQueue::enqueue(DeviceKernel kernel,
|
|
|
|
|
const int work_size,
|
2024-12-29 17:32:00 +01:00
|
|
|
const DeviceKernelArguments &args)
|
2023-04-24 19:05:30 +02:00
|
|
|
{
|
|
|
|
|
if (hiprt_device_->have_error()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!device_kernel_has_intersection(kernel)) {
|
|
|
|
|
return HIPDeviceQueue::enqueue(kernel, work_size, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debug_enqueue_begin(kernel, work_size);
|
|
|
|
|
|
|
|
|
|
const HIPContextScope scope(hiprt_device_);
|
|
|
|
|
const HIPDeviceKernel &hip_kernel = hiprt_device_->kernels.get(kernel);
|
|
|
|
|
|
2024-09-24 14:35:24 +02:00
|
|
|
if (!hiprt_device_->global_stack_buffer.stackData) {
|
|
|
|
|
uint32_t max_path = num_concurrent_states(0);
|
|
|
|
|
hiprtGlobalStackBufferInput stack_buffer_input{
|
|
|
|
|
hiprtStackTypeGlobal, hiprtStackEntryTypeInteger, HIPRT_THREAD_STACK_SIZE, max_path};
|
|
|
|
|
|
|
|
|
|
hiprtError rt_result = hiprtCreateGlobalStackBuffer(hiprt_device_->get_hiprt_context(),
|
|
|
|
|
stack_buffer_input,
|
|
|
|
|
hiprt_device_->global_stack_buffer);
|
|
|
|
|
|
|
|
|
|
if (rt_result != hiprtSuccess) {
|
2025-07-10 19:44:14 +02:00
|
|
|
LOG_ERROR << "Failed to create hiprt Global Stack Buffer";
|
2024-09-24 14:35:24 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-04-24 19:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceKernelArguments args_copy = args;
|
2024-09-24 14:35:24 +02:00
|
|
|
args_copy.add(DeviceKernelArguments::HIPRT_GLOBAL_STACK,
|
|
|
|
|
(void *)(&hiprt_device_->global_stack_buffer),
|
|
|
|
|
sizeof(hiprtGlobalStackBuffer));
|
2023-04-24 19:05:30 +02:00
|
|
|
|
|
|
|
|
/* Compute kernel launch parameters. */
|
|
|
|
|
const int num_threads_per_block = HIPRT_THREAD_GROUP_SIZE;
|
|
|
|
|
const int num_blocks = divide_up(work_size, num_threads_per_block);
|
|
|
|
|
int shared_mem_bytes = 0;
|
|
|
|
|
|
|
|
|
|
assert_success(hipModuleLaunchKernel(hip_kernel.function,
|
|
|
|
|
num_blocks,
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
num_threads_per_block,
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
shared_mem_bytes,
|
|
|
|
|
hip_stream_,
|
|
|
|
|
const_cast<void **>(args_copy.values),
|
2024-12-26 17:53:59 +01:00
|
|
|
nullptr),
|
2023-04-24 19:05:30 +02:00
|
|
|
"enqueue");
|
|
|
|
|
|
2023-06-20 20:47:10 +02:00
|
|
|
debug_enqueue_end();
|
|
|
|
|
|
2023-04-24 19:05:30 +02:00
|
|
|
return !(hiprt_device_->have_error());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
#endif /* WITH_HIPRT */
|