Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ PYBIND11_MODULE(ncnn, m)
.def_readwrite("use_sgemm_convolution", &Option::use_sgemm_convolution)
.def_readwrite("use_int8_inference", &Option::use_int8_inference)
.def_readwrite("use_vulkan_compute", &Option::use_vulkan_compute)
.def_readwrite("use_bf16_packed", &Option::use_bf16_packed)
.def_readwrite("use_bf16_storage", &Option::use_bf16_storage)
.def_readwrite("use_fp16_packed", &Option::use_fp16_packed)
.def_readwrite("use_fp16_storage", &Option::use_fp16_storage)
Expand Down
5 changes: 5 additions & 0 deletions python/tests/test_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def test_option():
opt.use_vulkan_compute = False
assert opt.use_vulkan_compute == False

opt.use_bf16_packed = True
assert opt.use_bf16_packed == True
opt.use_bf16_packed = False
assert opt.use_bf16_packed == False

opt.use_bf16_storage = True
assert opt.use_bf16_storage == True
opt.use_bf16_storage = False
Expand Down
204 changes: 192 additions & 12 deletions src/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,43 +159,193 @@ void ncnn_option_set_num_threads(ncnn_option_t opt, int num_threads)
((Option*)opt)->num_threads = num_threads;
}

void ncnn_option_set_blob_allocator(ncnn_option_t opt, ncnn_allocator_t allocator)
{
((Option*)opt)->blob_allocator = allocator ? (Allocator*)allocator->pthis : NULL;
}

void ncnn_option_set_workspace_allocator(ncnn_option_t opt, ncnn_allocator_t allocator)
{
((Option*)opt)->workspace_allocator = allocator ? (Allocator*)allocator->pthis : NULL;
}

int ncnn_option_get_use_vulkan_compute(const ncnn_option_t opt)
{
#if NCNN_VULKAN
return ((const Option*)opt)->use_vulkan_compute;
#else
(void)opt;
return 0;
#endif
}

int ncnn_option_get_use_local_pool_allocator(const ncnn_option_t opt)
{
return ((Option*)opt)->use_local_pool_allocator;
return ((const Option*)opt)->use_local_pool_allocator;
}

void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int use_local_pool_allocator)
int ncnn_option_get_use_winograd_convolution(const ncnn_option_t opt)
{
((Option*)opt)->use_local_pool_allocator = use_local_pool_allocator;
return ((const Option*)opt)->use_winograd_convolution;
}

void ncnn_option_set_blob_allocator(ncnn_option_t opt, ncnn_allocator_t allocator)
int ncnn_option_get_use_sgemm_convolution(const ncnn_option_t opt)
{
((Option*)opt)->blob_allocator = allocator ? (Allocator*)allocator->pthis : NULL;
return ((const Option*)opt)->use_sgemm_convolution;
}

void ncnn_option_set_workspace_allocator(ncnn_option_t opt, ncnn_allocator_t allocator)
int ncnn_option_get_use_packing_layout(const ncnn_option_t opt)
{
((Option*)opt)->workspace_allocator = allocator ? (Allocator*)allocator->pthis : NULL;
return ((const Option*)opt)->use_packing_layout;
}

int ncnn_option_get_use_vulkan_compute(const ncnn_option_t opt)
int ncnn_option_get_use_fp16_packed(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_fp16_packed;
}

int ncnn_option_get_use_fp16_storage(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_fp16_storage;
}

int ncnn_option_get_use_fp16_arithmetic(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_fp16_arithmetic;
}

int ncnn_option_get_use_int8_packed(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_int8_packed;
}

int ncnn_option_get_use_int8_storage(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_int8_storage;
}

int ncnn_option_get_use_int8_arithmetic(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_int8_arithmetic;
}

int ncnn_option_get_use_bf16_packed(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_bf16_packed;
}

int ncnn_option_get_use_bf16_storage(const ncnn_option_t opt)
{
return ((const Option*)opt)->use_bf16_storage;
}

int ncnn_option_get_use_shader_local_memory(const ncnn_option_t opt)
{
#if NCNN_VULKAN
return ((const Option*)opt)->use_vulkan_compute;
return ((const Option*)opt)->use_shader_local_memory;
#else
(void)opt;
return 0;
#endif
}

int ncnn_option_get_use_cooperative_matrix(const ncnn_option_t opt)
{
#if NCNN_VULKAN
return ((const Option*)opt)->use_cooperative_matrix;
#else
(void)opt;
return 0;
#endif
}

void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int use_vulkan_compute)
void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int enable)
{
#if NCNN_VULKAN
((Option*)opt)->use_vulkan_compute = use_vulkan_compute;
((Option*)opt)->use_vulkan_compute = enable;
#else
(void)opt;
(void)use_vulkan_compute;
(void)enable;
#endif
}

void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_local_pool_allocator = enable;
}

void ncnn_option_set_use_winograd_convolution(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_winograd_convolution = enable;
}

void ncnn_option_set_use_sgemm_convolution(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_sgemm_convolution = enable;
}

void ncnn_option_set_use_packing_layout(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_packing_layout = enable;
}

void ncnn_option_set_use_fp16_packed(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_fp16_packed = enable;
}

void ncnn_option_set_use_fp16_storage(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_fp16_storage = enable;
}

void ncnn_option_set_use_fp16_arithmetic(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_fp16_arithmetic = enable;
}

void ncnn_option_set_use_int8_packed(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_int8_packed = enable;
}

void ncnn_option_set_use_int8_storage(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_int8_storage = enable;
}

void ncnn_option_set_use_int8_arithmetic(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_int8_arithmetic = enable;
}

void ncnn_option_set_use_bf16_packed(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_bf16_packed = enable;
}

void ncnn_option_set_use_bf16_storage(ncnn_option_t opt, int enable)
{
((Option*)opt)->use_bf16_storage = enable;
}

void ncnn_option_set_use_shader_local_memory(ncnn_option_t opt, int enable)
{
#if NCNN_VULKAN
((Option*)opt)->use_shader_local_memory = enable;
#else
(void)opt;
(void)enable;
#endif
}

void ncnn_option_set_use_cooperative_matrix(ncnn_option_t opt, int enable)
{
#if NCNN_VULKAN
((Option*)opt)->use_cooperative_matrix = enable;
#else
(void)opt;
(void)enable;
#endif
}

Expand Down Expand Up @@ -1105,7 +1255,12 @@ int ncnn_layer_get_support_inplace(const ncnn_layer_t layer)

int ncnn_layer_get_support_vulkan(const ncnn_layer_t layer)
{
#if NCNN_VULKAN
return ((const Layer*)layer->pthis)->support_vulkan;
#else
(void)layer;
return 0;
#endif
}

int ncnn_layer_get_support_packing(const ncnn_layer_t layer)
Expand All @@ -1125,7 +1280,12 @@ int ncnn_layer_get_support_fp16_storage(const ncnn_layer_t layer)

int ncnn_layer_get_support_vulkan_packing(const ncnn_layer_t layer)
{
#if NCNN_VULKAN
return ((const Layer*)layer->pthis)->support_vulkan_packing;
#else
(void)layer;
return 0;
#endif
}

int ncnn_layer_get_support_any_packing(const ncnn_layer_t layer)
Expand All @@ -1135,7 +1295,12 @@ int ncnn_layer_get_support_any_packing(const ncnn_layer_t layer)

int ncnn_layer_get_support_vulkan_any_packing(const ncnn_layer_t layer)
{
#if NCNN_VULKAN
return ((const Layer*)layer->pthis)->support_vulkan_any_packing;
#else
(void)layer;
return 0;
#endif
}

void ncnn_layer_set_one_blob_only(ncnn_layer_t layer, int enable)
Expand All @@ -1150,7 +1315,12 @@ void ncnn_layer_set_support_inplace(ncnn_layer_t layer, int enable)

void ncnn_layer_set_support_vulkan(ncnn_layer_t layer, int enable)
{
#if NCNN_VULKAN
((Layer*)layer->pthis)->support_vulkan = enable;
#else
(void)layer;
(void)enable;
#endif
}

void ncnn_layer_set_support_packing(ncnn_layer_t layer, int enable)
Expand All @@ -1170,7 +1340,12 @@ void ncnn_layer_set_support_fp16_storage(ncnn_layer_t layer, int enable)

void ncnn_layer_set_support_vulkan_packing(ncnn_layer_t layer, int enable)
{
#if NCNN_VULKAN
((Layer*)layer->pthis)->support_vulkan_packing = enable;
#else
(void)layer;
(void)enable;
#endif
}

void ncnn_layer_set_support_any_packing(ncnn_layer_t layer, int enable)
Expand All @@ -1180,7 +1355,12 @@ void ncnn_layer_set_support_any_packing(ncnn_layer_t layer, int enable)

void ncnn_layer_set_support_vulkan_any_packing(ncnn_layer_t layer, int enable)
{
#if NCNN_VULKAN
((Layer*)layer->pthis)->support_vulkan_any_packing = enable;
#else
(void)layer;
(void)enable;
#endif
}

int ncnn_layer_get_bottom_count(const ncnn_layer_t layer)
Expand Down
34 changes: 30 additions & 4 deletions src/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,40 @@ NCNN_EXPORT void ncnn_option_destroy(ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_num_threads(const ncnn_option_t opt);
NCNN_EXPORT void ncnn_option_set_num_threads(ncnn_option_t opt, int num_threads);

NCNN_EXPORT int ncnn_option_get_use_local_pool_allocator(const ncnn_option_t opt);
NCNN_EXPORT void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int use_local_pool_allocator);

NCNN_EXPORT void ncnn_option_set_blob_allocator(ncnn_option_t opt, ncnn_allocator_t allocator);
NCNN_EXPORT void ncnn_option_set_workspace_allocator(ncnn_option_t opt, ncnn_allocator_t allocator);

NCNN_EXPORT int ncnn_option_get_use_vulkan_compute(const ncnn_option_t opt);
NCNN_EXPORT void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int use_vulkan_compute);
NCNN_EXPORT int ncnn_option_get_use_local_pool_allocator(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_winograd_convolution(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_sgemm_convolution(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_packing_layout(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_fp16_packed(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_fp16_storage(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_fp16_arithmetic(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_int8_packed(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_int8_storage(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_int8_arithmetic(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_bf16_packed(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_bf16_storage(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_shader_local_memory(const ncnn_option_t opt);
NCNN_EXPORT int ncnn_option_get_use_cooperative_matrix(const ncnn_option_t opt);

NCNN_EXPORT void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_winograd_convolution(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_sgemm_convolution(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_packing_layout(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_fp16_packed(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_fp16_storage(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_fp16_arithmetic(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_int8_packed(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_int8_storage(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_int8_arithmetic(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_bf16_packed(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_bf16_storage(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_shader_local_memory(ncnn_option_t opt, int enable);
NCNN_EXPORT void ncnn_option_set_use_cooperative_matrix(ncnn_option_t opt, int enable);

/* mat api */
typedef struct __ncnn_mat_t* ncnn_mat_t;
Expand Down
Loading
Loading