util.cuh 698 B

123456789101112131415161718192021222324252627282930313233
  1. // Adapted from turboderp exllama: https://github.com/turboderp/exllama
  2. #ifndef _util_cuh
  3. #define _util_cuh
  4. #include <cuda_runtime.h>
  5. #include <cuda_fp16.h>
  6. #include <cstdint>
  7. #include <cstdio>
  8. #if defined(USE_ROCM)
  9. #define cudaUnspecified hipErrorUnknown
  10. #else
  11. #define cudaUnspecified cudaErrorApiFailureBase
  12. #endif
  13. // React to failure on return code != cudaSuccess
  14. #define _cuda_check(fn) \
  15. do { \
  16. {_cuda_err = fn;} \
  17. if (_cuda_err != cudaSuccess) goto _cuda_fail; \
  18. } while(false)
  19. // React to failure on return code == 0
  20. #define _alloc_check(fn) \
  21. do { \
  22. if (!(fn)) { _cuda_err = cudaUnspecified; goto _cuda_fail; } \
  23. else _cuda_err = cudaSuccess; \
  24. } while(false)
  25. #endif