|
| 1 | +struct NNPACKError <: Exception |
| 2 | + code::nnp_status |
| 3 | + msg::AbstractString |
| 4 | +end |
| 5 | + |
| 6 | +Base.show(io::IO, err::NNPACKError) = print(io, "NNPACKError(code $(err.code), $(err.msg))") |
| 7 | + |
| 8 | +function NNPACKError(status::nnp_status) |
| 9 | + msg = "NNPACK STATUS SUCCESS" |
| 10 | + if status == nnp_status_invalid_batch_size |
| 11 | + msg = "NNPACK STATUS INVALID BATCH SIZE" |
| 12 | + elseif status == nnp_status_invalid_channels |
| 13 | + msg = "NNPACK STATUS INVALID CHANNELS" |
| 14 | + elseif status == nnp_status_invalid_input_channels |
| 15 | + msg = "NNPACK STATUS INVALID INPUT CHANNELS" |
| 16 | + elseif status == nnp_status_invalid_output_channels |
| 17 | + msg = "NNPACK STATUS INVALID OUTPUT CHANNELS" |
| 18 | + elseif status == nnp_status_invalid_input_size |
| 19 | + msg = "NNPACK STATUS INVALID INPUT SIZE" |
| 20 | + elseif status == nnp_status_invalid_input_stride |
| 21 | + msg = "NNPACK STATUS INVALID INPUT STRIDE" |
| 22 | + elseif status == nnp_status_invalid_input_padding |
| 23 | + msg = "NNPACK STATUS INVALID INPUT PADDING" |
| 24 | + elseif status == nnp_status_invalid_kernel_size |
| 25 | + msg = "NNPACK STATUS INVALID KERNEL SIZE" |
| 26 | + elseif status == nnp_status_invalid_pooling_size |
| 27 | + msg = "NNPACK STATUS INVALID POOLING SIZE" |
| 28 | + elseif status == nnp_status_invalid_pooling_stride |
| 29 | + msg = "NNPACK STATUS INVALID POOLING STRIDE" |
| 30 | + elseif status == nnp_status_invalid_algorithm |
| 31 | + msg = "NNPACK STATUS INVALID ALGORITHM" |
| 32 | + elseif status == nnp_status_invalid_transform_strategy |
| 33 | + msg = "NNPACK STATUS INVALID TRANSFORM STRATEGY" |
| 34 | + elseif status == nnp_status_invalid_output_subsampling |
| 35 | + msg = "NNPACK STATUS INVALID OUTPUT SUBSAMPLING" |
| 36 | + elseif status == nnp_status_invalid_activation |
| 37 | + msg = "NNPACK STATUS INVALID ACTIVATION" |
| 38 | + elseif status == nnp_status_invalid_activation_parameters |
| 39 | + msg = "NNPACK STATUS INVALID ACTIVATION PARAMETERS" |
| 40 | + elseif status == nnp_status_unsupported_input_size |
| 41 | + msg = "NNPACK STATUS UNSUPPORTED INPUT SIZE" |
| 42 | + elseif status == nnp_status_unsupported_input_stride |
| 43 | + msg = "NNPACK STATUS UNSUPPORTED INPUT STRIDE" |
| 44 | + elseif status == nnp_status_unsupported_input_padding |
| 45 | + msg = "NNPACK STATUS UNSUPPORTED INPUT PADDING" |
| 46 | + elseif status == nnp_status_unsupported_kernel_size |
| 47 | + msg = "NNPACK STATUS UNSUPPORTED KERNEL SIZE" |
| 48 | + elseif status == nnp_status_unsupported_pooling_size |
| 49 | + msg = "NNPACK STATUS UNSUPPORTED POOLING SIZE" |
| 50 | + elseif status == nnp_status_unsupported_pooling_stride |
| 51 | + msg = "NNPACK STATUS UNSUPPORTED POOLING STRIDE" |
| 52 | + elseif status == nnp_status_unsupported_algorithm |
| 53 | + msg = "NNPACK STATUS UNSUPPORTED ALGORITHM" |
| 54 | + elseif status == nnp_status_unsupported_transform_strategy |
| 55 | + msg = "NNPACK STATUS UNSUPPORTED TRANSFORM STRATEGY" |
| 56 | + elseif status == nnp_status_unsupported_activation |
| 57 | + msg = "NNPACK STATUS UNSUPPORTED ACTIVATION" |
| 58 | + elseif status == nnp_status_unsupported_activation_parameters |
| 59 | + msg = "NNPACK STATUS UNSUPPORTED ACTIVATION PARAMETERS" |
| 60 | + elseif status == nnp_status_uninitialized |
| 61 | + msg = "NNPACK STATUS UNINITIALIZED" |
| 62 | + elseif status == nnp_status_unsupported_hardware |
| 63 | + msg = "NNPACK STATUS UNSUPPORTED HARDWARE" |
| 64 | + elseif status == nnp_status_out_of_memory |
| 65 | + msg = "NNPACK STATUS OUT OF MEMORY" |
| 66 | + elseif status == nnp_status_insufficient_buffer |
| 67 | + msg = "NNPACK STATUS INSUFFICIENT BUFFER" |
| 68 | + elseif status == nnp_status_misaligned_buffer |
| 69 | + msg = "NNPACK STATUS MISALIGNED BUFFER" |
| 70 | + end |
| 71 | + NNPACKError(status, msg) |
| 72 | +end |
| 73 | + |
| 74 | +macro nnpack_check(nnp_func) |
| 75 | + quote |
| 76 | + local err::nnp_status |
| 77 | + err = $(esc(nnp_func)) |
| 78 | + if err != nnp_status_success |
| 79 | + throw(NNPACKError(err)) |
| 80 | + end |
| 81 | + err |
| 82 | + end |
| 83 | +end |
0 commit comments