Skip to content

Commit

Permalink
Add generic at-check and check
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsamaroo committed Feb 23, 2023
1 parent 92ec74d commit bc3cc37
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 35 deletions.
14 changes: 6 additions & 8 deletions src/blas/error.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export ROCBLASError

import .AMDGPU: @check, check

struct ROCBLASError <: Exception
code::rocblas_status_t
msg::AbstractString
Expand Down Expand Up @@ -31,13 +33,9 @@ function status_message(status)
end
end

macro check(blas_func)
quote
local err::rocblas_status_t
err = $(esc(blas_func::Expr))
if err != ROCBLAS_STATUS_SUCCESS
throw(ROCBLASError(err))
end
err
function check(status::rocblas_status_t)
if status != ROCBLAS_STATUS_SUCCESS
throw(ROCBLASError(status))
end
return status
end
15 changes: 6 additions & 9 deletions src/fft/error.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export ROCFFTError

import .AMDGPU: @check, check

struct ROCFFTError <: Exception
code::rocfft_status
msg::AbstractString
Expand Down Expand Up @@ -33,14 +35,9 @@ function status_message(status)
end
end


macro check(fft_func)
quote
local err::rocfft_status
err = $(esc(fft_func::Expr))
if err != rocfft_status_success
throw(ROCFFTError(err))
end
err
function check(status::rocfft_status)
if status != rocfft_status_success
throw(ROCFFTError(status))
end
return status
end
11 changes: 2 additions & 9 deletions src/hip/error.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export HIPError

import .AMDGPU: @check, check

struct HIPError <: Exception
code::hipError_t
msg::AbstractString
Expand Down Expand Up @@ -147,12 +149,3 @@ function check(err::hipError_t)
throw(HIPError(err))
end
end

macro check(hip_func)
quote
local err::hipError_t
err = $(esc(hip_func::Expr))
$check(err)
err
end
end
15 changes: 6 additions & 9 deletions src/rand/error.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export ROCRANDError

import .AMDGPU: @check, check

struct ROCRANDError <: Exception
code::rocrand_status
msg::AbstractString
Expand Down Expand Up @@ -37,14 +39,9 @@ function status_message(status)
end
end


macro check(rand_func)
quote
local err::rocrand_status
err = $(esc(rand_func::Expr))
if err != ROCRAND_STATUS_SUCCESS
throw(ROCRANDError(err))
end
err
function check(status::rocrand_status)
if status != ROCRAND_STATUS_SUCCESS
throw(ROCRANDError(status))
end
return status
end
9 changes: 9 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,12 @@ function getinfo(::Type{T}, object, query)::T where T
end

function check end

macro check(f)
quote
local err
err = $(esc(f::Expr))
$check(err)
err
end
end

0 comments on commit bc3cc37

Please sign in to comment.