+
Skip to content

Conversation

ViliamVadocz
Copy link
Contributor

Closes #407

Math Constant macros were not included which caused issues when trying to compile.
While at it, I also changed tanh to tanhf and added a constexpr where appropriate.

@@ -1,4 +1,6 @@
#include "unary_op_macros.cuh"
#define _USE_MATH_DEFINES
Copy link
Owner

@coreylowman coreylowman Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do exactly? Also have you tried compiling all this on a non GNU and MSVC device (I can verify on my dev machine later)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the MSVC documentation

The math constants aren't defined in Standard C/C++. To use them, you must first define _USE_MATH_DEFINES, and then include <cmath> or <math.h>.

The #define is used here to essentially set a flag so that the math constants are defined in the math.h header file.
If we take a look at the (relevant documentation) we can see how it works:

A #define without a token-string removes occurrences of identifier from the source file. The identifier remains defined and can be tested by using the #if defined and #ifdef directives.

(Emphasis mine)


I have not tested with other toolchains than stable-x86_64-pc-windows-gnu and stable-x86_64-pc-windows-msvc.

@ViliamVadocz
Copy link
Contributor Author

ViliamVadocz commented Jan 27, 2023

Apparently there exist also floating point versions of these constants which are available if _GNU_SOURCE is also defined. The constants would be appended with a lowercase f to get the floating point version. Info: https://www.gnu.org/software/libc/manual/html_node/Mathematical-Constants.html


EDIT: This does not seem to work on MSVC

Copy link
Owner

@coreylowman coreylowman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! thanks for the added details

@coreylowman coreylowman merged commit 6eb67c8 into coreylowman:main Jan 30, 2023
@ViliamVadocz ViliamVadocz deleted the fix-gelu-cuda branch February 4, 2023 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GELU cuda kernel does not compile, missing header

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载