[docs]defcheck_installation(val:bool=False,verbose:bool=False):""" Quickly checks the installation works. :param val: checks that a couple of functions in submodule validation are working :param verbose: prints out which verifications is being processed """importdatetimedeflocal_print(msg):t=datetime.datetime.now().time()print(msg.replace("[check_installation]",f"[check_installation] {t}"))ifverbose:local_print("[check_installation] --begin")assertisinstance(get_cxx_flags(),str)ifval:ifverbose:local_print("[check_installation] --val")local_print("[check_installation] import numpy")importnumpyifverbose:local_print("[check_installation] import teachcompute")fromteachcompute.validation.cython.vector_function_cyimportvector_sum_cya=(((numpy.arange(9).astype(numpy.float32)-5)).astype(numpy.float32).reshape((3,-1)))c=vector_sum_cy(a)assertisinstance(c,float)assertc==-9ifverbose:local_print("[check_installation] cast_float32_to_e4m3fn")ifverbose:local_print("[check_installation] --done")
[docs]defhas_cuda()->bool:""" Tells if cuda is available. """from._configimportHAS_CUDAreturnHAS_CUDA==1
[docs]defcuda_version()->str:""" Tells which version of CUDA was used to build the CUDA extensions. """asserthas_cuda(),"CUDA extensions are not available."from._configimportCUDA_VERSIONreturnCUDA_VERSION
[docs]defcuda_version_int()->tuple:""" Tells which version of CUDA was used to build the CUDA extensions. It returns `(0, 0)` if CUDA is not present. """ifnothas_cuda():return(0,0)from._configimportCUDA_VERSIONifnotisinstance(CUDA_VERSION,str):returntuple()spl=CUDA_VERSION.split(".")returntuple(map(int,spl))
[docs]defcompiled_with_cuda()->bool:""" Checks it was compiled with CUDA. """try:from.validation.cudaimportcuda_example_pyreturncuda_example_pyisnotNoneexceptImportError:returnFalse