From 1bb523111b839628c623f81a46eaae56d24dc3a9 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 14 Jun 2023 01:31:29 +0100 Subject: [PATCH] rusticl/api: Implement get_{device_and_}host_timer Use the get_timestamp as both the device_timestamp in get_device_and_host_timer and host_timestamp in that and get_host_timer. Having eliminited most other clock sources, discussions on previous versions have concluded it's best to use the same timer as the 'host_timestamp' since the main requirements are that it must be one that's a time seen by the device and that it's very closely coupled. Signed-off-by: Dr. David Alan Gilbert Part-of: --- src/gallium/frontends/rusticl/api/device.rs | 46 +++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/device.rs b/src/gallium/frontends/rusticl/api/device.rs index a7af6236dbe..993416267ab 100644 --- a/src/gallium/frontends/rusticl/api/device.rs +++ b/src/gallium/frontends/rusticl/api/device.rs @@ -378,18 +378,48 @@ fn release_device(_device: cl_device_id) -> CLResult<()> { #[cl_entrypoint] fn get_device_and_host_timer( - _device: cl_device_id, - _device_timestamp: *mut cl_ulong, - _host_timestamp: *mut cl_ulong, + device: cl_device_id, + device_timestamp: *mut cl_ulong, + host_timestamp: *mut cl_ulong, ) -> CLResult<()> { - // TODO: we could support it - Err(CL_INVALID_OPERATION) + if device_timestamp.is_null() { + // CL_INVALID_VALUE if host_timestamp or device_timestamp is NULL + return Err(CL_INVALID_VALUE); + } + + get_host_timer(device, host_timestamp)?; + // There is a requirement that the two timestamps + // are synchronised, but don't need to be the same, + // but as it is, the same timestamp is the best to + // use for both + + // Safe because null check on device_timestamp above + // and host_timestamp null check in get_host_timer + unsafe { + *device_timestamp = *host_timestamp; + }; + + Ok(()) } #[cl_entrypoint] -fn get_host_timer(_device: cl_device_id, _host_timestamp: *mut cl_ulong) -> CLResult<()> { - // TODO: we could support it - Err(CL_INVALID_OPERATION) +fn get_host_timer(device_id: cl_device_id, host_timestamp: *mut cl_ulong) -> CLResult<()> { + if host_timestamp.is_null() { + // CL_INVALID_VALUE if host_timestamp is NULL + return Err(CL_INVALID_VALUE); + } + + let device = device_id.get_ref()?; + + if !device.has_timestamp { + // CL_INVALID_OPERATION if the platform associated with device does not support device and host timer synchronization + return Err(CL_INVALID_OPERATION); + } + + // Currently the best clock we have for the host_timestamp + host_timestamp.write_checked(device.screen().get_timestamp()); + + Ok(()) } #[cl_entrypoint]