text:
function status_string(status::Status, status_string::Ref{Cstring})
    ccall((:hsa_status_string, "libhsa-runtime64"), Status, (Status, Ref{Cstring}), status, status_string)
end

function init()
    ccall((:hsa_init, "libhsa-runtime64"), Status, ())
end

function shut_down()
    ccall((:hsa_shut_down, "libhsa-runtime64"), Status, ())
end

function system_get_info(attribute::SystemInfo, value::Ref{Cvoid})
    ccall((:hsa_system_get_info, "libhsa-runtime64"), Status, (SystemInfo, Ref{Cvoid}), attribute, value)
end

function extension_get_name(extension::UInt16, name::String)
    ccall((:hsa_extension_get_name, "libhsa-runtime64"), Status, (UInt16, Cstring), extension, name)
end

function system_extension_supported(extension::UInt16, version_major::UInt16, version_minor::UInt16, result::Ref{Bool})
    ccall((:hsa_system_extension_supported, "libhsa-runtime64"), Status, (UInt16, UInt16, UInt16, Ref{Bool}), extension, version_major, version_minor, result)
end

function system_major_extension_supported(extension::UInt16, version_major::UInt16, version_minor::Ref{UInt16}, result::Ref{Bool})
    ccall((:hsa_system_major_extension_supported, "libhsa-runtime64"), Status, (UInt16, UInt16, Ref{UInt16}, Ref{Bool}), extension, version_major, version_minor, result)
end

function system_get_extension_table(extension::UInt16, version_major::UInt16, version_minor::UInt16, table::Ref{Cvoid})
    ccall((:hsa_system_get_extension_table, "libhsa-runtime64"), Status, (UInt16, UInt16, UInt16, Ref{Cvoid}), extension, version_major, version_minor, table)
end

function system_get_major_extension_table(extension::UInt16, version_major::UInt16, table_length::Integer, table::Ref{Cvoid})
    ccall((:hsa_system_get_major_extension_table, "libhsa-runtime64"), Status, (UInt16, UInt16, Csize_t, Ref{Cvoid}), extension, version_major, table_length, table)
end

function agent_get_info(agent::Agent, attribute::AgentInfo,
                        value::Union{Ref{T},Vector{T}}) where T
    ccall((:hsa_agent_get_info, "libhsa-runtime64"), Status,
          (Agent, AgentInfo, Ref{T}), agent, attribute, value)
end

function agent_get_info(agent::Agent, attribute::AgentInfo, value::String)
    ccall((:hsa_agent_get_info, "libhsa-runtime64"), Status,
          (Agent, AgentInfo, Cstring), agent, attribute, value)
end

#FIXME: function iterate_agents(callback::Ref{Cvoid}, data::Ref{Cvoid})
function iterate_agents(callback, data)
    ccall((:hsa_iterate_agents, "libhsa-runtime64"), Status, (Ptr{Cvoid}, Ptr{Cvoid}), callback, data)
end

function agent_get_exception_policies(agent::Agent, profile::Profile, mask::Ref{UInt16})
    ccall((:hsa_agent_get_exception_policies, "libhsa-runtime64"), Status, (Agent, Profile, Ref{UInt16}), agent, profile, mask)
end

function cache_get_info(cache::Cache, attribute::CacheInfo, value::Ref{Cvoid})
    ccall((:hsa_cache_get_info, "libhsa-runtime64"), Status, (Cache, CacheInfo, Ref{Cvoid}), cache, attribute, value)
end

function agent_iterate_caches(agent::Agent, callback::Ref{Cvoid}, data::Ref{Cvoid})
    ccall((:hsa_agent_iterate_caches, "libhsa-runtime64"), Status, (Agent, Ref{Cvoid}, Ref{Cvoid}), agent, callback, data)
end

function agent_extension_supported(extension::UInt16, agent::Agent, version_major::UInt16, version_minor::UInt16, result::Ref{Bool})
    ccall((:hsa_agent_extension_supported, "libhsa-runtime64"), Status, (UInt16, Agent, UInt16, UInt16, Ref{Bool}), extension, agent, version_major, version_minor, result)
end

function agent_major_extension_supported(extension::UInt16, agent::Agent, version_major::UInt16, version_minor::Ref{UInt16}, result::Ref{Bool})
    ccall((:hsa_agent_major_extension_supported, "libhsa-runtime64"), Status, (UInt16, Agent, UInt16, Ref{UInt16}, Ref{Bool}), extension, agent, version_major, version_minor, result)
end

function signal_create(initial_value::SignalValue, num_consumers::Integer,
                       consumers::Ref{Agent}, signal::Ref{Signal})
    ccall((:hsa_signal_create, "libhsa-runtime64"), Status,
          (SignalValue, UInt32, Ref{Agent}, Ref{Signal}),
          initial_value, num_consumers, consumers, signal)
end

function signal_create(initial_value::SignalValue, num_consumers::Integer,
                       consumers::Ptr{Cvoid}, signal::Ref{Signal})
    ccall((:hsa_signal_create, "libhsa-runtime64"), Status,
          (SignalValue, UInt32, Ptr{Cvoid}, Ref{Signal}),
          initial_value, num_consumers, consumers, signal)
end

function signal_destroy(signal::Signal)
    ccall((:hsa_signal_destroy, "libhsa-runtime64"), Status, (Signal,), signal)
end

function signal_load_scacquire(signal::Signal)
    ccall((:hsa_signal_load_scacquire, "libhsa-runtime64"), SignalValue, (Signal,), signal)
end

function signal_load_relaxed(signal::Signal)
    ccall((:hsa_signal_load_relaxed, "libhsa-runtime64"), SignalValue, (Signal,), signal)
end

function signal_load_acquire(signal::Signal)
    ccall((:hsa_signal_load_acquire, "libhsa-runtime64"), SignalValue, (Signal,), signal)
end

function signal_store_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_store_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_store_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_store_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_store_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_store_release, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_silent_store_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_silent_store_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_silent_store_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_silent_store_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_exchange_scacq_screl(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_scacq_screl, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_exchange_acq_rel(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_acq_rel, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_exchange_scacquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_scacquire, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_exchange_acquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_acquire, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_exchange_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_relaxed, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_exchange_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_screlease, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_exchange_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_exchange_release, "libhsa-runtime64"), SignalValue, (Signal, SignalValue), signal, value)
end

function signal_cas_scacq_screl(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_scacq_screl, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_cas_acq_rel(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_acq_rel, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_cas_scacquire(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_scacquire, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_cas_acquire(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_acquire, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_cas_relaxed(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_relaxed, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_cas_screlease(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_screlease, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_cas_release(signal::Signal, expected::SignalValue, value::SignalValue)
    ccall((:hsa_signal_cas_release, "libhsa-runtime64"), SignalValue, (Signal, SignalValue, SignalValue), signal, expected, value)
end

function signal_add_scacq_screl(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_scacq_screl, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_add_acq_rel(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_acq_rel, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_add_scacquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_scacquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_add_acquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_acquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_add_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_add_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_add_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_add_release, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_scacq_screl(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_scacq_screl, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_acq_rel(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_acq_rel, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_scacquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_scacquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_acquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_acquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_subtract_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_subtract_release, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_scacq_screl(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_scacq_screl, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_acq_rel(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_acq_rel, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_scacquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_scacquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_acquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_acquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_and_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_and_release, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_scacq_screl(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_scacq_screl, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_acq_rel(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_acq_rel, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_scacquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_scacquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_acquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_acquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_or_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_or_release, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_scacq_screl(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_scacq_screl, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_acq_rel(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_acq_rel, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_scacquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_scacquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_acquire(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_acquire, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_relaxed(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_relaxed, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_screlease(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_screlease, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_xor_release(signal::Signal, value::SignalValue)
    ccall((:hsa_signal_xor_release, "libhsa-runtime64"), Cvoid, (Signal, SignalValue), signal, value)
end

function signal_wait_scacquire(signal::Signal, condition::SignalCondition, compare_value::SignalValue, timeout_hint::UInt64, wait_state_hint::WaitState)
    ccall((:hsa_signal_wait_scacquire, "libhsa-runtime64"), SignalValue, (Signal, SignalCondition, SignalValue, UInt64, WaitState), signal, condition, compare_value, timeout_hint, wait_state_hint)
end

function signal_wait_relaxed(signal::Signal, condition::SignalCondition, compare_value::SignalValue, timeout_hint::UInt64, wait_state_hint::WaitState)
    ccall((:hsa_signal_wait_relaxed, "libhsa-runtime64"), SignalValue, (Signal, SignalCondition, SignalValue, UInt64, WaitState), signal, condition, compare_value, timeout_hint, wait_state_hint)
end

function signal_wait_acquire(signal::Signal, condition::SignalCondition, compare_value::SignalValue, timeout_hint::UInt64, wait_state_hint::WaitState)
    ccall((:hsa_signal_wait_acquire, "libhsa-runtime64"), SignalValue, (Signal, SignalCondition, SignalValue, UInt64, WaitState), signal, condition, compare_value, timeout_hint, wait_state_hint)
end

function signal_group_create(num_signals::Integer, signals::Ref{Signal}, num_consumers::Integer, consumers::Ref{Agent}, signal_group::Ref{SignalGroup})
    ccall((:hsa_signal_group_create, "libhsa-runtime64"), Status, (UInt32, Ref{Signal}, UInt32, Ref{Agent}, Ref{SignalGroup}), num_signals, signals, num_consumers, consumers, signal_group)
end

function signal_group_destroy(signal_group::SignalGroup)
    ccall((:hsa_signal_group_destroy, "libhsa-runtime64"), Status, (SignalGroup,), signal_group)
end

function signal_group_wait_any_scacquire(signal_group::SignalGroup, conditions::Ref{SignalCondition}, compare_values::Ref{SignalValue}, wait_state_hint::WaitState, signal::Ref{Signal}, value::Ref{SignalValue})
    ccall((:hsa_signal_group_wait_any_scacquire, "libhsa-runtime64"), Status, (SignalGroup, Ref{SignalCondition}, Ref{SignalValue}, WaitState, Ref{Signal}, Ref{SignalValue}), signal_group, conditions, compare_values, wait_state_hint, signal, value)
end

function signal_group_wait_any_relaxed(signal_group::SignalGroup, conditions::Ref{SignalCondition}, compare_values::Ref{SignalValue}, wait_state_hint::WaitState, signal::Ref{Signal}, value::Ref{SignalValue})
    ccall((:hsa_signal_group_wait_any_relaxed, "libhsa-runtime64"), Status, (SignalGroup, Ref{SignalCondition}, Ref{SignalValue}, WaitState, Ref{Signal}, Ref{SignalValue}), signal_group, conditions, compare_values, wait_state_hint, signal, value)
end

function queue_create(agent::Agent, size::Integer, type::QueueType, callback::Ptr{Cvoid}, data::Ptr{Cvoid}, private_segment_size::Integer, group_segment_size::Integer, queue::Ref{Ptr{Queue}})
    ccall((:hsa_queue_create, "libhsa-runtime64"), Status, (Agent, UInt32, QueueType, Ptr{Cvoid}, Ptr{Cvoid}, UInt32, UInt32, Ref{Ptr{Queue}}), agent, size, type, callback, data, private_segment_size, group_segment_size, queue)
end

function soft_queue_create(region::Region, size::Integer, type::QueueType, features::Integer, doorbell_signal::Signal, queue::Ref{Ref{Queue}})
    ccall((:hsa_soft_queue_create, "libhsa-runtime64"), Status, (Region, UInt32, QueueType, UInt32, Signal, Ref{Ref{Queue}}), region, size, type, features, doorbell_signal, queue)
end

function queue_destroy(queue::Ref{Queue})
    ccall((:hsa_queue_destroy, "libhsa-runtime64"), Status, (Ref{Queue},), queue)
end

function queue_inactivate(queue::Ref{Queue})
    ccall((:hsa_queue_inactivate, "libhsa-runtime64"), Status, (Ref{Queue},), queue)
end

function queue_load_read_index_acquire(queue::Ref{Queue})
    ccall((:hsa_queue_load_read_index_acquire, "libhsa-runtime64"), UInt64, (Ref{Queue},), queue)
end

function queue_load_read_index_scacquire(queue::Ref{Queue})
    ccall((:hsa_queue_load_read_index_scacquire, "libhsa-runtime64"), UInt64, (Ref{Queue},), queue)
end

function queue_load_read_index_relaxed(queue::Ref{Queue})
    ccall((:hsa_queue_load_read_index_relaxed, "libhsa-runtime64"), UInt64, (Ref{Queue},), queue)
end

function queue_load_write_index_acquire(queue::Ref{Queue})
    ccall((:hsa_queue_load_write_index_acquire, "libhsa-runtime64"), UInt64, (Ref{Queue},), queue)
end

function queue_load_write_index_scacquire(queue::Ref{Queue})
    ccall((:hsa_queue_load_write_index_scacquire, "libhsa-runtime64"), UInt64, (Ref{Queue},), queue)
end

function queue_load_write_index_relaxed(queue::Ref{Queue})
    ccall((:hsa_queue_load_write_index_relaxed, "libhsa-runtime64"), UInt64, (Ref{Queue},), queue)
end

function queue_store_write_index_relaxed(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_store_write_index_relaxed, "libhsa-runtime64"), Cvoid, (Ref{Queue}, UInt64), queue, value)
end

function queue_store_write_index_release(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_store_write_index_release, "libhsa-runtime64"), Cvoid, (Ref{Queue}, UInt64), queue, value)
end

function queue_store_write_index_screlease(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_store_write_index_screlease, "libhsa-runtime64"), Cvoid, (Ref{Queue}, UInt64), queue, value)
end

function queue_cas_write_index_acq_rel(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_acq_rel, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_cas_write_index_scacq_screl(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_scacq_screl, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_cas_write_index_acquire(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_acquire, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_cas_write_index_scacquire(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_scacquire, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_cas_write_index_relaxed(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_relaxed, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_cas_write_index_release(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_release, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_cas_write_index_screlease(queue::Ref{Queue}, expected::UInt64, value::UInt64)
    ccall((:hsa_queue_cas_write_index_screlease, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64, UInt64), queue, expected, value)
end

function queue_add_write_index_acq_rel(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_acq_rel, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_add_write_index_scacq_screl(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_scacq_screl, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_add_write_index_acquire(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_acquire, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_add_write_index_scacquire(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_scacquire, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_add_write_index_relaxed(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_relaxed, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_add_write_index_release(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_release, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_add_write_index_screlease(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_add_write_index_screlease, "libhsa-runtime64"), UInt64, (Ref{Queue}, UInt64), queue, value)
end

function queue_store_read_index_relaxed(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_store_read_index_relaxed, "libhsa-runtime64"), Cvoid, (Ref{Queue}, UInt64), queue, value)
end

function queue_store_read_index_release(queue::Ref{Queue}, value::UInt64)
    ccall((:hsa_queue_store_read_index_release, "libhsa-runtime64"), Cvoid, (Ref{Queue}, UInt64), queue, value)
end

function queue_store_read_index_screlease(queue::Ref{Queue}, value::Integer)
    ccall((:hsa_queue_store_read_index_screlease, "libhsa-runtime64"), Cvoid, (Ref{Queue}, UInt64), queue, value)
end

function region_get_info(region::Region, attribute::RegionInfo, value::Ref{T}) where T
    ccall((:hsa_region_get_info, "libhsa-runtime64"), Status, (Region, RegionInfo, Ref{T}), region, attribute, value)
end

function agent_iterate_regions(agent::Agent, callback::Ref{Cvoid}, data::Ref{T}) where T
    ccall((:hsa_agent_iterate_regions, "libhsa-runtime64"), Status, (Agent, Ref{Cvoid}, Ref{T}), agent, callback, data)
end

function memory_allocate(region::Region, size::Integer, ptr::Ref{Ptr{T}}) where T
    ccall((:hsa_memory_allocate, "libhsa-runtime64"), Status, (Region, Csize_t, Ref{Ptr{T}}), region, size, ptr)
end

function memory_free(ptr::Ptr{T}) where T
    ccall((:hsa_memory_free, "libhsa-runtime64"), Status, (Ptr{T},), ptr)
end

function memory_copy(dst::Ptr{T}, src::Ptr{T}, size::Integer) where T
    ccall((:hsa_memory_copy, "libhsa-runtime64"), Status, (Ptr{T}, Ptr{T}, Csize_t), dst, src, size)
end

function memory_assign_agent(ptr::Ref{Cvoid}, agent::Agent, access::AccessPermission)
    ccall((:hsa_memory_assign_agent, "libhsa-runtime64"), Status, (Ref{Cvoid}, Agent, AccessPermission), ptr, agent, access)
end

function memory_register(ptr::Ref{Cvoid}, size::Integer)
    ccall((:hsa_memory_register, "libhsa-runtime64"), Status, (Ref{Cvoid}, Csize_t), ptr, size)
end

function memory_deregister(ptr::Ref{Cvoid}, size::Integer)
    ccall((:hsa_memory_deregister, "libhsa-runtime64"), Status, (Ref{Cvoid}, Csize_t), ptr, size)
end

function isa_from_name(name, isa::Ref{ISA})
    ccall((:hsa_isa_from_name, "libhsa-runtime64"), Status, (Cstring, Ref{ISA}), name, isa)
end

function agent_iterate_isas(agent::Agent, callback::Ref{Cvoid}, data::Ref{ISA})
    ccall((:hsa_agent_iterate_isas, "libhsa-runtime64"), Status, (Agent, Ptr{Cvoid}, Ptr{Cvoid}), agent, callback, data)
end

function isa_get_info(isa::ISA, attribute::ISAInfo, index::Integer, value::Ref{Cvoid})
    ccall((:hsa_isa_get_info, "libhsa-runtime64"), Status, (ISA, ISAInfo, UInt32, Ref{Cvoid}), isa, attribute, index, value)
end

function isa_get_info_alt(isa::ISA, attribute::ISAInfo,
                          value::Union{Vector{T},Ref{T}}) where T
    ccall((:hsa_isa_get_info_alt, "libhsa-runtime64"), Status,
          (ISA, ISAInfo, Ref{T}), isa, attribute, value)
end

function isa_get_info_alt(isa::ISA, attribute::ISAInfo, value::String)
    ccall((:hsa_isa_get_info_alt, "libhsa-runtime64"), Status,
          (ISA, ISAInfo, Cstring), isa, attribute, value)
end

function isa_get_exception_policies(isa::ISA, profile::Profile, mask::Ref{UInt16})
    ccall((:hsa_isa_get_exception_policies, "libhsa-runtime64"), Status, (ISA, Profile, Ref{UInt16}), isa, profile, mask)
end

function isa_get_round_method(isa::ISA, fp_type::FPType, flush_mode::FlushMode, round_method::Ref{RoundMethod})
    ccall((:hsa_isa_get_round_method, "libhsa-runtime64"), Status, (ISA, FPType, FlushMode, Ref{RoundMethod}), isa, fp_type, flush_mode, round_method)
end

function wavefront_get_info(wavefront::Wavefront, attribute::WavefrontInfo, value::Ref{Cvoid})
    ccall((:hsa_wavefront_get_info, "libhsa-runtime64"), Status, (Wavefront, WavefrontInfo, Ref{Cvoid}), wavefront, attribute, value)
end

function isa_iterate_wavefronts(isa::ISA, callback::Ref{Cvoid}, data::Ref{Cvoid})
    ccall((:hsa_isa_iterate_wavefronts, "libhsa-runtime64"), Status, (ISA, Ref{Cvoid}, Ref{Cvoid}), isa, callback, data)
end

function isa_compatible(code_object_isa::ISA, agent_isa::ISA, result::Ref{Bool})
    ccall((:hsa_isa_compatible, "libhsa-runtime64"), Status, (ISA, ISA, Ref{Bool}), code_object_isa, agent_isa, result)
end

function code_object_reader_create_from_file(file::File, code_object_reader::Ref{CodeObjectReader})
    ccall((:hsa_code_object_reader_create_from_file, "libhsa-runtime64"), Status, (File, Ref{CodeObjectReader}), file, code_object_reader)
end

function code_object_reader_create_from_memory(code_object::Union{Vector{UInt8},Ref{UInt8}}, size::Integer, code_object_reader::Ref{CodeObjectReader})
    ccall((:hsa_code_object_reader_create_from_memory, "libhsa-runtime64"), Status, (Ref{UInt8}, Csize_t, Ref{CodeObjectReader}), code_object, size, code_object_reader)
end

function code_object_reader_destroy(code_object_reader::CodeObjectReader)
    ccall((:hsa_code_object_reader_destroy, "libhsa-runtime64"), Status, (CodeObjectReader,), code_object_reader)
end

function executable_create(profile::Profile, executable_state::ExecutableState, options, executable::Ref{Executable})
    ccall((:hsa_executable_create, "libhsa-runtime64"), Status, (Profile, ExecutableState, Cstring, Ref{Executable}), profile, executable_state, options, executable)
end

function executable_create_alt(profile::Profile, default_float_rounding_mode::DefaultFloatRoundingMode, options, executable::Ref{Executable})
    ccall((:hsa_executable_create_alt, "libhsa-runtime64"), Status, (Profile, DefaultFloatRoundingMode, Cstring, Ref{Executable}), profile, default_float_rounding_mode, options, executable)
end

function executable_destroy(executable::Executable)
    ccall((:hsa_executable_destroy, "libhsa-runtime64"), Status, (Executable,), executable)
end

function executable_load_program_code_object(executable::Executable, code_object_reader::CodeObjectReader, options, loaded_code_object::Ref{LoadedCodeObject})
    ccall((:hsa_executable_load_program_code_object, "libhsa-runtime64"), Status, (Executable, CodeObjectReader, Cstring, Ref{LoadedCodeObject}), executable, code_object_reader, options, loaded_code_object)
end

function executable_load_agent_code_object(executable::Executable, agent::Agent, code_object_reader::CodeObjectReader, options, loaded_code_object::Ref{LoadedCodeObject})
    ccall((:hsa_executable_load_agent_code_object, "libhsa-runtime64"), Status, (Executable, Agent, CodeObjectReader, Cstring, Ref{LoadedCodeObject}), executable, agent, code_object_reader, options, loaded_code_object)
end
# FIXME: temporary dispatch while sorting out calls to this function
function executable_load_agent_code_object(executable::Executable, agent::Agent, code_object_reader::CodeObjectReader, options, loaded_code_object)
    ccall((:hsa_executable_load_agent_code_object, "libhsa-runtime64"), Status, (Executable, Agent, CodeObjectReader, Ptr{Cvoid}, Ptr{Cvoid}), executable, agent, code_object_reader, options, loaded_code_object)
end

function executable_freeze(executable::Executable, options)
    ccall((:hsa_executable_freeze, "libhsa-runtime64"), Status, (Executable, Cstring), executable, options)
end

function executable_get_info(executable::Executable, attribute::ExecutableInfo, value::Ref{Cvoid})
    ccall((:hsa_executable_get_info, "libhsa-runtime64"), Status, (Executable, ExecutableInfo, Ref{Cvoid}), executable, attribute, value)
end

function executable_global_variable_define(executable::Executable, variable_name, address::Ref{Cvoid})
    ccall((:hsa_executable_global_variable_define, "libhsa-runtime64"), Status, (Executable, Cstring, Ref{Cvoid}), executable, variable_name, address)
end

function executable_agent_global_variable_define(executable::Executable, agent::Agent, variable_name, address::Ref{Cvoid})
    ccall((:hsa_executable_agent_global_variable_define, "libhsa-runtime64"), Status, (Executable, Agent, Cstring, Ref{Cvoid}), executable, agent, variable_name, address)
end

function executable_readonly_variable_define(executable::Executable, agent::Agent, variable_name, address::Ref{Cvoid})
    ccall((:hsa_executable_readonly_variable_define, "libhsa-runtime64"), Status, (Executable, Agent, Cstring, Ref{Cvoid}), executable, agent, variable_name, address)
end

function executable_validate(executable::Executable, result::Ref{UInt32})
    ccall((:hsa_executable_validate, "libhsa-runtime64"), Status, (Executable, Ref{UInt32}), executable, result)
end

function executable_validate_alt(executable::Executable, options, result::Ref{UInt32})
    ccall((:hsa_executable_validate_alt, "libhsa-runtime64"), Status, (Executable, Cstring, Ref{UInt32}), executable, options, result)
end

function executable_get_symbol(executable::Executable, module_name, symbol_name, agent::Agent, call_conventionInteger, symbol::Ref{ExecutableSymbol})
    ccall((:hsa_executable_get_symbol, "libhsa-runtime64"), Status, (Executable, Cstring, Cstring, Agent, Int32, Ref{ExecutableSymbol}), executable, module_name, symbol_name, agent, call_convention, symbol)
end

function executable_get_symbol_by_name(executable::Executable, symbol_name, agent::Ref{Agent}, symbol::Ref{ExecutableSymbol})
    ccall((:hsa_executable_get_symbol_by_name, "libhsa-runtime64"), Status, (Executable, Cstring, Ref{Agent}, Ref{ExecutableSymbol}), executable, symbol_name, agent, symbol)
end

function executable_symbol_get_info(executable_symbol::ExecutableSymbol,
                                    attribute::ExecutableSymbolInfo,
                                    value::Union{Ref{T},Vector{T}}) where T
    ccall((:hsa_executable_symbol_get_info, "libhsa-runtime64"), Status,
          (ExecutableSymbol, ExecutableSymbolInfo, Ref{T}),
          executable_symbol, attribute, value)
end

function executable_symbol_get_info(executable_symbol::ExecutableSymbol,
                                    attribute::ExecutableSymbolInfo,
                                    value::String)
    ccall((:hsa_executable_symbol_get_info, "libhsa-runtime64"), Status,
          (ExecutableSymbol, ExecutableSymbolInfo, Cstring),
          executable_symbol, attribute, value)
end

function executable_iterate_symbols(executable::Executable, callback::Ref{Cvoid}, data::Ref{Cvoid})
    ccall((:hsa_executable_iterate_symbols, "libhsa-runtime64"), Status, (Executable, Ref{Cvoid}, Ref{Cvoid}), executable, callback, data)
end

function executable_iterate_agent_symbols(executable::Executable, agent::Agent, callback::Ptr{Cvoid}, data::Ref{Cvoid})
    ccall((:hsa_executable_iterate_agent_symbols, "libhsa-runtime64"), Status, (Executable, Agent, Ptr{Cvoid}, Ref{Cvoid}), executable, agent, callback, data)
end

function executable_iterate_program_symbols(executable::Executable, callback::Ptr{Cvoid}, data::Ptr{Cvoid})
    ccall((:hsa_executable_iterate_program_symbols, "libhsa-runtime64"), Status, (Executable, Ptr{Cvoid}, Ptr{Cvoid}), executable, callback, data)
end

function code_object_serialize(code_object::CodeObject, alloc_callback::Ref{Cvoid}, callback_data::CallbackData, options, serialized_code_object::Ref{Ref{Cvoid}}, serialized_code_object_size::Ref{Csize_t})
    ccall((:hsa_code_object_serialize, "libhsa-runtime64"), Status, (CodeObject, Ref{Cvoid}, CallbackData, Cstring, Ref{Ref{Cvoid}}, Ref{Csize_t}), code_object, alloc_callback, callback_data, options, serialized_code_object, serialized_code_object_size)
end

function code_object_deserialize(serialized_code_object::Ref{Cvoid}, serialized_code_object_size::Integer, options, code_object::Ref{CodeObject})
    ccall((:hsa_code_object_deserialize, "libhsa-runtime64"), Status, (Ref{Cvoid}, Csize_t, Cstring, Ref{CodeObject}), serialized_code_object, serialized_code_object_size, options, code_object)
end

function code_object_destroy(code_object::CodeObject)
    ccall((:hsa_code_object_destroy, "libhsa-runtime64"), Status, (CodeObject,), code_object)
end

function code_object_get_info(code_object::CodeObject, attribute::CodeObjectInfo, value::Ref{Cvoid})
    ccall((:hsa_code_object_get_info, "libhsa-runtime64"), Status, (CodeObject, CodeObjectInfo, Ref{Cvoid}), code_object, attribute, value)
end

function executable_load_code_object(executable::Executable, agent::Agent, code_object::CodeObject, options)
    ccall((:hsa_executable_load_code_object, "libhsa-runtime64"), Status, (Executable, Agent, CodeObject, Cstring), executable, agent, code_object, options)
end

function code_object_get_symbol(code_object::CodeObject, symbol_name, symbol::Ref{CodeSymbol})
    ccall((:hsa_code_object_get_symbol, "libhsa-runtime64"), Status, (CodeObject, Cstring, Ref{CodeSymbol}), code_object, symbol_name, symbol)
end

function code_object_get_symbol_from_name(code_object::CodeObject, module_name, symbol_name, symbol::Ref{CodeSymbol})
    ccall((:hsa_code_object_get_symbol_from_name, "libhsa-runtime64"), Status, (CodeObject, Cstring, Cstring, Ref{CodeSymbol}), code_object, module_name, symbol_name, symbol)
end

function code_symbol_get_info(code_symbol::CodeSymbol, attribute::CodeSymbolInfo, value::Ref{Cvoid})
    ccall((:hsa_code_symbol_get_info, "libhsa-runtime64"), Status, (CodeSymbol, CodeSymbolInfo, Ref{Cvoid}), code_symbol, attribute, value)
end

function code_object_iterate_symbols(code_object::CodeObject, callback::Ptr{Cvoid}, data::Ptr{Cvoid})
    ccall((:hsa_code_object_iterate_symbols, "libhsa-runtime64"), Status, (CodeObject, Ptr{Cvoid}, Ptr{Cvoid}), code_object, callback, data)
end

function amd_queue_intercept_register(queue::Ref{Queue}, callback::QueueInterceptHandler, user_data::Ref{Cvoid})
    ccall((:hsa_amd_queue_intercept_register, "libhsa-runtime64"), Status, (Ref{Queue}, QueueInterceptHandler, Ref{Cvoid}), queue, callback, user_data)
end

function amd_queue_intercept_create(agent_handle::Agent, size::Integer, type::QueueType, callback::Ref{Cvoid}, data::Ref{Cvoid}, private_segment_size::Integer, group_segment_size::Integer, queue::Ref{Ref{Queue}})
    ccall((:hsa_amd_queue_intercept_create, "libhsa-runtime64"), Status, (Agent, UInt32, QueueType, Ref{Cvoid}, Ref{Cvoid}, UInt32, UInt32, Ref{Ref{Queue}}), agent_handle, size, type, callback, data, private_segment_size, group_segment_size, queue)
end

function amd_runtime_queue_create_register(callback::RuntimeQueueNotifier, user_data::Ref{Cvoid})
    ccall((:hsa_amd_runtime_queue_create_register, "libhsa-runtime64"), Status, (RuntimeQueueNotifier, Ref{Cvoid}), callback, user_data)
end
#=
function copyApi(src::Ref{Cvoid}, dest::Ref{Cvoid}, size::Integer)
    ccall((:copyApi, "libhsa-runtime64"), Cvoid, (Ref{Cvoid}, Ref{Cvoid}, Csize_t), src, dest, size)
end

function copyElement(dest::Ref{ApiTableVersion}, src::Ref{ApiTableVersion})
    ccall((:copyElement, "libhsa-runtime64"), Cvoid, (Ref{ApiTableVersion}, Ref{ApiTableVersion}), dest, src)
end

function copyTables(src::Ref{HsaApiTable}, dest::Ref{HsaApiTable})
    ccall((:copyTables, "libhsa-runtime64"), Cvoid, (Ref{HsaApiTable}, Ref{HsaApiTable}), src, dest)
end
=#
function ext_image_get_capability(agent::Agent, geometry::ImageGeometry, image_format::Ref{ImageFormat}, capability_mask::Ref{UInt32})
    ccall((:hsa_ext_image_get_capability, "libhsa-runtime64"), Status, (Agent, ImageGeometry, Ref{ImageFormat}, Ref{UInt32}), agent, geometry, image_format, capability_mask)
end

function ext_image_get_capability_with_layout(agent::Agent, geometry::ImageGeometry, image_format::Ref{ImageFormat}, image_data_layout::ImageDataLayout, capability_mask::Ref{UInt32})
    ccall((:hsa_ext_image_get_capability_with_layout, "libhsa-runtime64"), Status, (Agent, ImageGeometry, Ref{ImageFormat}, ImageDataLayout, Ref{UInt32}), agent, geometry, image_format, image_data_layout, capability_mask)
end

function ext_image_data_get_info(agent::Agent, image_descriptor::Ref{ExtImageDescriptor}, access_permission::AccessPermission, image_data_info::Ref{ImageDataInfo})
    ccall((:hsa_ext_image_data_get_info, "libhsa-runtime64"), Status, (Agent, Ref{ExtImageDescriptor}, AccessPermission, Ref{ImageDataInfo}), agent, image_descriptor, access_permission, image_data_info)
end

function ext_image_data_get_info_with_layout(agent::Agent, image_descriptor::Ref{ExtImageDescriptor}, access_permission::AccessPermission, image_data_layout::ImageDataLayout, image_data_row_pitch::Integer, image_data_slice_pitch::Integer, image_data_info::Ref{ImageDataInfo})
    ccall((:hsa_ext_image_data_get_info_with_layout, "libhsa-runtime64"), Status, (Agent, Ref{ExtImageDescriptor}, AccessPermission, ImageDataLayout, Csize_t, Csize_t, Ref{ImageDataInfo}), agent, image_descriptor, access_permission, image_data_layout, image_data_row_pitch, image_data_slice_pitch, image_data_info)
end

function ext_image_create(agent::Agent, image_descriptor::Ref{ExtImageDescriptor}, image_data::Ref{Cvoid}, access_permission::AccessPermission, image::Ref{Image})
    ccall((:hsa_ext_image_create, "libhsa-runtime64"), Status, (Agent, Ref{ExtImageDescriptor}, Ref{Cvoid}, AccessPermission, Ref{Image}), agent, image_descriptor, image_data, access_permission, image)
end

function ext_image_create_with_layout(agent::Agent, image_descriptor::Ref{ExtImageDescriptor}, image_data::Ref{Cvoid}, access_permission::AccessPermission, image_data_layout::ImageDataLayout, image_data_row_pitch::Integer, image_data_slice_pitch::Integer, image::Ref{Image})
    ccall((:hsa_ext_image_create_with_layout, "libhsa-runtime64"), Status, (Agent, Ref{ExtImageDescriptor}, Ref{Cvoid}, AccessPermission, ImageDataLayout, Csize_t, Csize_t, Ref{Image}), agent, image_descriptor, image_data, access_permission, image_data_layout, image_data_row_pitch, image_data_slice_pitch, image)
end

function ext_image_destroy(agent::Agent, image::Image)
    ccall((:hsa_ext_image_destroy, "libhsa-runtime64"), Status, (Agent, Image), agent, image)
end

function ext_image_copy(agent::Agent, src_image::Image, src_offset::Ref{Dim3}, dst_image::Image, dst_offset::Ref{Dim3}, range::Ref{Dim3})
    ccall((:hsa_ext_image_copy, "libhsa-runtime64"), Status, (Agent, Image, Ref{Dim3}, Image, Ref{Dim3}, Ref{Dim3}), agent, src_image, src_offset, dst_image, dst_offset, range)
end

function ext_image_import(agent::Agent, src_memory::Ref{Cvoid}, src_row_pitch::Integer, src_slice_pitch::Integer, dst_image::Image, image_region::Ref{ImageRegion})
    ccall((:hsa_ext_image_import, "libhsa-runtime64"), Status, (Agent, Ref{Cvoid}, Csize_t, Csize_t, Image, Ref{ImageRegion}), agent, src_memory, src_row_pitch, src_slice_pitch, dst_image, image_region)
end

function ext_image_export(agent::Agent, src_image::Image, dst_memory::Ref{Cvoid}, dst_row_pitch::Integer, dst_slice_pitch::Integer, image_region::Ref{ImageRegion})
    ccall((:hsa_ext_image_export, "libhsa-runtime64"), Status, (Agent, Image, Ref{Cvoid}, Csize_t, Csize_t, Ref{ImageRegion}), agent, src_image, dst_memory, dst_row_pitch, dst_slice_pitch, image_region)
end

function ext_image_clear(agent::Agent, image::Image, data::Ref{Cvoid}, image_region::Ref{ImageRegion})
    ccall((:hsa_ext_image_clear, "libhsa-runtime64"), Status, (Agent, Image, Ref{Cvoid}, Ref{ImageRegion}), agent, image, data, image_region)
end

function ext_sampler_create(agent::Agent, sampler_descriptor::Ref{ExtSamplerDescriptor}, sampler::Ref{Sampler})
    ccall((:hsa_ext_sampler_create, "libhsa-runtime64"), Status, (Agent, Ref{ExtSamplerDescriptor}, Ref{Sampler}), agent, sampler_descriptor, sampler)
end

function ext_sampler_destroy(agent::Agent, sampler::Sampler)
    ccall((:hsa_ext_sampler_destroy, "libhsa-runtime64"), Status, (Agent, Sampler), agent, sampler)
end

function amd_coherency_get_type(agent::Agent, type::Ref{CoherencyType})
    ccall((:hsa_amd_coherency_get_type, "libhsa-runtime64"), Status, (Agent, Ref{CoherencyType}), agent, type)
end

function amd_coherency_set_type(agent::Agent, type::CoherencyType)
    ccall((:hsa_amd_coherency_set_type, "libhsa-runtime64"), Status, (Agent, CoherencyType), agent, type)
end

function amd_profiling_set_profiler_enabled(queue::Ref{Queue}, enable::Cint)
    ccall((:hsa_amd_profiling_set_profiler_enabled, "libhsa-runtime64"), Status, (Ref{Queue}, Cint), queue, enable)
end

function amd_profiling_async_copy_enable(enable::Bool)
    ccall((:hsa_amd_profiling_async_copy_enable, "libhsa-runtime64"), Status, (Bool,), enable)
end

function amd_profiling_get_dispatch_time(agent::Agent, signal::Signal, time::Ref{ProfilingDispatchTime})
    ccall((:hsa_amd_profiling_get_dispatch_time, "libhsa-runtime64"), Status, (Agent, Signal, Ref{ProfilingDispatchTime}), agent, signal, time)
end

function amd_profiling_get_async_copy_time(signal::Signal, time::Ref{ProfilingAsyncCopyTime})
    ccall((:hsa_amd_profiling_get_async_copy_time, "libhsa-runtime64"), Status, (Signal, Ref{ProfilingAsyncCopyTime}), signal, time)
end

function amd_profiling_convert_tick_to_system_domain(agent::Agent, agent_tick::UInt64, system_tick::Ref{UInt64})
    ccall((:hsa_amd_profiling_convert_tick_to_system_domain, "libhsa-runtime64"), Status, (Agent, UInt64, Ref{UInt64}), agent, agent_tick, system_tick)
end

function amd_signal_create(initial_value::SignalValue, num_consumers::Integer, consumers::Ref{Agent}, attributes::UInt64, signal::Ref{Signal})
    ccall((:hsa_amd_signal_create, "libhsa-runtime64"), Status, (SignalValue, UInt32, Ref{Agent}, UInt64, Ref{Signal}), initial_value, num_consumers, consumers, attributes, signal)
end

function amd_signal_async_handler(signal::Signal, cond::SignalCondition, value::SignalValue, handler::SignalHandler, arg::Ref{Cvoid})
    ccall((:hsa_amd_signal_async_handler, "libhsa-runtime64"), Status, (Signal, SignalCondition, SignalValue, SignalHandler, Ref{Cvoid}), signal, cond, value, handler, arg)
end

function amd_async_function(callback::Ref{Cvoid}, arg::Ref{Cvoid})
    ccall((:hsa_amd_async_function, "libhsa-runtime64"), Status, (Ref{Cvoid}, Ref{Cvoid}), callback, arg)
end

function amd_signal_wait_any(signal_count::Integer, signals::Ref{Signal}, conds::Ref{SignalCondition}, values::Ref{SignalValue}, timeout_hint::UInt64, wait_hint::WaitState, satisfying_value::Ref{SignalValue})
    ccall((:hsa_amd_signal_wait_any, "libhsa-runtime64"), UInt32, (UInt32, Ref{Signal}, Ref{SignalCondition}, Ref{SignalValue}, UInt64, WaitState, Ref{SignalValue}), signal_count, signals, conds, values, timeout_hint, wait_hint, satisfying_value)
end

function amd_image_get_info_max_dim(agent::Agent, attribute::AgentInfo, value::Ref{Cvoid})
    ccall((:hsa_amd_image_get_info_max_dim, "libhsa-runtime64"), Status, (Agent, AgentInfo, Ref{Cvoid}), agent, attribute, value)
end

function amd_queue_cu_set_mask(queue::Ref{Queue}, num_cu_mask_count::Integer, cu_mask::Ref{UInt32})
    ccall((:hsa_amd_queue_cu_set_mask, "libhsa-runtime64"), Status, (Ref{Queue}, UInt32, Ref{UInt32}), queue, num_cu_mask_count, cu_mask)
end

function amd_memory_pool_get_info(memory_pool::MemoryPool, attribute::MemoryPoolInfo, value::Ref{Cvoid})
    ccall((:hsa_amd_memory_pool_get_info, "libhsa-runtime64"), Status, (MemoryPool, MemoryPoolInfo, Ref{Cvoid}), memory_pool, attribute, value)
end

function amd_agent_iterate_memory_pools(agent::Agent, callback::Ptr{Cvoid}, data::Ptr{Cvoid})
    ccall((:hsa_amd_agent_iterate_memory_pools, "libhsa-runtime64"), Status, (Agent, Ptr{Cvoid}, Ptr{Cvoid}), agent, callback, data)
end

function amd_memory_pool_allocate(memory_pool::MemoryPool, size::Integer, flags::Integer, ptr::Ref{Ref{Cvoid}})
    ccall((:hsa_amd_memory_pool_allocate, "libhsa-runtime64"), Status, (MemoryPool, Csize_t, UInt32, Ref{Ref{Cvoid}}), memory_pool, size, flags, ptr)
end

function amd_memory_pool_free(ptr::Ref{Cvoid})
    ccall((:hsa_amd_memory_pool_free, "libhsa-runtime64"), Status, (Ref{Cvoid},), ptr)
end

function amd_memory_async_copy(dst::Ref{Cvoid}, dst_agent::Agent, src::Ref{Cvoid}, src_agent::Agent, size::Integer, num_dep_signals::Integer, dep_signals::Ref{Signal}, completion_signal::Signal)
    ccall((:hsa_amd_memory_async_copy, "libhsa-runtime64"), Status, (Ref{Cvoid}, Agent, Ref{Cvoid}, Agent, Csize_t, UInt32, Ref{Signal}, Signal), dst, dst_agent, src, src_agent, size, num_dep_signals, dep_signals, completion_signal)
end

function amd_memory_async_copy_rect(dst::Ref{PitchedPtr}, dst_offset::Ref{Dim3}, src::Ref{PitchedPtr}, src_offset::Ref{Dim3}, range::Ref{Dim3}, copy_agent::Agent, dir::CopyDirection, num_dep_signals::Integer, dep_signals::Ref{Signal}, completion_signal::Signal)
    ccall((:hsa_amd_memory_async_copy_rect, "libhsa-runtime64"), Status, (Ref{PitchedPtr}, Ref{Dim3}, Ref{PitchedPtr}, Ref{Dim3}, Ref{Dim3}, Agent, CopyDirection, UInt32, Ref{Signal}, Signal), dst, dst_offset, src, src_offset, range, copy_agent, dir, num_dep_signals, dep_signals, completion_signal)
end

function amd_agent_memory_pool_get_info(agent::Agent, memory_pool::MemoryPool, attribute::AgentMemoryPoolInfo, value::Ref{Cvoid})
    ccall((:hsa_amd_agent_memory_pool_get_info, "libhsa-runtime64"), Status, (Agent, MemoryPool, AgentMemoryPoolInfo, Ref{Cvoid}), agent, memory_pool, attribute, value)
end

function amd_agents_allow_access(num_agents::Integer, agents::Ref{Agent}, flags::Ref{UInt32}, ptr::Ref{Cvoid})
    ccall((:hsa_amd_agents_allow_access, "libhsa-runtime64"), Status, (UInt32, Ref{Agent}, Ref{UInt32}, Ref{Cvoid}), num_agents, agents, flags, ptr)
end

function amd_memory_pool_can_migrate(src_memory_pool::MemoryPool, dst_memory_pool::MemoryPool, result::Ref{Bool})
    ccall((:hsa_amd_memory_pool_can_migrate, "libhsa-runtime64"), Status, (MemoryPool, MemoryPool, Ref{Bool}), src_memory_pool, dst_memory_pool, result)
end

function amd_memory_migrate(ptr::Ref{Cvoid}, memory_pool::MemoryPool, flags::Integer)
    ccall((:hsa_amd_memory_migrate, "libhsa-runtime64"), Status, (Ref{Cvoid}, MemoryPool, UInt32), ptr, memory_pool, flags)
end

function amd_memory_lock(host_ptr::Ptr{Cvoid}, size::Integer, agents::Ref{Agent}, num_agent::Integer, agent_ptr::Ref{Ptr{Cvoid}})
    ccall((:hsa_amd_memory_lock, "libhsa-runtime64"), Status, (Ptr{Cvoid}, Csize_t, Ref{Agent}, Cint, Ref{Ptr{Cvoid}}), host_ptr, size, agents, num_agent, agent_ptr)
end

function amd_memory_lock_to_pool(host_ptr::Ref{Cvoid}, size::Integer, agents::Ref{Agent}, num_agent::Cint, pool::MemoryPool, flags::Integer, agent_ptr::Ref{Ref{Cvoid}})
    ccall((:hsa_amd_memory_lock_to_pool, "libhsa-runtime64"), Status, (Ref{Cvoid}, Csize_t, Ref{Agent}, Cint, MemoryPool, UInt32, Ref{Ref{Cvoid}}), host_ptr, size, agents, num_agent, pool, flags, agent_ptr)
end

function amd_memory_unlock(host_ptr::Ptr{Cvoid})
    ccall((:hsa_amd_memory_unlock, "libhsa-runtime64"), Status, (Ptr{Cvoid},), host_ptr)
end

function amd_memory_fill(ptr::Ptr{Cvoid}, value::UInt32, count::Integer)
    ccall((:hsa_amd_memory_fill, "libhsa-runtime64"), Status, (Ptr{Cvoid}, UInt32, Csize_t), ptr, value, count)
end

function amd_interop_map_buffer(num_agents::Integer, agents::Ref{Agent}, interop_handle::Cint, flags::Integer, size::Ref{Csize_t}, ptr::Ref{Ref{Cvoid}}, metadata_size::Ref{Csize_t}, metadata::Ref{Ref{Cvoid}})
    ccall((:hsa_amd_interop_map_buffer, "libhsa-runtime64"), Status, (UInt32, Ref{Agent}, Cint, UInt32, Ref{Csize_t}, Ref{Ref{Cvoid}}, Ref{Csize_t}, Ref{Ref{Cvoid}}), num_agents, agents, interop_handle, flags, size, ptr, metadata_size, metadata)
end

function amd_interop_unmap_buffer(ptr::Ref{Cvoid})
    ccall((:hsa_amd_interop_unmap_buffer, "libhsa-runtime64"), Status, (Ref{Cvoid},), ptr)
end

function amd_image_create(agent::Agent, image_descriptor::Ref{ExtImageDescriptor}, image_layout::Ref{AMDImageDescriptor}, image_data::Ref{Cvoid}, access_permission::AccessPermission, image::Ref{Image})
    ccall((:hsa_amd_image_create, "libhsa-runtime64"), Status, (Agent, Ref{ExtImageDescriptor}, Ref{AMDImageDescriptor}, Ref{Cvoid}, AccessPermission, Ref{Image}), agent, image_descriptor, image_layout, image_data, access_permission, image)
end

function amd_pointer_info(ptr::Ptr{Cvoid}, info::Ref{PointerInfo}, alloc::Ptr{Cvoid}, num_agents_accessible::Ptr{UInt32}, accessible)
    ccall((:hsa_amd_pointer_info, "libhsa-runtime64"), Status, (Ptr{Cvoid}, Ref{PointerInfo}, Ptr{Cvoid}, Ptr{UInt32}, Ptr{Cvoid}), ptr, info, alloc, num_agents_accessible, accessible)
end

function amd_pointer_info_set_userdata(ptr::Ref{Cvoid}, userdata::Ref{Cvoid})
    ccall((:hsa_amd_pointer_info_set_userdata, "libhsa-runtime64"), Status, (Ref{Cvoid}, Ref{Cvoid}), ptr, userdata)
end

function amd_ipc_memory_create(ptr::Ref{Cvoid}, len::Integer, handle::Ref{IPCMemory})
    ccall((:hsa_amd_ipc_memory_create, "libhsa-runtime64"), Status, (Ref{Cvoid}, Csize_t, Ref{IPCMemory}), ptr, len, handle)
end

function amd_ipc_memory_attach(handle::Ref{IPCMemory}, len::Integer, num_agents::Integer, mapping_agents::Ref{Agent}, mapped_ptr::Ref{Ref{Cvoid}})
    ccall((:hsa_amd_ipc_memory_attach, "libhsa-runtime64"), Status, (Ref{IPCMemory}, Csize_t, UInt32, Ref{Agent}, Ref{Ref{Cvoid}}), handle, len, num_agents, mapping_agents, mapped_ptr)
end

function amd_ipc_memory_detach(mapped_ptr::Ref{Cvoid})
    ccall((:hsa_amd_ipc_memory_detach, "libhsa-runtime64"), Status, (Ref{Cvoid},), mapped_ptr)
end

function amd_ipc_signal_create(signal::Signal, handle::Ref{IPCSignal})
    ccall((:hsa_amd_ipc_signal_create, "libhsa-runtime64"), Status, (Signal, Ref{IPCSignal}), signal, handle)
end

function amd_ipc_signal_attach(handle::Ref{IPCSignal}, signal::Ref{Signal})
    ccall((:hsa_amd_ipc_signal_attach, "libhsa-runtime64"), Status, (Ref{IPCSignal}, Ref{Signal}), handle, signal)
end

function amd_register_system_event_handler(callback::SystemEventCallback, data::Ref{Cvoid})
    ccall((:hsa_amd_register_system_event_handler, "libhsa-runtime64"), Status, (SystemEventCallback, Ref{Cvoid}), callback, data)
end

function amd_queue_set_priority(queue::Ref{Queue}, priority::QueuePriority)
    ccall((:hsa_amd_queue_set_priority, "libhsa-runtime64"), Status, (Ref{Queue}, QueuePriority), queue, priority)
end

function amd_register_deallocation_callback(ptr::Ref{Cvoid}, callback::DeallocationCallback, user_data::Ref{Cvoid})
    ccall((:hsa_amd_register_deallocation_callback, "libhsa-runtime64"), Status, (Ref{Cvoid}, DeallocationCallback, Ref{Cvoid}), ptr, callback, user_data)
end

function amd_deregister_deallocation_callback(ptr::Ref{Cvoid}, callback::DeallocationCallback)
    ccall((:hsa_amd_deregister_deallocation_callback, "libhsa-runtime64"), Status, (Ref{Cvoid}, DeallocationCallback), ptr, callback)
end

function ext_tools_set_correlation_handler(agent::Agent, correlation_handle::Ref{Cvoid})
    ccall((:hsa_ext_tools_set_correlation_handler, "libhsa-runtime64"), Status, (Agent, Ref{Cvoid}), agent, correlation_handle)
end

function ext_tools_wave_control(agent::Agent, action::WaveAction, mode::WaveMode, trap_id::Integer, msg_ptr::Ref{Cvoid})
    ccall((:hsa_ext_tools_wave_control, "libhsa-runtime64"), Status, (Agent, WaveAction, WaveMode, UInt32, Ref{Cvoid}), agent, action, mode, trap_id, msg_ptr)
end

#=
function ext_tools_flush_cache(agent::Agent, options::CacheFlushOptions)
    ccall((:hsa_ext_tools_flush_cache, "libhsa-runtime64"), Status, (Agent, CacheFlushOptions), agent, options)
end
=#

function ext_tools_install_trap(agent::Agent, type::TrapType, trap_handler::Ref{Cvoid}, trap_buffer::Ref{Cvoid}, trap_handler_size::Integer, trap_buffer_size::Integer)
    ccall((:hsa_ext_tools_install_trap, "libhsa-runtime64"), Status, (Agent, TrapType, Ref{Cvoid}, Ref{Cvoid}, Csize_t, Csize_t), agent, type, trap_handler, trap_buffer, trap_handler_size, trap_buffer_size)
end

function ext_tools_set_exception_policy(agent::Agent, exception_policy::ExceptionPolicy)
    ccall((:hsa_ext_tools_set_exception_policy, "libhsa-runtime64"), Status, (Agent, ExceptionPolicy), agent, exception_policy)
end

function ext_tools_get_exception_policy(agent::Agent, exception_policy::Ref{ExceptionPolicy})
    ccall((:hsa_ext_tools_get_exception_policy, "libhsa-runtime64"), Status, (Agent, Ref{ExceptionPolicy}), agent, exception_policy)
end

function ext_tools_set_kernel_execution_mode(agent::Agent, mode::KernelExecutionMode)
    ccall((:hsa_ext_tools_set_kernel_execution_mode, "libhsa-runtime64"), Status, (Agent, KernelExecutionMode), agent, mode)
end

function ext_tools_get_kernel_execution_mode(agent::Agent, mode::Ref{KernelExecutionMode})
    ccall((:hsa_ext_tools_get_kernel_execution_mode, "libhsa-runtime64"), Status, (Agent, Ref{KernelExecutionMode}), agent, mode)
end

function ext_tools_register(agent::Agent)
    ccall((:hsa_ext_tools_register, "libhsa-runtime64"), Status, (Agent,), agent)
end

function ext_tools_unregister(agent::Agent)
    ccall((:hsa_ext_tools_unregister, "libhsa-runtime64"), Status, (Agent,), agent)
end

function ext_tools_address_watch(agent::Agent, num_watch_points::Integer, mode::Ref{AddressWatchMode}, watch_address::Ref{Ref{Cvoid}}, watch_mask::Ref{UInt64}, watch_event::Ref{ToolsEvent})
    ccall((:hsa_ext_tools_address_watch, "libhsa-runtime64"), Status, (Agent, UInt32, Ref{AddressWatchMode}, Ref{Ref{Cvoid}}, Ref{UInt64}, Ref{ToolsEvent}), agent, num_watch_points, mode, watch_address, watch_mask, watch_event)
end

function ext_tools_get_dispatch_debug_info(agent::Agent, info::Ref{DispatchDebugInfo})
    ccall((:hsa_ext_tools_get_dispatch_debug_info, "libhsa-runtime64"), Status, (Agent, Ref{DispatchDebugInfo}), agent, info)
end

function ext_tools_dmacopy(agent::Agent, src_addr::Ref{UInt32}, dst_addr::Ref{UInt32}, size::Integer)
    ccall((:hsa_ext_tools_dmacopy, "libhsa-runtime64"), Status, (Agent, Ref{UInt32}, Ref{UInt32}, UInt32), agent, src_addr, dst_addr, size)
end

function ext_tools_create_event(agent::Agent, auto_reset::Bool, event::Ref{ToolsEvent}, event_id::Ref{UInt32})
    ccall((:hsa_ext_tools_create_event, "libhsa-runtime64"), Status, (Agent, Bool, Ref{ToolsEvent}, Ref{UInt32}), agent, auto_reset, event, event_id)
end

function ext_tools_wait_event(timeoutInteger, event::ToolsEvent)
    ccall((:hsa_ext_tools_wait_event, "libhsa-runtime64"), EventWaitStatus, (Int32, ToolsEvent), timeout, event)
end

function ext_tools_destroy_event(event::ToolsEvent)
    ccall((:hsa_ext_tools_destroy_event, "libhsa-runtime64"), Status, (ToolsEvent,), event)
end

function ext_program_create(machine_model::MachineModel, profile::Profile, default_float_rounding_mode::DefaultFloatRoundingMode, options, program::Ref{ExtProgram})
    ccall((:hsa_ext_program_create, "libhsa-runtime64"), Status, (MachineModel, Profile, DefaultFloatRoundingMode, Cstring, Ref{ExtProgram}), machine_model, profile, default_float_rounding_mode, options, program)
end

function ext_program_destroy(program::ExtProgram)
    ccall((:hsa_ext_program_destroy, "libhsa-runtime64"), Status, (ExtProgram,), program)
end

function ext_program_add_module(program::ExtProgram, _module::ExtModule)
    ccall((:hsa_ext_program_add_module, "libhsa-runtime64"), Status, (ExtProgram, ExtModule), program, _module)
end

function ext_program_iterate_modules(program::ExtProgram, callback::Ptr{Cvoid}, data::Ptr{Cvoid})
    ccall((:hsa_ext_program_iterate_modules, "libhsa-runtime64"), Status, (ExtProgram, Ptr{Cvoid}, Ptr{Cvoid}), program, callback, data)
end

function ext_program_get_info(program::ExtProgram, attribute::ProgramInfo, value::Ref{Cvoid})
    ccall((:hsa_ext_program_get_info, "libhsa-runtime64"), Status, (ExtProgram, ProgramInfo, Ref{Cvoid}), program, attribute, value)
end

function ext_program_finalize(program::ExtProgram, isa::ISA, call_conventionInteger, control_directives::ExtControlDirectives, options, code_object_type::CodeObjectType, code_object::Ref{CodeObject})
    ccall((:hsa_ext_program_finalize, "libhsa-runtime64"), Status, (ExtProgram, ISA, Int32, ExtControlDirectives, Cstring, CodeObjectType, Ref{CodeObject}), program, isa, call_convention, control_directives, options, code_object_type, code_object)
end

function ven_amd_aqlprofile_version_major()
    ccall((:hsa_ven_amd_aqlprofile_version_major, "libhsa-runtime64"), UInt32, ())
end

function ven_amd_aqlprofile_version_minor()
    ccall((:hsa_ven_amd_aqlprofile_version_minor, "libhsa-runtime64"), UInt32, ())
end

function ven_amd_aqlprofile_validate_event(agent::Agent, event::Ref{AQLProfileEvent}, result::Ref{Bool})
    ccall((:hsa_ven_amd_aqlprofile_validate_event, "libhsa-runtime64"), Status, (Agent, Ref{AQLProfileEvent}, Ref{Bool}), agent, event, result)
end

function ven_amd_aqlprofile_start(profile::Ref{AQLProfile}, aql_start_packet::Ref{AQLPm4Packet})
    ccall((:hsa_ven_amd_aqlprofile_start, "libhsa-runtime64"), Status, (Ref{AQLProfile}, Ref{AQLPm4Packet}), profile, aql_start_packet)
end

function ven_amd_aqlprofile_stop(profile::Ref{AQLProfile}, aql_stop_packet::Ref{AQLPm4Packet})
    ccall((:hsa_ven_amd_aqlprofile_stop, "libhsa-runtime64"), Status, (Ref{AQLProfile}, Ref{AQLPm4Packet}), profile, aql_stop_packet)
end

function ven_amd_aqlprofile_read(profile::Ref{AQLProfile}, aql_read_packet::Ref{AQLPm4Packet})
    ccall((:hsa_ven_amd_aqlprofile_read, "libhsa-runtime64"), Status, (Ref{AQLProfile}, Ref{AQLPm4Packet}), profile, aql_read_packet)
end

function ven_amd_aqlprofile_legacy_get_pm4(aql_packet::Ref{AQLPm4Packet}, data::Ref{Cvoid})
    ccall((:hsa_ven_amd_aqlprofile_legacy_get_pm4, "libhsa-runtime64"), Status, (Ref{AQLPm4Packet}, Ref{Cvoid}), aql_packet, data)
end

function ven_amd_aqlprofile_get_info(profile::Ref{AQLProfile}, attribute::AQLProfileInfoType, value::Ref{Cvoid})
    ccall((:hsa_ven_amd_aqlprofile_get_info, "libhsa-runtime64"), Status, (Ref{AQLProfile}, AQLProfileInfoType, Ref{Cvoid}), profile, attribute, value)
end

function ven_amd_aqlprofile_iterate_data(profile::Ref{AQLProfile}, callback::AQLProfileDataCallback, data::Ptr{Cvoid})
    ccall((:hsa_ven_amd_aqlprofile_iterate_data, "libhsa-runtime64"), Status, (Ref{AQLProfile}, AQLProfileDataCallback, Ptr{Cvoid}), profile, callback, data)
end

function ven_amd_aqlprofile_error_string(str::Ref{Cstring})
    ccall((:hsa_ven_amd_aqlprofile_error_string, "libhsa-runtime64"), Status, (Ref{Cstring},), str)
end

function ven_amd_loader_query_host_address(device_address::Ref{Cvoid}, host_address::Ref{Ref{Cvoid}})
    ccall((:hsa_ven_amd_loader_query_host_address, "libhsa-runtime64"), Status, (Ref{Cvoid}, Ref{Ref{Cvoid}}), device_address, host_address)
end

function ven_amd_loader_query_segment_descriptors(segment_descriptors::Ref{SegmentDescriptor}, num_segment_descriptors::Ref{Csize_t})
    ccall((:hsa_ven_amd_loader_query_segment_descriptors, "libhsa-runtime64"), Status, (Ref{SegmentDescriptor}, Ref{Csize_t}), segment_descriptors, num_segment_descriptors)
end

function ven_amd_loader_query_executable(device_address::Ref{Cvoid}, executable::Ref{Executable})
    ccall((:hsa_ven_amd_loader_query_executable, "libhsa-runtime64"), Status, (Ref{Cvoid}, Ref{Executable}), device_address, executable)
end

function ven_amd_loader_executable_iterate_loaded_code_objects(executable::Executable, callback::Ref{Cvoid}, data::Ref{Cvoid})
    ccall((:hsa_ven_amd_loader_executable_iterate_loaded_code_objects, "libhsa-runtime64"), Status, (Executable, Ref{Cvoid}, Ref{Cvoid}), executable, callback, data)
end

function ven_amd_loader_loaded_code_object_get_info(loaded_code_object::LoadedCodeObject, attribute::LoadedCodeObjectInfo, value::Ref{Cvoid})
    ccall((:hsa_ven_amd_loader_loaded_code_object_get_info, "libhsa-runtime64"), Status, (LoadedCodeObject, LoadedCodeObjectInfo, Ref{Cvoid}), loaded_code_object, attribute, value)
end


text:
#
# ncconst.jl -
#
# Constants defined for Nüvü Camēras.
#
# *DO NOT EDIT* Some parts of this file are generated automatically.
#
const OPENGL_ENABLE  = Cint(0)

const AUTO_DETECT    = Cint(0x0000ffff)
const AUTO_CHANNEL   = AUTO_DETECT
const AUTO_UNIT      = Cint(0x6fffffff)
const FULL_WIDTH     = Cint(-1)
const FULL_HEIGHT    = Cint(-1)
const USE_MAC_ADRESS = Cint(0x20000000)

# Type of amplifier set by the seleted readout mode.
@enum(Ampli::Cint, NOTHING = 0, EM, CONV)

# Type of communication interface that can be used.
@enum(CommType::Cint,
      INVALID     = 0x0000fffe,
      AUTO_COMM   = 0x6fff0000, # AUTO_UNIT - AUTO_DETECT
      VIRTUAL     = 0x7fff0000,
      EDT_CL      = 0x00000000,
      PT_GIGE     = 0x00010000,
      MIL_CL      = 0x00020000,
      SAPERA_CL   = 0x00030000,
      UNKNOWN     = 0x00040000,
      REMOTE_COMM = 0x00050000)

@enum(DetectorType::Cint,
      CCD60 = 0,
      CCD97,
      CCD201_20,
      CCD207_00,
      CCD207_10,
      CCD207_40,
      CCD220,
      UNKNOWN_CCD)

# All camera parameters.
@enum(Features::Cint,
      UNKNOWN_FEATURE,
      EXPOSURE,
      WAITING_TIME,
      TRIGGER_MODE,
      SHUTTER_MODE,
      SHUTTER_POLARITY,
      EXTERNAL_SHUTTER,
      EXTERNAL_SHUTTER_MODE,
      EXTERNAL_SHUTTER_DELAY,
      FIRE_POLARITY,
      MINIMUM_PULSE_WIDTH,
      ARM_POLARITY,
      CALIBRATED_EM_GAIN,
      RAW_EM_GAIN,
      ANALOG_GAIN,
      ANALOG_OFFSET,
      TARGET_DETECTOR_TEMP,
      DETECTOR_TEMP,
      CTRL_TIMESTAMP,
      GPS_PRESENT,
      GPS_LOCKED,
      BINNING_X,
      BINNING_Y,
      ROI,
      CROP_MODE_X,
      CROP_MODE_Y,
      ACTIVE_REGION,
      MULTIPLE_ROI,
      TRIGGER_MODE_INTERNAL,   # INTERNAL trigger mode
      TRIGGER_MODE_EXTERNAL,   # EXT_HIGH_LOW or EXT_LOW_HIGH
      TRIGGER_MODE_EXPOSURE,   # EXT_HIGH_LOW_EXP or EXT_HIGH_LOW_EXP
      TRIGGER_MODE_CONTINUOUS, # CONT_HIGH_LOW or CONT_LOW_HIGH
      SYSTEM_STATUS,
      SHORT_SSVA_CMD,
      BIN_CDS)

# List of different temperatures
@enum(TemperatureType::Cint,
      TEMP_CCD,
      TEMP_CONTROLLER,
      TEMP_POWER_SUPPLY,
      TEMP_FPGA,
      TEMP_HEATINK)

# Reasons why a tap was reported as unused
@enum(PortUnusedReason::Cint,
      PORT_UNUSED_NO_DEVICE,      # The port was found to not be connected to a device
      PORT_UNUSED_ALREADY_IN_USE, # The device is already in use by another instance
      PORT_UNUSED_FILTERED,       # Port was not scanned (filtered, internal use only)
      PORT_UNUSED_UNKNOWN)        # The reason was unusual and has no unique identifier

# Type of shutter mode available
@enum(ShutterMode::Cint, SHUT_NOT_SET = 0, OPEN = 1, CLOSE = 2, AUTO = 3)
const BIAS_DEFAULT = CLOSE

# Type of trigger mode available
@enum(TriggerMode::Cint,
      CONT_HIGH_LOW = -3,
      EXT_HIGH_LOW_EXP = -2,
      EXT_HIGH_LOW = -1,
      INTERNAL = 0,
      EXT_LOW_HIGH = 1,
      EXT_LOW_HIGH_EXP = 2,
      CONT_LOW_HIGH = 3)

# Type of crop-mode available
@enum(CropMode::Cint,
      CROP_MODE_DISABLE = 0,
      CROP_MODE_ENABLE_X = 1,
      CROP_MODE_ENABLE_Y = 2,
      CROP_MODE_ENABLE_XY = 3)
const CROP_MODE_ENABLE_ZL = CROP_MODE_ENABLE_X
const CROP_MODE_ENABLE_SP = CROP_MODE_ENABLE_Y
const CROP_MODE_ENABLE_MX = CROP_MODE_ENABLE_XY

@enum(ExtShutter::Cint, EXTERNAL_SHUTTER_DISABLE = 0, EXTERNAL_SHUTTER_ENABLE = 1)

@enum(ExtPolarity::Cint,NEGATIVE = -1, POL_NOT_SET = 0, POSITIVE = 1)

# Type of image format which will be used to save an image
@enum(ImageFormat::Cint, UNKNOWNN = -1, TIF = 0, FITS)

# Use only CFITSIO DATATYPE codes
@enum(ImageDataType::Cint,
      IMG,       # uint 16 bit
      IMG_UINT,  # uint 32 bit
      IMG_ULONG, # uint 64 bit
      IMG_FLOAT) # 32 bit float

const PixelTypes = Union{UInt16,UInt32,UInt64,Cfloat}
getPixelType(::Type{UInt16}) = IMG
getPixelType(::Type{UInt32}) = IMG_UINT
getPixelType(::Type{UInt64}) = IMG_ULONG
getPixelType(::Type{Cfloat}) = IMG_FLOAT

@enum(HeaderDataType::Cint, INT, DOUBLE, STRING)

@enum(ImageCompression::Cint, NO_COMPRESSION = 0, GZIP)

@enum(ProcType::Cint, NO_PROC = 0x00, LM = 0x01, PC = 0x02)

@enum(TimestampMode::Cint,
      NO_TIMESTAMP = 0,
      INTERNAL_TIMESTAMP = 1,
      GPS_TIMESTAMP = 2)

# List of possible version numbers.
@enum(VersionType::Cint, SOFTWARE, FIRMWARE, FPGA, HARDWARE)

# Tiff tags.
@enum(TiffTag::Cint,
      AMPLI_TYPE_TAG           = 650,
      HORIZ_FREQ_TAG           = 651,
      VERT_FREQ_TAG            = 652,
      EXPOSURE_TIME_TAG        = 653,
      EFFECTIVE_EXP_TIME_TAG   = 682,
      WAITING_TIME_TAG         = 654,
      RAW_EM_GAIN_TAG          = 655,
      CAL_EM_GAIN_TAG          = 680,
      ANALOG_GAIN_TAG          = 656,
      ANALOG_OFFSET_TAG        = 657,
      TARGET_DETECTOR_TEMP_TAG = 658,
      BINNING_X_TAG            = 659,
      BINNING_Y_TAG            = 660,
      ROI_X1_TAG               = 661,
      ROI_X2_TAG               = 662,
      ROI_Y1_TAG               = 663,
      ROI_Y2_TAG               = 664,
      CROP_MODE_ENABLE_TAG     = 695,
      CROP_MODE_PADDING_X_TAG  = 696,
      CROP_MODE_PADDING_Y_TAG  = 697,
      SHUTTER_MODE_TAG         = 665,
      TRIGGER_MODE_TAG         = 666,
      CLAMP_LEVEL_TAG          = 667,
      PROC_TYPE_TAG            = 676,
      NBR_PC_IMAGES_TAG        = 675,
      SERIAL_NUMBER_TAG        = 668,
      FIRM_VERSION_TAG         = 669,
      HARDW_VERSION_TAG        = 670,
      FPGA_VERSION_TAG         = 671,
      SOFT_VERSION_TAG         = 672,
      ADD_COMMENTS_TAG         = 674,
      OVERSCAN_LINES_TAG       = 677,
      OVERSAMPLE_X_TAG         = 678,
      DETECTOR_TYPE_TAG        = 681,
      FIRE_POLARITY_TAG        = 688,
      SHUTTER_POLARITY_TAG     = 683,
      ARM_POLARITY_TAG         = 689,
      OUTPUT_PULSE_WIDTH_TAG   = 687,
      EXT_SHUTTER_PRES_TAG     = 684,
      EXT_SHUTTER_MODE_TAG     = 685,
      EXT_SHUTTER_DELAY_TAG    = 686,
      OBS_DATE_TAG             = 690,
      OBS_TIME_SEC_FRACT_TAG   = 691,
      OBS_FLAGS_TAG            = 692,
      DATE_TIME_US_TAG         = 694,
      HOST_TIME_TAG            = 693,
      NBR_IMAGES_TRIG_TAG      = 679,
      SEQUENCE_NAME_TAG        = 673)

# Common data type enumeration
@enum(SdkDataTypes::Cint,
      SdkDataTypeInt = 0,
      SdkDataTypeDouble,
      SdkDataTypeString)

# Error codes.
const SUCCESS = Status(0)
const GENERIC_ERROR = Status(1)
const ERROR_MEM_ALLOC = Status(11) # Memory allocation error, please make sure your system have sufficient RAM to operate your application
const ERROR_MUTEX_LOCK = Status(12)
const ERROR_MUTEX_RELEASE = Status(14) # An internal mutex can't be released, please review the concurrent threads of your application
const ERROR_CREATE_THREAD = Status(15) # An internal thread can't be properly created
const ERROR_RELEASE_THREAD = Status(16)
const ERROR_WAIT_SIGNAL = Status(17)
const ERROR_BAD_CMD_LINE_PARAMS = Status(18)
const ERROR_DATA_TYPE = Status(25) # The data type passed for this function is invalid
const ERROR_IMAGE_HEADER_FORMAT = Status(26) # The image format doesn't support additional headers
const ERROR_CAMERA_FOUND = Status(27) # No camera has been found using the automatic parameters passed
const ERROR_NO_GRABBER = Status(28)
const ERROR_UNKNOWN = Status(41)
const ERROR_STL_ERROR = Status(42) # std::exception
const ERROR_LOGIC_ERROR = Status(43) # std::logic_error exception
const ERROR_RUNTIME_ERROR = Status(44) # std::runtime_error exception
const ERROR_BAD_CAST = Status(45) # stdbad_cast exception
const ERROR_BAD_FUNC_POINTER = Status(46) # std::bad_function_call
const ERROR_BAD_TYPE_ID = Status(47) # std::bad_typeid
const ERROR_BAD_WEAK_PTR = Status(48) # std::bad_weak_ptr
const ERROR_COM_CMD_RET = Status(51) # The camera returned an error to the command sent
const ERROR_COM_CMD_ANSW = Status(52) # The camera never finished answering the command sent
const ERROR_COM_CSUM_REC = Status(53) # The checksum calculated for the answer received doesn't match the one sent by the camera
const ERROR_COM_CSUM_SENT = Status(54) # The camera returned an error to the checksum sent
const ERROR_COM_CSUM_ANSW = Status(55) # The camera never finished answering the checksum sent
const ERROR_COM_ABORT_STATE = Status(56) # The camera status command didn't came back in the idle state as it should after an abort
const ERROR_COM_UNEXPECTED = Status(57) # Serial communication with the controller diverged from the established protocol
const ERROR_CAM_PARSE_INIT = Status(76) # One of the passed parameter hasn't been properly initialized
const ERROR_CAM_PARSE_FOUND = Status(77) # The information expected hasn't been found
const ERROR_CAM_PARSE_DEFINE = Status(78) # The internal define function hasn't been able to run as expected
const ERROR_NO_MENS_LAND = Status(99) # You're in an unexpected case, if you can reproduce this issue, contact Nuvu Cameras
const ERROR_CAM_STRUCT_PTR = Status(101) # The structure pointer (NcCam) passed to the function is invalid
const ERROR_CAM_PARAM_INIT = Status(102) # One of the required parameters hasn't been properly initialized
const ERROR_CAM_PARAM_OUT = Status(103) # One of the parameter values is invalid because it is out of bounds
const ERROR_CAM_ASCII_REC = Status(104) # Even though the serial answer received seems fine, a typo error from the controller seems to be present
const ERROR_CAM_FIRMWARE_VERSION = Status(105) # The firmware version of the controller isn't compatible with the feature you're trying to use
const ERROR_CAM_FIRMWARE_DETECTION = Status(106) # The firmware version can't be read properly
const ERROR_CAM_NO_FEATURE = Status(107) # The feature you're looking to use isn't supported by this camera
const ERROR_CAM_NO_READOUT = Status(108) # The readout mode loaded isn't a valid one
const ERROR_CAM_EM_READOUT = Status(109) # This function can only be executed while using an EM readout mode, which isn't the case
const ERROR_CAM_SAVE_OPEN = Status(110) # The file you're trying to create to save the image can't be put in place
const ERROR_CAM_SAVE_FORMAT = Status(111) # The save format specified isn't valid or supported for this data type
const ERROR_CAM_SAVE_OVERWRITE = Status(112) # There's already an image file with this name, please select a new name or modify the overwrite flag
const ERROR_CAM_SAVE_DEPTH = Status(113) # The data type specified can't be saved with the appropriate depth
const ERROR_CAM_INTERNAL_REG = Status(114) # Some internal camera registers hasn't properly be initialized
const ERROR_CAM_PARAM_OPEN = Status(115) # The camera parameter file speified can't be opened
const ERROR_CAM_PARAM_READ = Status(116) # The camera parameter file can't be read properly, please make sure it's not write protected and you have the rights to access this file
const ERROR_CAM_PARAM_POS = Status(117) # The camera parameter file size can't be retrieved, make sure it's not empty
const ERROR_CAM_PARAM_VALUE = Status(118) # The buffer size in which the camera parameter file information are being copied isn't the appropriate one
const ERROR_CAM_PARAM_READOUT = Status(119) # There's no readout mode matching the one you used when saving your parameters
const ERROR_CAM_PARAM_MISS = Status(120) # Some required camera parameters can't be found in the camera parameters file
const ERROR_CAM_PARAM_OVERWRITE = Status(121) # There's already a camera parameter file existing with the same name, please select a new name or modify the overwrite flag
const ERROR_CAM_EMPTY_ANSWER = Status(122)
const ERROR_CAM_FEATURE_DISABLED = Status(123) # The current mode of operation means that this function can't be used (e.g. Crop mode prohibits MoveRoi)
const ERROR_CAM_ROI_OVERLAP = Status(124) # Can't apply the current ROIs because two or more ROIs overlap
const ERROR_CAM_TOO_MANY_ROIS = Status(125) # Trying to add an ROI, but the maximum number of supported ROIs has been reached
const ERROR_CAM_BAD_ROI_INDEX = Status(126) # Trying to access an ROI, but the index that was used is invalid
const ERROR_CAM_ROI_OUT_OF_BOUNDS = Status(127) # An ROI's definition exceeds the available dimensions of the sensor
const ERROR_CAM_SAVE_WRITE_DATA = Status(128) # An error occured while writing pixel values to an image file
const ERROR_CAM_SAVE_WRITE_META = Status(129) # An error occured while writing metadata to an image file
const ERROR_CAM_DEPRECATED = Status(130) # This function is deprecated and this use of it is not supported
const ERROR_CAM_NONSTOP = Status(131) # The acquisition in progress is required to not halt but the change requested would require it
const ERROR_CAM_NO_READOUT_MODE = Status(132) # No readout sequence has been loaded yet
const ERROR_CAM_READOUT_MODE_INVALID = Status(133) # The selected readout mode does not conform to the requirements of a CamContext
const ERROR_CAM_ROI_INVLAID = Status(134) # The requested ROI cannot be returned
const ERROR_CAM_CROPMODE_ROI_INVLAID = Status(135) # The requested ROI cannot be returned with this crop-mode
const ERROR_CAM_NOT_PREPARED = Status(136) # The user has asked the acquisition to begin but has not prepared the framegrabber
const ERROR_CAM_NO_ROIS = Status(137) # Trying to apply ROIs, but none are defined; there must always be one or more ROIs defined.
const ERROR_GRAB_STRUCT_PTR = Status(201) # The structure pointer (NcGrab) passed to the function is invalid
const ERROR_GRAB_PARAM_INIT = Status(202) # One of the required parameter hasn't been properly initialized
const ERROR_GRAB_PARAM_OUT = Status(203) # One of the parameter value is out of bound and can't be used
const ERROR_GRAB_REG_ACCESS = Status(204) # The nc registry keys can't be accessed. Please make sure that the installation of this software does not report an error and that the permissions of your current session let you access the registry of your system.
const ERROR_GRAB_REG_MISS = Status(205) # Some of the mandatory nc registry keys haven't been setup properly. Please contact nc Technical support to remedy this issue.
const ERROR_GRAB_COMM_INTER = Status(206) # Unknown communication interface passed to the Open function thru the Unit parameter
const ERROR_GRAB_CONFIG_OPEN = Status(207) # The Nuvu Cameras configuration file can't be opened, please make sure it's in the Nuvu Cameras path
const ERROR_GRAB_CONFIG_READ = Status(208) # The Nuvu Cameras configuration file can't be read properly, please make sure it's not right protected and you have the rights to access this file
const ERROR_GRAB_CONFIG_POS = Status(209) # The Nuvu Cameras configuration file size can't be retrieved, make sure it's not empty
const ERROR_GRAB_CONFIG_VALUE = Status(210) # The buffer size in which the Nuvu Cameras configuration file information are being copied isn't the appropriate one
const ERROR_GRAB_LOG_OPEN = Status(211) # The log file file can't be opened, please make sure "Log" folder exist in the Nuvu Cameras path
const ERROR_GRAB_SAVE_FORMAT = Status(212) # The save format specified isn't valid or supported
const ERROR_GRAB_COMP_FORMAT = Status(213) # The compression format specified isn't valid or supported
const ERROR_GRAB_TIMEOUT = Status(214) # The image didn't arrived prior to the timeout value set
const ERROR_GRAB_NO_IMAGE = Status(215) # There's no image already available, so a null pointer is being returned
const ERROR_GRAB_NOT_STOP = Status(216) # Acquisitions are still in progress even though they should be stopped
const ERROR_GRAB_CLOSE_ACQUISITION = Status(217)
const ERROR_GRAB_SKIP_IMAGE = Status(218)
const ERROR_GRAB_BIAS_SIZE = Status(219)
const ERROR_GRAB_DEBUG_LEVEL = Status(220)
const ERROR_GRAB_PROC_TIMEOUT = Status(221)
const ERROR_GRAB_BIAS_CANCEL = Status(222)
const ERROR_GRAB_SUPPORT_MAC = Status(223)
const ERROR_GRAB_FIRMWARE_VERSION = Status(224)
const ERROR_GRAB_NO_FEATURE = Status(225) # The feature you're looking to use isn't supported by this controller
const ERROR_GRAB_NO_GPS = Status(226)
const ERROR_GRAB_TIMESTAMP_SKIP = Status(227)
const ERROR_GRAB_GPS_UNLOCK = Status(228)
const ERROR_GRAB_NO_TIMESTAMP = Status(229)
const ERROR_GRAB_UNMATCH_IMAGE = Status(230)
const ERROR_GRAB_BUFFER_TOO_SMALL = Status(231)
const ERROR_ALREADY_OPENED = Status(232)
const ERROR_GRAB_CONFIRM_FAILED = Status(233)
const ERROR_GRAB_GPS_INVALID = Status(234) # Timestamp information received from the GPS unit is not valid: it must provide the NEMA GPZDA sentence
const ERROR_PROC_STRUCT_PTR = Status(301) # The structure pointer (NcProcCtx) passed to the function is invalid
const ERROR_PROC_PARAM_INI = Status(302) # One of the required parameter hasn't been properly initialized
const ERROR_PROC_PARAM_OUT = Status(303) # One of the parameter value is out of bound and can't be used
const ERROR_PROC_NO_TYPE = Status(304) # The processing type isn't valid or supported
const ERROR_PROC_NO_BIAS = Status(305) # There's no image stored to calculate the Bias
const ERROR_PROC_SAVE_OPEN = Status(306) # The bias file can't be correctly open
const ERROR_PROC_BIAS_LOAD = Status(307) # One the bias parameter can't be loaded correctly
const ERROR_PROC_BIAS_SAVE = Status(308) # There's no Bias image available to save
const ERROR_PROC_SAVE_OVERWRITE = Status(309) # There's already a bias file with this name, please select a new name or modify the overwrite flag
const ERROR_PROC_LOAD_SN = Status(310)
const ERROR_PROC_LOAD_READOUT = Status(311)
const ERROR_PROC_LOAD_AMPLI = Status(312)
const ERROR_PROC_LOAD_VERT = Status(313)
const ERROR_PROC_LOAD_HORIZ = Status(314)
const ERROR_PROC_IMAGE_CONTEXT_SIZE = Status(315) # The number of images the context can contain is 3 or 10
const ERROR_PROC_RETRIEVE_OUT = Status(316) # The number of the image to be retrieved is larger than the maximum number of images that the context stores
const ERROR_PROC_RETRIEVE_LARGE = Status(317) # The number of the image to be retrieved is larger than the number of images in the context
const ERROR_PROC_SIZE_COSMICRAY = Status(318) # The number of images in the context is not large enough for removing cosmic rays. Please add more images
const ERROR_PROC_NO_CONTEXT_SIZE = Status(319) # It is not possible to add / get images to / from the context since it is set to not store images
const ERROR_PROC_NO_RECENT_IMAGE = Status(320) # No more recent images to retrieve
const ERROR_PROC_SIZE_PC = Status(321) # The number of images in the context is not large enough to obtain a PC image. Please add more images
const ERROR_PROC_BAD_MODE = Status(322) # The current processing mode is invalid for the requested operation
const ERROR_EDT_DEP_STRUCT = Status(401) # The internal dependent structure that EDT generates to initialize the frame grabber hasn't been created properly
const ERROR_EDT_INIT = Status(402) # The initialization of the frame grabber failed
const ERROR_EDT_READ_CONFIG = Status(403) # The EDT initialization file hasn't been read properly
const ERROR_EDT_OPEN_STRUCT = Status(404) # The EDT driver hasn't been able to properly open/allocate its structure
const ERROR_EDT_CLOSE_STRUCT = Status(405) # The EDT driver hasn't been able to properly close/free its structure
const ERROR_EDT_MULTIBUF = Status(406) # The EDT driver hasn't been able to allocate the desired number of loop buffer
const ERROR_EDT_SET_BAUD = Status(407) # The EDT driver can't set this baudrate.
const ERROR_EDT_BIN_CMD = Status(408) # The binary command can't be sent using the EDT driver
const ERROR_EDT_SET_TIMEOUT = Status(409) # The timeout can't be set using the the EDT driver
const ERROR_EDT_STOP_BUFFERS = Status(410) # The EDT drivers can't have the buffer to stop receiving images
const ERROR_EDT_PARAM_SIZE = Status(411) # The EDT driver hasn't been able to set the width or the heigth passed in parameter
const ERROR_EDT_SET_SIZE = Status(412) # The EDT driver hasn't been able to modifiy the buffer size receiving the image
const ERROR_EDT_SET_ROI = Status(413) # The EDT driver hasn't been able to modify the buffer size so it size is now matching the buffer receive
const ERROR_EDT_CANCEL_EVENT = Status(414) # The EDT driver can't cancel the grab event linked to the structure passed in parameter
const ERROR_EDT_SET_EVENT = Status(415) # The EDT driver isn't able to properly set the grab event
const ERROR_EDT_DEVICE_FOUND = Status(416) # No device linked through EDT have been found, make sure the cable are correctly plus and try to reboot the device
const ERROR_VIRTUAL_NO_CAMERA = Status(501) # There's no virtual camera specified in the Nuvu Cameras configuration file
const ERROR_VIRTUAL_DETECTOR_TYPE = Status(502) # There's no detector type specified in the Nuvu Cameras configuration file
const ERROR_VIRTUAL_DETECTOR_WIDTH = Status(503) # There's no detector width specified in the Nuvu Cameras configuration file
const ERROR_VIRTUAL_DETECTOR_HEIGHT = Status(504) # There's no detector height specified in the Nuvu Cameras configuration file
const ERROR_VIRTUAL_TEMP_MIN = Status(505) # There's no minimal temperature specified in the Nuvu Cameras configuration file
const ERROR_VIRTUAL_TEMP_MAX = Status(506) # There's no maximal temperature specified in the Nuvu Cameras configuration file
const ERROR_VIRTUAL_ACTIVE_WIDTH = Status(507)
const ERROR_VIRTUAL_ACTIVE_HEIGHT = Status(508)
const ERROR_PLEORA_SIZE_MISMATCH = Status(601)
const ERROR_PLEORA_TIMEOUT_MISMATCH = Status(602)
const ERROR_PLEORA_FIND_SYSEM = Status(603) # The Pleora driver hasn't been able to proceed with the detection of the GigE devices
const ERROR_PLEORA_CONNECTION_FAILED = Status(604) # The connection to the requested GigE device failed
const ERROR_PLEORA_DEVICE_FOUND = Status(605) # No GigE device have been found, make sure the cable are correctly plus and try to reboot the device
const ERROR_PLEORA_STREAM_OPEN = Status(606) # The Pleora GigE stream can't be opened with the requested device
const ERROR_PLEORA_STREAM_DESTINATION = Status(607) # The Pleora GigE stream destination can't be set
const ERROR_PLEORA_PIPELINE_BUFFERS = Status(608) # The Pleora acquisitions buffers can't be allocated by the pleora driver
const ERROR_PLEORA_SET_TIMEOUT = Status(609) # The modification request, to have the timeout modified, failed
const ERROR_PLEORA_SET_DEPTH = Status(610) # The modification request, to have the pixel depth modified, failed
const ERROR_PLEORA_DVAL_ENABLE = Status(611) # The modification request, to have the DVAL signal enable, failed
const ERROR_PLEORA_SET_WIDTH = Status(612) # The modification request, to have the image width modified, failed
const ERROR_PLEORA_SET_HEIGHT = Status(613) # The modification request, to have the image height modified, failed
const ERROR_PLEORA_SET_BAUDRATE = Status(614) # The modification request, to have the serial baudrate modified, failed
const ERROR_PLEORA_STOP_BITS = Status(615) # The modification request, to have the number of stop bits set to one, failed
const ERROR_PLEORA_TEST_IMAGE = Status(616) # The modification request, to have the test image disabled, failed
const ERROR_PLEORA_TICK_FREQUENCY = Status(617) # The modification request, to get the tick frequency per second, failed
const ERROR_PLEORA_SET_PARITY = Status(618) # The modification request, to have the parity set to none, failed
const ERROR_PLEORA_RESET_TIMSTAMP = Status(619) # The modification request, to reset the timestamp, failed
const ERROR_PLEORA_SET_LOOPBACK = Status(620) # The modification request, to disable the Uart loopback, failed
const ERROR_PLEORA_ACQUISITION_START = Status(621) # The command, to have the acquisition started, failed
const ERROR_PLEORA_ACQUISITION_STOP = Status(622) # The command, to have the acquisotion stopped, failed
const ERROR_PLEORA_PORT_OPEN = Status(623) # The Pleora GigE port can't be opened with the requested device
const ERROR_PLEORA_SERIAL_SIZE = Status(624) # The Pleora GigE driver can't set the serial buffer size
const ERROR_PLEORA_PIPELINE_START = Status(625) # The Pleora GigE driver can't have the image pipeline to start
const ERROR_PLEORA_SERIAL_WRITE = Status(626) # The Pleora GigE driver can't write the requested command to the serial port
const ERROR_PLEORA_SET_HEARTBEAT = Status(627)
const ERROR_PLEORA_SET_DEVICE = Status(628)
const ERROR_PLEORA_SET_PORT = Status(629)
const ERROR_PLEORA_NEGOCIATE_PACKET = Status(630)
const ERROR_PLEORA_NOT_SUPPORTED = Status(631)
const ERROR_PLEORA_REQUEST_TIMEOUT = Status(632) # The modification request, to set the timeout on an image request, failed
const ERROR_SERVICE_WINSOCK_START = Status(701) # The winsock library hasn't started properly
const ERROR_SERVICE_WINSOCK_VERSION = Status(702) # The winsock version used in the dll isn't the one expected
const ERROR_SERVICE_CREATE_SOCKET = Status(703) # The application hasn't been able to create a socket to connect to the service
const ERROR_SERVICE_CONNECT_SERVICE = Status(704) # The application hasn't been able to connect itself to the service
const ERROR_SERVICE_SEND_COMMAND = Status(705) # The application hasn't been able to send a command to the service
const ERROR_SERVICE_RECEIVE_COMMAND = Status(706) # The application hasn't been able to receive the answer from the service
const ERROR_SERVICE_DEVICE_LOCK = Status(707) # The device you're trying to open is already locked by another application
const ERROR_SERVICE_LOCK_ACCESS_DENIED = Status(708) # The device lock you're trying to access belongs to another process
const ERROR_STATS_INVALID_INDEX = Status(801)
const ERROR_STATS_REGION_OUT = Status(802) # The statsCtx selected is outside the boundaries of the image
const ERROR_STATS_IMAGE_SIZE = Status(803)
const ERROR_STATS_STRUCT_PTR = Status(804)
const ERROR_MIL_DEVICE_FOUND = Status(901)
const ERROR_MIL_NOT_SUPPORTED = Status(902)
const ERROR_MIL_SET_SIZE = Status(903)
const ERROR_MIL_BUFFER_ALLOCATION = Status(904) # Use the MILConfig tool to reserve additional non-paged memory
const ERROR_MIL_UART_UAVAILABLE = Status(905)
const ERROR_APPLICATION_ALLOCATION = Status(906)
const ERROR_MIL_SMALL_WIDTH = Status(907)
const ERROR_MIL_PORT_UNAVAILABLE = Status(908)
const ERRROR_SAPERA_SERIAL_FUNCTION = Status(1001)
const ERROR_SAPERA_SERIAL_READ = Status(1002)
const ERROR_SAPERA_SERIAL_WRITE = Status(1003)
const ERROR_SAPERA_SERIAL_UNREAD = Status(1004)
const ERROR_SAPERA_DEVICE_FOUND = Status(1005)
const ERROR_SAPERA_INVALID_BAUDRATE = Status(1006)
const ERROR_SAPERA_SET_BAUDRATE = Status(1007)
const ERROR_SAPERA_CREATE_ACQUISITION = Status(1008)
const ERROR_SAPERA_SERIAL_PORT = Status(1009)
const ERROR_SAPERA_SERIAL_INIT = Status(1010)
const ERROR_SAPERA_SERIAL_MATCH = Status(1011)
const ERROR_SAPERA_SERIAL_CLOSE = Status(1012)
const ERROR_SAPERA_ACQ_DESTROY = Status(1013)
const ERROR_SAPERA_NBR_SERIAL = Status(1014)
const ERROR_SAPERA_ACQ_CREATE = Status(1015)
const ERROR_SAPERA_BUFFERS_CREATE = Status(1016)
const ERROR_SAPERA_XFER_CREATE = Status(1017)
const ERROR_SAPERA_DESTROY_XFER = Status(1018)
const ERROR_SAPERA_DESTROY_BUFFERS = Status(1019)
const ERROR_SAPERA_DESTROY_ACQ = Status(1020)
const ERROR_SAPERA_BUFFERS_WIDTH = Status(1021)
const ERROR_SAPERA_BUFFERS_HEIGHT = Status(1022)
const ERROR_SAPERA_ACQ_WIDTH = Status(1023)
const ERROR_SAPERA_CROP_WIDTH = Status(1024)
const ERROR_SAPERA_ACQ_HEIGHT = Status(1025)
const ERROR_SAPERA_CROP_HEIGHT = Status(1026)
const ERROR_SAPERA_GRAB_START = Status(1027)
const ERROR_SAPERA_XFER_FREEZE = Status(1028)
const ERROR_SAPERA_XFER_WAIT = Status(1029)
const ERROR_SAPERA_XFER_ABORT = Status(1030)
const ERROR_SAPERA_WIDTH_OUT = Status(1031)
const ERROR_SAPERA_HEIGHT_OUT = Status(1032)
const ERROR_SAPERA_XFER_INIT = Status(1033)
const ERROR_SAPERA_SERIAL_READ_TIMEOUT = Status(1034)
const ERROR_SAPERA_RESSOURCE_CREATE = Status(1035)
const ERROR_SAPERA_ASSERT_FAILURE = Status(1036)
const ERROR_VERSION_FAILED = Status(2001) # Failed to parse a version string
const ERROR_STRING_CAST_FAILED = Status(2002) # Failed to obtain a value from a string
const ERROR_ENV_VAR_ACCESS_FAILED = Status(2003)
const ERROR_PIPELINE_ERROR = Status(3001)
const ERROR_GLOBAL_MUTEX_CREATE_FAILED = Status(4001) # An error occured while creating a global mutex file, check the lock files directory write permissions
const ERROR_GLOBAL_MUTEX_LOCK_FAILED = Status(4002)
const ERROR_SHARED_MEMORY_CREATE_FAILED = Status(4003)
const ERROR_SHARED_MEMORY_TOO_SMALL = Status(4004)
const ERROR_SHARED_MEMORY_ACCESS_FAILED = Status(4005)
const ERROR_PROCESS_FAILED_TO_FIND_BIN = Status(4006)
const ERROR_PROCESS_FAILED_TO_START_BIN = Status(4007)
const ERROR_PROCESS_FAILED_TO_OPEN_PIPE = Status(4008)
const ERROR_PROCESS_PIPE_IO_ERROR = Status(4009)
const ERROR_FAILED_TO_MAKE_DIR = Status(5001)
const ERROR_FAILED_TO_OPEN_FILE = Status(5002)
const ERROR_FAILED_TO_DELETE_FILE = Status(5003)
const ERROR_FILE_IO_FAILED = Status(5004)
const ERROR_FAILED_TO_LOAD_PLUGIN = Status(6001)
const ERROR_FAILED_TO_LOAD_SYMBOL = Status(6002)
const ERROR_SYMBOL_NOT_LOADED = Status(6003)
const ERROR_PLUGIN_DIRECTORY_MISSING = Status(6004)
const ERROR_PLUGIN_METADATA_MISSING = Status(6005)
const ERROR_BOARD_NAME_TOO_LONG = Status(6006)
const ERROR_TAP_TAG_TOO_LONG = Status(6007)
const ERROR_TAP_ALREADY_LOCKED = Status(6008)
const ERROR_PLUGIN_THREW_EXCEPTION = Status(6009)
const ERROR_CORE_OVERFLOW = Status(7001)
const ERROR_CORE_UNDERFLOW = Status(7002)
const ERROR_TIME_CAST_FAILED = Status(7003)
const ERROR_OUT_OF_BOUNDS = Status(7004)

ext: jl


text:
export AbstractRegister, AdjointRegister, DensityMatrix

"""
    AbstractRegister{D}

Abstract type for quantum registers. `D` is the number of levels in each qudit.
"""
abstract type AbstractRegister{D} end

"""
    AdjointRegister{D, RT} <: AbstractRegister{D}

Lazy adjoint for a quantum register, `RT` is the parent type.
"""
struct AdjointRegister{D,RT<:AbstractRegister{D}} <: AbstractRegister{D}
    parent::RT
end

"""
    instruct!(state, operator[, locs, control_locs, control_configs, theta])

instruction implementation for applying an operator to a quantum state.

This operator will be overloaded for different operator or state with
different types.
"""
@interface instruct!

# properties
"""
    nactive(register) -> Int

Returns the number of active qudits.

!!! note

    Operators always apply on active qudits.
"""
@interface nactive

"""
    nqubits(register) -> Int

Returns the (total) number of qubits. See [`nactive`](@ref), [`nremain`](@ref)
for more details.
"""
@interface nqubits

"""
    nqudits(register) -> Int

Returns the (total) number of qudits. See [`nactive`](@ref), [`nremain`](@ref)
for more details.
"""
@interface nqudits

"""
    nremain(register) -> Int

Returns the number of non-active qudits.
"""
@interface nremain

"""
    viewbatch(register, i::Int) -> AbstractRegister{1}

Returns a view of the i-th slice on batch dimension.
"""
@interface viewbatch

###################### Reg Operations: Location and size #####################
"""
    adddits!(register, n::Int) -> register
    adddits!(n::Int) -> λ(register)

Add `n` qudits to given register in state |0>.
i.e. |psi> -> |000> ⊗ |psi>, increased bits have higher indices.

If only an integer is provided, then returns a lambda function.
"""
@interface addbits!

"""
    insert_qudits!(register, loc::Int; nqudits::Int=1) -> register
    insert_qudits!(loc::Int; nqudits::Int=1) -> λ(register)

Insert `n` qudits to given register in state |0>.
i.e. |psi> -> |psi> ⊗ |000> ⊗ |psi>, increased bits have higher indices.

If only an integer is provided, then returns a lambda function.
"""
@interface insert_qudits!

"""
    insert_qubits!(register, loc::Int; nqubits::Int=1) -> register
    insert_qubits!(loc::Int; nqubits::Int=1) -> λ(register)

Insert `n` qubits to given register in state |0>.
i.e. |psi> -> |psi> ⊗ |000> ⊗ |psi>, increased bits have higher indices.

If only an integer is provided, then returns a lambda function.
"""
@interface insert_qubits!

"""
    focus!(register, locs) -> register

Focus the wires on specified location.

# Example

```julia
julia> focus!(r, (1, 2, 4))

```
"""
@interface focus!

"""
    focus(f, register, locs...)

Call a callable `f` under the context of `focus`. See also [`focus!`](@ref).

# Example

print the focused register

```julia
julia> r = ArrayReg(bit"101100")
ArrayReg{1,Complex{Float64},Array...}
    active qudits: 6/6

julia> focus(x->(println(x);x), r, 1, 2);
ArrayReg{1,Complex{Float64},Array...}
    active qudits: 2/6
```
"""
@interface focus

function focus(f, r::AbstractRegister, locs::NTuple{N, Int}) where N
    focus!(r, locs)
    ret = f(r)
    relax!(r, locs)
    return ret
end

focus(f, r::AbstractRegister, locs::Int...) = focus(f, r, locs)

"""
    relax!(register[, locs]; to_nactive=nqudits(register)) -> register

Inverse transformation of [`focus!`](@ref), where `to_nactive` is the number
 of active bits for target register.
"""
@interface relax!

"""
    partial_tr(register, locs)

Return a register which is the partial traced on `locs`.
"""
@interface partial_tr

"""
    reorder!(reigster, orders)

Reorder the locations of register by input orders.
"""
@interface reorder!

"""
    invorder(register)

Inverse the locations of register.
"""
@interface invorder!

"""
    collapseto!(register, config)

Set the `register` to bit string literal `bit_str` (or an equivalent integer). About bit string literal,
see more in [`@bit_str`](@ref).
"""
@interface collapseto!

##################### Measure ###################
export ComputationalBasis, AllLocs
export ResetTo, RemoveMeasured, NoPostProcess, PostProcess

struct ComputationalBasis end
struct AllLocs end

abstract type PostProcess end
struct ResetTo{T} <: PostProcess
    x::T
end
struct RemoveMeasured <: PostProcess end
struct NoPostProcess <: PostProcess end

"""
    measure([, operator], register[, locs]; nshots=1, rng=Random.GLOBAL_RNG) -> Vector{Int}

Return measurement results of qudits in `locs`.
If `locs` is not provided, all current active qudits are measured (regarding to active qudits,
see [`focus!`](@ref) and [`relax!`](@ref)).
"""
@interface measure

"""
    measure!([postprocess,] [operator, ]register[, locs]; rng=Random.GLOBAL_RNG)

Measure current active qudits or qudits at `locs`. After measure and collapse,

    * do nothing if postprocess is `NoPostProcess`
    * reset to result state to `postprocess.config` if `postprocess` is `ResetTo`.
    * remove the qubit if `postprocess` is `RemoveMeasured`
"""
@interface measure!

"""
    select!(dest::AbstractRegister, src::AbstractRegister, bits::Integer...) -> AbstractRegister
    select!(register::AbstractRegister, bits::Integer...) -> register

select a subspace of given quantum state based on input eigen state `bits`.
See also [`select`](@ref).

## Example

`select!(reg, 0b110)` will select the subspace with (focused) configuration `110`.
After selection, the focused qubit space is 0, so you may want call `relax!` manually.

!!! tip

    Developers should overload `select!(r::RegisterType, bits::NTuple{N, <:Integer})` and
    do not assume `bits` has specific number of bits (e.g `Int64`), or it will restrict the
    its maximum available number of qudits.
"""
@interface select!

"""
    select(register, bits) -> AbstractRegister

Non-inplace version of [`select!`](@ref).
"""
@interface select

###################### Other Operations #################
"""
    probs(register)

Returns the probability distribution of computation basis, aka ``|<x|ψ>|^2``.
"""
@interface probs

"""
    fidelity(register1, register2)

Return the fidelity between two states.

# Definition
The fidelity of two quantum state for qudits is defined as:

```math
F(ρ, σ) = tr(\\sqrt{\\sqrt{ρ}σ\\sqrt{ρ}})
```

Or its equivalent form (which we use in numerical calculation):

```math
F(ρ, σ) = sqrt(tr(ρσ) + 2 \\sqrt{det(ρ)det(σ)})
```

# Reference

- Jozsa R. Fidelity for mixed quantum states[J]. Journal of modern optics, 1994, 41(12): 2315-2323.
- Nielsen M A, Chuang I. Quantum computation and quantum information[J]. 2002.

!!! note

    The original definition of fidelity ``F`` was from "transition probability",
    defined by Jozsa in 1994, it is the square of what we use here.
"""
@interface fidelity

"""
    tracedist(register1, register2)

Return the trace distance of `register1` and `register2`.

# Definition
Trace distance is defined as following:

```math
\\frac{1}{2} || A - B ||_{tr}
```

# Reference

- https://en.wikipedia.org/wiki/Trace_distance
"""
@interface tracedist

#################### Error Handling ######################
export NotImplementedError, LocationConflictError, QubitMismatchError

# NOTE: kwargs do not involve in multiple dispatch
#       no need to store kwargs
struct NotImplementedError{ArgsT} <: Exception
    name::Symbol
    args::ArgsT
end

struct LocationConflictError <: Exception
    msg::String
end

# NOTE: More detailed error msg?
"""
    QubitMismatchError <: Exception

Qubit number mismatch error when applying a Block to a Register or concatenating Blocks.
"""
struct QubitMismatchError <: Exception
    msg::String
end

####################### Operator properties ###############
"""
    isunitary(op) -> Bool

check if this operator is a unitary operator.
"""
@interface isunitary

"""
    isreflexive(op) -> Bool

check if this operator is reflexive.
"""
@interface isreflexive

"""
    iscommute(ops...) -> Bool

check if operators are commute.
"""
@interface iscommute

####################### Density Matrix ############

"""
    DensityMatrix{D, T, MT}

Density Matrix.

- `T`: element type
"""
struct DensityMatrix{D,T,MT<:AbstractMatrix{T}} <: AbstractRegister{D}
    state::MT
end

"""
    purify(r::DensityMatrix; nbit_env::Int=nactive(r)) -> ArrayReg

Get a purification of target density matrix.
"""
@interface purify

"""
    density_matrix(register)

Returns the density matrix of current active qudits.
"""
@interface density_matrix

"""
    ρ(register)

Returns the density matrix of current active qudits. This is the same as
[`density_matrix`](@ref).
"""
@interface ρ