1fb810d93c
The whole path works end-to-end on real silicon (boltzmann, 7.0.0-rc3 rocket,
/dev/accel/accel0): our golden regcmd builder + rkt_operands tiling + librocket
submission -> a 4x8x16 INT8 matmul whose per-element output (incl requant +
int8 saturation) matches the CPU reference exactly (144,160,...,255).
ROOT CAUSE of the long all-zero saga: rocket_prep_bo()'s timeout_ns is an
ABSOLUTE CLOCK_MONOTONIC deadline (kernel drm_timeout_abs_to_jiffies), not a
relative duration. hwtest passed 3e9 ('3s') -> read as a deadline ~9h in the
past -> effective timeout 0 -> we read the output BO (memset 0) BEFORE the NPU
wrote it. The -EBUSY we dismissed WAS the 'not done' signal. Mesa passes
INT64_MAX (block until the DPU-write fence signals). Nothing was wrong with the
regcmd, operands, addresses, driver, or hardware -- diagnosed via the working
Mesa Teflon reference ('if tflite works it has the proper spells', per Markus;
divergence found by Fable/rknpu-specialist).
Fixes: hwtest prep_bo INT64_MAX; close all BO handles (kills drm_mm_takedown
WARN); librocket rocket_close_bo added + prep_bo doc corrected (abs deadline).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
88 lines
2.5 KiB
C
88 lines
2.5 KiB
C
/* SPDX-License-Identifier: MIT */
|
|
/*
|
|
* librocket — thin C wrapper over the Rockchip "rocket" NPU DRM-accel uAPI.
|
|
*
|
|
* This is pure syscall-surface plumbing. No NPU/tensor semantics, no register
|
|
* commands. Every function returns 0 on success or -errno on failure (except
|
|
* rocket_mmap_bo which returns the mmap'd pointer or MAP_FAILED).
|
|
*/
|
|
#ifndef LIBROCKET_H
|
|
#define LIBROCKET_H
|
|
|
|
#include "rocket_accel.h"
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* rocket_open - open a rocket NPU accel device
|
|
* @path: device node path (e.g. "/dev/accel/accel0")
|
|
*
|
|
* Returns the file descriptor on success, or -errno on failure.
|
|
*/
|
|
int rocket_open(const char *path);
|
|
|
|
/**
|
|
* rocket_create_bo - allocate a buffer object
|
|
* @fd: rocket device fd
|
|
* @size: desired BO size in bytes
|
|
* @handle_out: on success, written with the GEM handle
|
|
* @dma_address_out: on success, written with the NPU DMA address
|
|
* @mmap_offset_out: on success, written with the mmap offset
|
|
*
|
|
* Returns 0 on success, -errno on failure.
|
|
*/
|
|
int rocket_create_bo(int fd, uint32_t size, uint32_t *handle_out,
|
|
uint64_t *dma_address_out, uint64_t *mmap_offset_out);
|
|
|
|
/**
|
|
* rocket_mmap_bo - mmap a BO into userspace
|
|
* @fd: rocket device fd
|
|
* @mmap_offset: offset returned by rocket_create_bo
|
|
* @size: number of bytes to map
|
|
*
|
|
* Returns the mapped pointer, or MAP_FAILED on failure.
|
|
*/
|
|
void *rocket_mmap_bo(int fd, uint64_t mmap_offset, uint32_t size);
|
|
|
|
/**
|
|
* rocket_prep_bo - take CPU ownership of a BO (wait for NPU, sync caches)
|
|
* @fd: rocket device fd
|
|
* @handle: GEM handle of the BO
|
|
* @timeout_ns: ABSOLUTE CLOCK_MONOTONIC deadline (ns); INT64_MAX = block until signalled
|
|
*
|
|
* Returns 0 on success, -errno on failure.
|
|
*/
|
|
int rocket_prep_bo(int fd, uint32_t handle, int64_t timeout_ns);
|
|
|
|
/**
|
|
* rocket_fini_bo - hand a BO back to the device (sync caches)
|
|
* @fd: rocket device fd
|
|
* @handle: GEM handle of the BO
|
|
*
|
|
* Returns 0 on success, -errno on failure.
|
|
*/
|
|
int rocket_fini_bo(int fd, uint32_t handle);
|
|
|
|
/**
|
|
* rocket_submit - submit NPU jobs
|
|
* @fd: rocket device fd
|
|
* @jobs: pointer to an array of struct drm_rocket_job
|
|
* @job_count: number of jobs in the array
|
|
*
|
|
* Returns 0 on success, -errno on failure.
|
|
*/
|
|
int rocket_submit(int fd, struct drm_rocket_job *jobs, uint32_t job_count);
|
|
|
|
/* Release a BO handle (DRM_IOCTL_GEM_CLOSE). Returns 0 or -errno. */
|
|
int rocket_close_bo(int fd, uint32_t handle);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* LIBROCKET_H */
|