18 @brief Represents a future for retrieving the result of asynchronous inference.
20 This class provides a mechanism similar to C++11 std::future, allowing access to
21 the result of an asynchronous inference operation initiated via `Model.infer_async()`.
22 For details on C++11 std::future, refer to https://en.cppreference.com/w/cpp/thread/future.html .
24 The Future object enables the caller to:
25 - Wait for the inference to complete (`wait_for`)
26 - Block until completion and retrieve the output (`get`)
31 _future: Optional[Union[_cMaccel.FutureFloat, _cMaccel.FutureInt8]] =
None,
32 _inputs: Optional[List[np.ndarray]] =
None,
36 self.
_future = _future
if _future
is not None else _cMaccel.FutureFloat()
44 _future: Union[_cMaccel.FutureFloat, _cMaccel.FutureInt8],
45 _inputs: List[np.ndarray],
47 return cls(_future, _inputs)
51 @brief Waits for asynchronous inference to complete or until the timeout elapses.
53 @note This method is safe to call multiple times. Calling it with
54 a timeout of zero (i.e., `wait_for(0)`) performs a non-blocking
55 check to see whether asynchronous inference has already completed.
57 @param[in] timeout_ms Maximum duration to wait, in milliseconds.
59 @return True if inference completed before the timeout, false otherwise.
63 def get(self) -> List[np.ndarray]:
65 @brief Blocks until asynchronous inference completes and retrieves the output.
67 @note This method should be called only once per Future. If called again,
68 the return value will be invalid, and it will raise maccel.MAccelError
71 @return A list of numpy ndarray containing the inference output.
75 return [np.asarray(o)
for o
in outputs]