/* * SPDX-FileCopyrightText: Copyright 2020, 2022 Arm Limited and/or its affiliates * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include "mlw_encode.h" #include "mlw_decode.h" #define UNCHECKED(call) (void)call static void fatal_error(const char *format, ...) { va_list ap; va_start (ap, format); vfprintf(stderr, format, ap); va_end(ap); exit(1); } static void print_usage(void) { printf("Usage:\n"); printf(" Encode: ./mlw_codec [] [-o ] infiles.bin\n"); printf(" Decode: ./mlw_codec [] -d [-o ] infiles.mlw\n"); printf("\n"); printf("Options:\n"); printf(" -w The uncompressed weight file is an int16_t (word) stream.\n"); printf(" This is to support 9bit signed weights. Little endian is assuemd.\n"); printf(" The default format is int8_t (byte) stream (if -w is not specified)\n"); printf("\n"); } // Read file into allocated buffer. Return length in bytes. static size_t read_file( FILE *f, uint8_t **buf) { size_t rsize = 0; UNCHECKED(fseek(f, 0, SEEK_END)); long size = ftell(f); size = size < 0 ? 0 : size; UNCHECKED(fseek(f, 0, SEEK_SET)); *buf = malloc(size); if (*buf) { rsize = fread(*buf, 1, size, f); assert(rsize==size); } UNCHECKED(fclose(f)); return rsize; } #define MAX_INFILES 1000 int main(int argc, char *argv[]) { int c, decode=0, inbuf_size, outbuf_size; char *infile_name[MAX_INFILES], *outfile_name=0; uint8_t *inbuf=0, *outbuf=0; FILE *infile, *outfile=0; int verbose=0, infile_idx=0; int int16_format=0; if (argc==1) { print_usage(); exit(1); } // Parse command line options while( optind < argc) { // Parse options while ((c = getopt (argc, argv, "di:o:v:w?")) != -1) { switch (c) { case 'd': decode=1; break; case 'i': assert(infile_idx