diff --git a/CMakeLists.txt b/CMakeLists.txt index 5203492..f6c34c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") # Set default flags (from opus-ng build) -set(CMAKE_C_FLAGS "-O2 -fvisibility=hidden -fstack-protector-strong -W -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes") +set(CMAKE_C_FLAGS "-O2 -fstack-protector-strong -W -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -DHAVE_CONFIG_H") if(NOT CMAKE_CROSSCOMPILING) # Python tells us the CFLAGS we need for Embedding Python in a C lib. diff --git a/cmake/BuildOpus.cmake b/cmake/BuildOpus.cmake index bc655dd..a3766d4 100644 --- a/cmake/BuildOpus.cmake +++ b/cmake/BuildOpus.cmake @@ -15,6 +15,7 @@ if(APPLE AND BUILD_OSX_UNIVERSAL) ExternalProject_Add(build_opus_x86 DOWNLOAD_EXTRACT_TIMESTAMP NO BUILD_IN_SOURCE 1 + PATCH_COMMAND sh -c "patch dnn/nnet.h < ${CMAKE_SOURCE_DIR}/src/opus-export.diff" CONFIGURE_COMMAND ${CONFIGURE_COMMAND} --host=x86_64-apple-darwin --target=x86_64-apple-darwin CFLAGS=-arch\ x86_64\ -O2\ -mmacosx-version-min=10.11 BUILD_COMMAND $(MAKE) INSTALL_COMMAND "" @@ -23,6 +24,7 @@ ExternalProject_Add(build_opus_x86 ExternalProject_Add(build_opus_arm DOWNLOAD_EXTRACT_TIMESTAMP NO BUILD_IN_SOURCE 1 + PATCH_COMMAND sh -c "patch dnn/nnet.h < ${CMAKE_SOURCE_DIR}/src/opus-export.diff" CONFIGURE_COMMAND ${CONFIGURE_COMMAND} --host=aarch64-apple-darwin --target=aarch64-apple-darwin CFLAGS=-arch\ arm64\ -O2\ -mmacosx-version-min=10.11 BUILD_COMMAND $(MAKE) INSTALL_COMMAND "" @@ -56,6 +58,7 @@ else(APPLE AND BUILD_OSX_UNIVERSAL) ExternalProject_Add(build_opus DOWNLOAD_EXTRACT_TIMESTAMP NO BUILD_IN_SOURCE 1 + PATCH_COMMAND sh -c "patch dnn/nnet.h < ${CMAKE_SOURCE_DIR}/src/opus-export.diff" CONFIGURE_COMMAND ${CONFIGURE_COMMAND} BUILD_COMMAND $(MAKE) INSTALL_COMMAND "" @@ -72,5 +75,5 @@ set_target_properties(opus PROPERTIES IMPORTED_IMPLIB "${BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}" ) -include_directories(${SOURCE_DIR}/dnn ${SOURCE_DIR}/celt ${SOURCE_DIR}/include) +include_directories(${SOURCE_DIR}/dnn ${SOURCE_DIR}/celt ${SOURCE_DIR}/include ${SOURCE_DIR}) endif(APPLE AND BUILD_OSX_UNIVERSAL) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2528c62..d1bf376 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,3 +28,6 @@ set_target_properties(radecore PROPERTIES SOVERSION "0.1" PUBLIC_HEADER "rade_api.h" ) + +add_executable(test_rade_enc test_rade_enc.c) +target_link_libraries(test_rade_enc radecore opus m) diff --git a/src/opus-export.diff b/src/opus-export.diff new file mode 100644 index 0000000..36446af --- /dev/null +++ b/src/opus-export.diff @@ -0,0 +1,25 @@ +30a31,32 +> #define RADE_EXPORT __attribute__((visibility("default"))) +> +88,93c90,95 +< void compute_generic_dense(const LinearLayer *layer, float *output, const float *input, int activation, int arch); +< void compute_generic_gru(const LinearLayer *input_weights, const LinearLayer *recurrent_weights, float *state, const float *in, int arch); +< void compute_generic_conv1d(const LinearLayer *layer, float *output, float *mem, const float *input, int input_size, int activation, int arch); +< void compute_generic_conv1d_dilation(const LinearLayer *layer, float *output, float *mem, const float *input, int input_size, int dilation, int activation, int arch); +< void compute_glu(const LinearLayer *layer, float *output, const float *input, int arch); +< void compute_gated_activation(const LinearLayer *layer, float *output, const float *input, int activation, int arch); +--- +> void RADE_EXPORT compute_generic_dense(const LinearLayer *layer, float *output, const float *input, int activation, int arch); +> void RADE_EXPORT compute_generic_gru(const LinearLayer *input_weights, const LinearLayer *recurrent_weights, float *state, const float *in, int arch); +> void RADE_EXPORT compute_generic_conv1d(const LinearLayer *layer, float *output, float *mem, const float *input, int input_size, int activation, int arch); +> void RADE_EXPORT compute_generic_conv1d_dilation(const LinearLayer *layer, float *output, float *mem, const float *input, int input_size, int dilation, int activation, int arch); +> void RADE_EXPORT compute_glu(const LinearLayer *layer, float *output, const float *input, int arch); +> void RADE_EXPORT compute_gated_activation(const LinearLayer *layer, float *output, const float *input, int activation, int arch); +108c110 +< int linear_init(LinearLayer *layer, const WeightArray *arrays, +--- +> int RADE_EXPORT linear_init(LinearLayer *layer, const WeightArray *arrays, +119c121 +< int conv2d_init(Conv2dLayer *layer, const WeightArray *arrays, +--- +> int RADE_EXPORT conv2d_init(Conv2dLayer *layer, const WeightArray *arrays, diff --git a/src/rade_core.h b/src/rade_core.h index 0b1f787..e1827dc 100644 --- a/src/rade_core.h +++ b/src/rade_core.h @@ -10,7 +10,8 @@ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + documentatio + n and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -32,7 +33,7 @@ #include "opus_types.h" -typedef struct RADEDec RADEDec; +typedef struct RADEDec RADEDec; typedef struct RADEEnc RADEEnc; typedef struct RADEDecStruct RADEDecState; typedef struct RADEEncStruct RADEEncState; diff --git a/src/rade_enc_data.h b/src/rade_enc_data.h index 778041b..36c2edf 100644 --- a/src/rade_enc_data.h +++ b/src/rade_enc_data.h @@ -99,5 +99,6 @@ struct RADEEnc { }; int init_radeenc(RADEEnc *model, const WeightArray *arrays); +extern const WeightArray radeenc_arrays[]; #endif /* RADE_ENC_DATA_H */ diff --git a/src/test_rade_enc.c b/src/test_rade_enc.c new file mode 100644 index 0000000..c6a8996 --- /dev/null +++ b/src/test_rade_enc.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "rade_core.h" +#include "rade_enc.h" +#include "rade_enc_data.h" + +int opus_select_arch(void); + +int main(void) +{ + RADEEnc enc_model; + RADEEncState enc_state; + + if (init_radeenc(&enc_model, rdovaeenc_arrays) != 0) { + fprintf(stderr, "Error initialising encoder model\n"); + exit(1); + } + rade_init_encoder(&enc_state); + + int n_features_in = enc_model.enc_dense1.nb_inputs; + assert(enc_model.enc_zdense.nb_outputs == RADE_LATENT_DIM); + fprintf(stderr, "n_features_in: %d n_z_out: %d", n_features_in, enc_model.enc_zdense.nb_outputs); + float features[n_features_in]; + float z[RADE_LATENT_DIM]; + int arch = opus_select_arch(); + + while((size_t)n_features_in == fread(features, sizeof(float), n_features_in, stdin)) { + rade_core_encoder(&enc_state, &enc_model, z, features, arch); + fwrite(z, sizeof(float), RADE_LATENT_DIM, stdout); + fflush(stdout); + } + + return 0; +}