# mypy: disable-error-code="empty-body" from __future__ import annotations import ctypes from typing import Literal, TypeAlias from tinygrad.runtime.support.c import _IO, _IOW, _IOR, _IOWR from tinygrad.runtime.support import c import sysconfig dll = c.DLL('nvrtc', 'nvrtc', [f'/{pre}/cuda/targets/{tgt}/lib' for pre in ['opt', 'usr/local'] for tgt in [sysconfig.get_config_vars().get("MULTIARCH", "").rsplit("-", 1)[0], 'sbsa-linux']]) nvrtcResult: dict[int, str] = {(NVRTC_SUCCESS:=0): 'NVRTC_SUCCESS', (NVRTC_ERROR_OUT_OF_MEMORY:=1): 'NVRTC_ERROR_OUT_OF_MEMORY', (NVRTC_ERROR_PROGRAM_CREATION_FAILURE:=2): 'NVRTC_ERROR_PROGRAM_CREATION_FAILURE', (NVRTC_ERROR_INVALID_INPUT:=3): 'NVRTC_ERROR_INVALID_INPUT', (NVRTC_ERROR_INVALID_PROGRAM:=4): 'NVRTC_ERROR_INVALID_PROGRAM', (NVRTC_ERROR_INVALID_OPTION:=5): 'NVRTC_ERROR_INVALID_OPTION', (NVRTC_ERROR_COMPILATION:=6): 'NVRTC_ERROR_COMPILATION', (NVRTC_ERROR_BUILTIN_OPERATION_FAILURE:=7): 'NVRTC_ERROR_BUILTIN_OPERATION_FAILURE', (NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION:=8): 'NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION', (NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION:=9): 'NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION', (NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID:=10): 'NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID', (NVRTC_ERROR_INTERNAL_ERROR:=11): 'NVRTC_ERROR_INTERNAL_ERROR'} @dll.bind(c.POINTER[ctypes.c_char], ctypes.c_uint32) def nvrtcGetErrorString(result:ctypes.c_uint32) -> c.POINTER[ctypes.c_char]: ... @dll.bind(ctypes.c_uint32, c.POINTER[ctypes.c_int32], c.POINTER[ctypes.c_int32]) def nvrtcVersion(major:c.POINTER[ctypes.c_int32], minor:c.POINTER[ctypes.c_int32]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, c.POINTER[ctypes.c_int32]) def nvrtcGetNumSupportedArchs(numArchs:c.POINTER[ctypes.c_int32]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, c.POINTER[ctypes.c_int32]) def nvrtcGetSupportedArchs(supportedArchs:c.POINTER[ctypes.c_int32]) -> ctypes.c_uint32: ... class struct__nvrtcProgram(c.Struct): pass nvrtcProgram: TypeAlias = c.POINTER[struct__nvrtcProgram] @dll.bind(ctypes.c_uint32, c.POINTER[nvrtcProgram], c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], ctypes.c_int32, c.POINTER[c.POINTER[ctypes.c_char]], c.POINTER[c.POINTER[ctypes.c_char]]) def nvrtcCreateProgram(prog:c.POINTER[nvrtcProgram], src:c.POINTER[ctypes.c_char], name:c.POINTER[ctypes.c_char], numHeaders:int, headers:c.POINTER[c.POINTER[ctypes.c_char]], includeNames:c.POINTER[c.POINTER[ctypes.c_char]]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, c.POINTER[nvrtcProgram]) def nvrtcDestroyProgram(prog:c.POINTER[nvrtcProgram]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, ctypes.c_int32, c.POINTER[c.POINTER[ctypes.c_char]]) def nvrtcCompileProgram(prog:nvrtcProgram, numOptions:int, options:c.POINTER[c.POINTER[ctypes.c_char]]) -> ctypes.c_uint32: ... size_t: TypeAlias = ctypes.c_uint64 @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[size_t]) def nvrtcGetPTXSize(prog:nvrtcProgram, ptxSizeRet:c.POINTER[size_t]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcGetPTX(prog:nvrtcProgram, ptx:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[size_t]) def nvrtcGetCUBINSize(prog:nvrtcProgram, cubinSizeRet:c.POINTER[size_t]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcGetCUBIN(prog:nvrtcProgram, cubin:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[size_t]) def nvrtcGetNVVMSize(prog:nvrtcProgram, nvvmSizeRet:c.POINTER[size_t]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcGetNVVM(prog:nvrtcProgram, nvvm:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[size_t]) def nvrtcGetLTOIRSize(prog:nvrtcProgram, LTOIRSizeRet:c.POINTER[size_t]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcGetLTOIR(prog:nvrtcProgram, LTOIR:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[size_t]) def nvrtcGetOptiXIRSize(prog:nvrtcProgram, optixirSizeRet:c.POINTER[size_t]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcGetOptiXIR(prog:nvrtcProgram, optixir:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[size_t]) def nvrtcGetProgramLogSize(prog:nvrtcProgram, logSizeRet:c.POINTER[size_t]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcGetProgramLog(prog:nvrtcProgram, log:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char]) def nvrtcAddNameExpression(prog:nvrtcProgram, name_expression:c.POINTER[ctypes.c_char]) -> ctypes.c_uint32: ... @dll.bind(ctypes.c_uint32, nvrtcProgram, c.POINTER[ctypes.c_char], c.POINTER[c.POINTER[ctypes.c_char]]) def nvrtcGetLoweredName(prog:nvrtcProgram, name_expression:c.POINTER[ctypes.c_char], lowered_name:c.POINTER[c.POINTER[ctypes.c_char]]) -> ctypes.c_uint32: ... __DEPRECATED__ = lambda msg: __attribute__((deprecated(msg))) # type: ignore