This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Allow std::malloc in device function
ClosedPublic

Authored by yaxunl on May 19 2023, 7:31 AM.

Details

Summary

D106463 caused a regression that prevents std::malloc to be
called in the device function, which is allowed with nvcc.

Basically the standard C++ header introducing malloc in
std namespace by using ::malloc. The device ::malloc
function needs to be declared before using ::malloc
to be introduced into std namespace.

Revert D106463 and add a test.

Diff Detail

Event Timeline

yaxunl created this revision.May 19 2023, 7:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 7:31 AM
yaxunl requested review of this revision.May 19 2023, 7:31 AM
tra accepted this revision.May 19 2023, 10:18 AM

LGTM.

clang/test/Headers/Inputs/include/math.h
108–109

Why were these functions removed? It does not seem related to the changes in the patch?

This revision is now accepted and ready to land.May 19 2023, 10:18 AM
yaxunl added inline comments.May 19 2023, 11:01 AM
clang/test/Headers/Inputs/include/math.h
108–109

These functions caused failure in the added lit test.

For C++, max/min are defined as templates in <algorithm>. There is no max/min in either standard C or C++ math.h. Their existence cause false alarms in lit tests. Removing them to be consistent with standard C/C++ headers.

tra added inline comments.May 19 2023, 11:30 AM
clang/test/Headers/Inputs/include/math.h
108–109

I suspect those may have been used for some CUDA tests. CUDA headers used to define ::min() and ::max().

As long as it does not affect the tests, removing them is fine.

This revision was landed with ongoing or failed builds.May 23 2023, 8:53 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 8:53 AM