Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yamaguchi1024 committed Oct 5, 2024
1 parent b63da8e commit 32d34ba
Show file tree
Hide file tree
Showing 13 changed files with 515 additions and 35 deletions.
7 changes: 6 additions & 1 deletion src/exo/libs/externs.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ def typecheck(self, args):
return atyp

def globl(self, prim_type):
return "#include <math.h>"
return f"""
#include <math.h>
{prim_type} sigmoid({prim_type} x) {{
return 1 / (1 + exp(-x));
}}
"""

def interpret(self, args):
return math.sigmoid(args[0])

Check warning on line 218 in src/exo/libs/externs.py

View check run for this annotation

Codecov / codecov/patch

src/exo/libs/externs.py#L218

Added line #L218 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void matmul_on_cpu( c_code_str_Context *ctxt, int_fast32_t N, int_fast32_t M, co
#include "gemm_acc_malloc.h"
#include <include/gemmini.h>
#include "gemm_malloc.h"
double _relu_(double x) {
int8_t _relu_int8_t(int8_t x) {
if (x > 0.0) return x;
else return 0.0;
}
Expand Down
45 changes: 45 additions & 0 deletions tests/golden/test_externs/test_expf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,48 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : i8[16] @DRAM,
// y : i8[16] @DRAM
// )
void foo( void *ctxt, const int8_t* x, int8_t* y );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
45 changes: 45 additions & 0 deletions tests/golden/test_externs/test_fmaxf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,48 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : f32[16] @DRAM,
// y : f32[16] @DRAM
// )
void foo( void *ctxt, const float* x, float* y );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
44 changes: 44 additions & 0 deletions tests/golden/test_externs/test_relu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,47 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : f32[16] @DRAM
// )
void foo( void *ctxt, float* x );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
44 changes: 44 additions & 0 deletions tests/golden/test_externs/test_relu2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,47 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : f32[16] @DRAM
// )
void foo( void *ctxt, float* x );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
46 changes: 46 additions & 0 deletions tests/golden/test_externs/test_relu3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,49 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : f32[16] @DRAM,
// y : f32[16] @DRAM,
// z : f32[16] @DRAM
// )
void foo( void *ctxt, const float* x, const float* y, float* z );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
44 changes: 44 additions & 0 deletions tests/golden/test_externs/test_relu4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,47 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : i8[16] @DRAM
// )
void foo( void *ctxt, int8_t* x );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
46 changes: 46 additions & 0 deletions tests/golden/test_externs/test_select.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,49 @@ for (int_fast32_t i = 0; i < 16; i++) {
}
}


#pragma once
#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern "C" {
#endif


#include <stdint.h>
#include <stdbool.h>

// Compiler feature macros adapted from Hedley (public domain)
// https://github.com/nemequ/hedley

#if defined(__has_builtin)
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin)
#else
# define EXO_HAS_BUILTIN(builtin) (0)
#endif

#if EXO_HAS_BUILTIN(__builtin_assume)
# define EXO_ASSUME(expr) __builtin_assume(expr)
#elif EXO_HAS_BUILTIN(__builtin_unreachable)
# define EXO_ASSUME(expr) \
((void)((expr) ? 1 : (__builtin_unreachable(), 1)))
#else
# define EXO_ASSUME(expr) ((void)(expr))
#endif



// foo(
// x : i8[16] @DRAM,
// y : i8[16] @DRAM,
// z : i8[16] @DRAM
// )
void foo( void *ctxt, const int8_t* x, const int8_t* y, int8_t* z );



#ifdef __cplusplus
}
#endif
#endif // TEST_H
Loading

0 comments on commit 32d34ba

Please sign in to comment.