Skip to content

Commit

Permalink
wip - first build of libradecore
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Nov 8, 2024
1 parent df81adb commit 5482f85
Show file tree
Hide file tree
Showing 10 changed files with 467,286 additions and 10 deletions.
3 changes: 1 addition & 2 deletions export_rade_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ def c_export(args, model):
dec_writer = CWriter(os.path.join(args.output_dir, "rade_dec_data"), message=message, model_struct_name='RADEDec')
#stats_writer = CWriter(os.path.join(args.output_dir, "rade_stats_data"), message=message, enable_binary_blob=False)
constants_writer = CWriter(os.path.join(args.output_dir, "rade_constants"), message=message, header_only=True, enable_binary_blob=False)
xmlout = open("stats.xml", "w")

# some custom includes
for writer in [enc_writer, dec_writer]:
writer.header.write(
f"""
#include "opus_types.h"
#include "rade.h"
#include "rade_core.h"
#include "rade_constants.h"
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ target_link_libraries(radae_rx rade Python3::Python)
target_include_directories(radae_rx PRIVATE
"$<TARGET_PROPERTY:Python3::NumPy,INTERFACE_INCLUDE_DIRECTORIES>")

add_library(radecore rade_enc.c rade_enc_data.c)
set_target_properties(radecore PROPERTIES
SOVERSION "0.1"
PUBLIC_HEADER "rade_api.h"
)
25 changes: 25 additions & 0 deletions src/rade_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Auto generated from checkpoint checkpoint_epoch_100.pth */


#ifndef RADE_CONSTANTS_H
#define RADE_CONSTANTS_H

#include "nnet.h"


#define RADE_NUM_FEATURES 21

#define RADE_LATENT_DIM 80

#define RADE_MAX_RNN_NEURONS 96

#define RADE_MAX_CONV_INPUTS 1536

#define RADE_ENC_MAX_RNN_NEURONS 1536

#define RADE_ENC_MAX_CONV_INPUTS 1536

#define RADE_DEC_MAX_RNN_NEURONS 96


#endif /* RADE_CONSTANTS_H */
46 changes: 46 additions & 0 deletions src/rade_core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright (c) 2022 Amazon
Written by Jan Buethe */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef RADECORE_H
#define RADECORE_H

#include <stdlib.h>

#include "opus_types.h"

typedef struct RADEDec RADEDec;
typedef struct RADEEnc RADEEnc;
typedef struct RADEDecStruct RADEDecState;
typedef struct RADEEncStruct RADEEncState;

void rade_init_encoder(RADEEncState *enc_state);
void rade_core_encoder(RADEEncState *enc_state, const RADEEnc *model, float *z, const float *features, int arch);

void rade_init_decoder(RADEDecState *dec_state);
void rade_core_decoder(RADEDecState *dec_state, const RADEDec *model, float *features, const float *z_hat);

#endif
230,335 changes: 230,335 additions & 0 deletions src/rade_dec_data.c

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions src/rade_dec_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* Auto generated from checkpoint checkpoint_epoch_100.pth */


#ifndef RADE_DEC_DATA_H
#define RADE_DEC_DATA_H

#include "nnet.h"


#include "opus_types.h"

#include "rade.h"

#include "rade_constants.h"


#define DEC_DENSE1_OUT_SIZE 96

#define DEC_GLU1_OUT_SIZE 96

#define DEC_GLU2_OUT_SIZE 96

#define DEC_GLU3_OUT_SIZE 96

#define DEC_GLU4_OUT_SIZE 96

#define DEC_GLU5_OUT_SIZE 96

#define DEC_OUTPUT_OUT_SIZE 84

#define DEC_GRU1_OUT_SIZE 96

#define DEC_GRU1_STATE_SIZE 96

#define DEC_GRU2_OUT_SIZE 96

#define DEC_GRU2_STATE_SIZE 96

#define DEC_GRU3_OUT_SIZE 96

#define DEC_GRU3_STATE_SIZE 96

#define DEC_GRU4_OUT_SIZE 96

#define DEC_GRU4_STATE_SIZE 96

#define DEC_GRU5_OUT_SIZE 96

#define DEC_GRU5_STATE_SIZE 96

#define DEC_CONV1_OUT_SIZE 32

#define DEC_CONV1_IN_SIZE 192

#define DEC_CONV1_STATE_SIZE (192 * (1))

#define DEC_CONV1_DELAY 0

#define DEC_CONV2_OUT_SIZE 32

#define DEC_CONV2_IN_SIZE 320

#define DEC_CONV2_STATE_SIZE (320 * (1))

#define DEC_CONV2_DELAY 0

#define DEC_CONV3_OUT_SIZE 32

#define DEC_CONV3_IN_SIZE 448

#define DEC_CONV3_STATE_SIZE (448 * (1))

#define DEC_CONV3_DELAY 0

#define DEC_CONV4_OUT_SIZE 32

#define DEC_CONV4_IN_SIZE 576

#define DEC_CONV4_STATE_SIZE (576 * (1))

#define DEC_CONV4_DELAY 0

#define DEC_CONV5_OUT_SIZE 32

#define DEC_CONV5_IN_SIZE 704

#define DEC_CONV5_STATE_SIZE (704 * (1))

#define DEC_CONV5_DELAY 0

struct RADEDec {
LinearLayer dec_dense1;
LinearLayer dec_glu1;
LinearLayer dec_glu2;
LinearLayer dec_glu3;
LinearLayer dec_glu4;
LinearLayer dec_glu5;
LinearLayer dec_output;
LinearLayer dec_gru1_input;
LinearLayer dec_gru1_recurrent;
LinearLayer dec_gru2_input;
LinearLayer dec_gru2_recurrent;
LinearLayer dec_gru3_input;
LinearLayer dec_gru3_recurrent;
LinearLayer dec_gru4_input;
LinearLayer dec_gru4_recurrent;
LinearLayer dec_gru5_input;
LinearLayer dec_gru5_recurrent;
LinearLayer dec_conv1;
LinearLayer dec_conv2;
LinearLayer dec_conv3;
LinearLayer dec_conv4;
LinearLayer dec_conv5;
};

int init_radedec(RADEDec *model, const WeightArray *arrays);

#endif /* RADE_DEC_DATA_H */
23 changes: 15 additions & 8 deletions src/rade_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
#include "os_support.h"
#include "rade_constants.h"

void rade_init_encoder(RADEEncState *enc_state)
{
memset(enc_state, 0, sizeof(*enc_state));

}

static void conv1_cond_init(float *mem, int len, int dilation, int *init)
{
if (!*init) {
Expand All @@ -45,18 +51,19 @@ static void conv1_cond_init(float *mem, int len, int dilation, int *init)
*init = 1;
}

void rade_encode_dframe(
RDOVAEEncState *enc_state, /* io: encoder state */
const RDOVAEEnc *model,
const float *input, /* i: double feature frame (concatenated) */
int arch
void rade_core_encoder(
RADEEncState *enc_state,
const RADEEnc *model,
float *latents,
const float *input,
int arch
)
{
//float padded_latents[DRED_PADDED_LATENT_DIM];
//float padded_state[DRED_PADDED_STATE_DIM];
float buffer[ENC_DENSE1_OUT_SIZE + ENC_GRU1_OUT_SIZE + ENC_GRU2_OUT_SIZE + ENC_GRU3_OUT_SIZE + ENC_GRU4_OUT_SIZE + ENC_GRU5_OUT_SIZE
+ ENC_CONV1_OUT_SIZE + ENC_CONV2_OUT_SIZE + ENC_CONV3_OUT_SIZE + ENC_CONV4_OUT_SIZE + ENC_CONV5_OUT_SIZE];
float state_hidden[GDENSE1_OUT_SIZE];
//float state_hidden[GDENSE1_OUT_SIZE];
int output_index = 0;

/* run encoder stack and concatenate output in buffer*/
Expand Down Expand Up @@ -98,8 +105,8 @@ void rade_encode_dframe(
compute_generic_conv1d_dilation(&model->enc_conv5, &buffer[output_index], enc_state->conv5_state, buffer, output_index, 2, ACTIVATION_TANH, arch);
output_index += ENC_CONV5_OUT_SIZE;

compute_generic_dense(&model->enc_zdense, padded_latents, buffer, ACTIVATION_LINEAR, arch);
OPUS_COPY(latents, padded_latents, RADE_LATENT_DIM);
compute_generic_dense(&model->enc_zdense, latents, buffer, ACTIVATION_LINEAR, arch);
//OPUS_COPY(latents, padded_latents, RADE_LATENT_DIM);

// DR: don't think we need this?
#ifdef RM_ME
Expand Down
52 changes: 52 additions & 0 deletions src/rade_enc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Copyright (c) 2022 Amazon
Written by Jan Buethe */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef RADE_ENC_H
#define RADE_ENC_H

#include "rade_core.h"

#include "rade_enc_data.h"

struct RADEEncStruct {
int initialized;
float gru1_state[ENC_GRU1_STATE_SIZE];
float gru2_state[ENC_GRU2_STATE_SIZE];
float gru3_state[ENC_GRU3_STATE_SIZE];
float gru4_state[ENC_GRU4_STATE_SIZE];
float gru5_state[ENC_GRU5_STATE_SIZE];
float conv1_state[ENC_CONV1_STATE_SIZE];
float conv2_state[2*ENC_CONV2_STATE_SIZE];
float conv3_state[2*ENC_CONV3_STATE_SIZE];
float conv4_state[2*ENC_CONV4_STATE_SIZE];
float conv5_state[2*ENC_CONV5_STATE_SIZE];
};

void rade_encode_dframe(RADEEncState *enc_state, const RADEEnc *model, float *latents, float *initial_state, const float *input);


#endif
Loading

0 comments on commit 5482f85

Please sign in to comment.