Align example models to 64-bit boundaries to guarantee correctness for all 64-bit flatbuffer accesses. Aligning 64-bit datatypes to 32-bits can cause memory errors on some architectures.
PiperOrigin-RevId: 312570183 Change-Id: I023dc868d9ec3026d23d461a21fcfe0f6251150d
This commit is contained in:
parent
4829f33e1f
commit
4148ee2e95
@ -15,19 +15,8 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h"
|
||||
|
||||
// We need to keep the data array aligned on some architectures.
|
||||
#ifdef __has_attribute
|
||||
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
|
||||
#else
|
||||
#define HAVE_ATTRIBUTE(x) 0
|
||||
#endif
|
||||
#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4)))
|
||||
#else
|
||||
#define DATA_ALIGN_ATTRIBUTE
|
||||
#endif
|
||||
|
||||
const unsigned char g_keyword_scrambled_model_data[] DATA_ALIGN_ATTRIBUTE = {
|
||||
// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses.
|
||||
alignas(8) const unsigned char g_keyword_scrambled_model_data[] = {
|
||||
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
|
||||
0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00,
|
||||
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xd0, 0x6e, 0x00, 0x00,
|
||||
|
@ -24,19 +24,8 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/lite/micro/examples/hello_world/model.h"
|
||||
|
||||
// We need to keep the data array aligned on some architectures.
|
||||
#ifdef __has_attribute
|
||||
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
|
||||
#else
|
||||
#define HAVE_ATTRIBUTE(x) 0
|
||||
#endif
|
||||
#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4)))
|
||||
#else
|
||||
#define DATA_ALIGN_ATTRIBUTE
|
||||
#endif
|
||||
|
||||
const unsigned char g_model[] DATA_ALIGN_ATTRIBUTE = {
|
||||
// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses.
|
||||
alignas(8) const unsigned char g_model[] = {
|
||||
0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x12, 0x00,
|
||||
0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
|
||||
0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
|
@ -19,19 +19,8 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h"
|
||||
|
||||
// We need to keep the data array aligned on some architectures.
|
||||
#ifdef __has_attribute
|
||||
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
|
||||
#else
|
||||
#define HAVE_ATTRIBUTE(x) 0
|
||||
#endif
|
||||
#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4)))
|
||||
#else
|
||||
#define DATA_ALIGN_ATTRIBUTE
|
||||
#endif
|
||||
|
||||
const unsigned char g_magic_wand_model_data[] DATA_ALIGN_ATTRIBUTE = {
|
||||
// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses.
|
||||
alignas(8) const unsigned char g_magic_wand_model_data[] = {
|
||||
0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x12, 0x00,
|
||||
0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
|
||||
0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
|
Loading…
Reference in New Issue
Block a user