forked from nnstreamer/nntrainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows writing FP16-independent code without breaking the current code. This is a non-invasive subset of nnstreamer#2403 to address the concern of nnstreamer#2403 (comment) I believe nntrainer can use this during the refactoring so that we do not introduce additional code divergences. Signed-off-by: MyungJoo Ham <[email protected]>
- Loading branch information
Showing
6 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* @see https://github.com/nnstreamer/nntrainer | ||
* @author Jijoong Moon <[email protected]> | ||
* @bug No known bugs except for NYI items | ||
* @todo Move FP16 macros to somewhere common enough. | ||
* | ||
*/ | ||
|
||
|
@@ -20,6 +21,7 @@ | |
#include <iosfwd> | ||
|
||
#include <bitset> | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
#ifdef ENABLE_FP16 | ||
|
@@ -28,8 +30,56 @@ | |
#else | ||
#define _FP16 _Float16 | ||
#endif | ||
#else /* !ENABLE_FP16 */ | ||
/* Keep the FP16 programming interface, but don't allow using it in run-time */ | ||
#define _FP16 uint16_t | ||
#endif | ||
|
||
/** | ||
* @brief Check if fp16 is enabled. Let's not use #if/#endif for FP16 elsewhere | ||
* @todo Move to a proper header file! | ||
*/ | ||
static inline bool is_fp16_enabled() { | ||
/** @todo if this becomes runtime conditionals, use likely/unlikely */ | ||
#ifdef ENABLE_FP16 | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
#ifdef ENABLE_FP16 | ||
#define THROW_UNLESS_FP16_ENABLED (void)0 | ||
#define FP16_REQUIRED(...) \ | ||
do { \ | ||
__VA_ARGS; \ | ||
} while (0) | ||
#else | ||
#define THROW_UNLESS_FP16_ENABLED \ | ||
do { \ | ||
throw std::runtime_error("The data type 'fp16' is not supported."); \ | ||
} while (0) | ||
#define FP16_REQUIRED(...) \ | ||
do { \ | ||
throw std::runtime_error("The data type 'fp16' is not supported."); \ | ||
} while (0) | ||
#endif | ||
/** If FP16-enable becomes dynamic, apply the following code. | ||
#define THROW_UNLESS_FP16_ENABLED \ | ||
do { \ | ||
if (unlikely(!is_fp16_enabled())) \ | ||
throw std::runtime_error("The data type 'fp16' is not supported."); \ | ||
} while (0) | ||
#define FP16_REQUIRED(...) \ | ||
do { \ | ||
if (likely(is_fp16_enabled())) { \ | ||
__VA_ARGS; \ | ||
} else { \ | ||
throw std::runtime_error("The data type 'fp16' is not supported."); \ | ||
} \ | ||
} while (0) | ||
*/ | ||
|
||
namespace ml { | ||
namespace train { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters