Skip to content

c10/util/BFloat16-math.h has undefined behavior #144495

Open
@swolchok

Description

@swolchok

🐛 Describe the bug

Per https://en.cppreference.com/w/cpp/language/extending_std:

It is undefined behavior to add declarations or definitions to namespace std or to any namespace nested within std, with a few exceptions noted below.

The "exceptions noted below" do not seem to include what we're doing in BFloat16-math.h, and specifically don't include adding overloads of functions that take program-defined types.

This problem is currently "theoretical" in that I am not aware of practical issues resulting from this header at this time.

To fix this, we would need to at least put the functions in BFloat16-math.h into a namespace other than std (either c10 or a new one, like say c10_math). Then, we could either:

  • have callers do using std::pow and all the other cmath functions, and rely on ADL to select the c10/c10_math version for half/BFloat16
  • using all the std:: functions into our namespace (which IMO argues toward that namespace being a new one like c10_math).

Versions

N/A

cc @malfet @seemethere @manuelcandales @SherlockNoMad @angelayi

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: buildBuild system issuesmodule: core atenRelated to change to the Core ATen opsettriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions