forked from ROCm/pytorch
-
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.
Extend DispatchStub to support CUDA dispatch (pytorch#9579)
Summary: This is a few files taken from pytorch#8919. They're unchanged from the latest versions of that PR. ``` This is part of pytorch#8919. It's separated to make it easier to merge the PR in pieces. There are a few major changes to DispatchStub - The environment variable ATEN_CPU_CAPABILITY overrides the CPU capability detection code (Previous ATEN_DISABLE_AVX/AVX2) - DispatchStub is defined in the generic native code instead of the CPU_CAPABILITY_DEFAULT kernel. ``` Pull Request resolved: pytorch#9579 Differential Revision: D8909000 Pulled By: colesbury fbshipit-source-id: fdeb606270b06acdab3c01dba97ec9d81584ecc0
- Loading branch information
1 parent
a08119a
commit bcf0bf4
Showing
10 changed files
with
139 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "DispatchStub.h" | ||
|
||
#include <ATen/Error.h> | ||
|
||
#include <cpuinfo.h> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
namespace at { namespace native { | ||
|
||
static CPUCapability compute_cpu_capability() { | ||
auto envar = std::getenv("ATEN_CPU_CAPABILITY"); | ||
if (envar) { | ||
if (strcmp(envar, "avx2") == 0) { | ||
return CPUCapability::AVX2; | ||
} | ||
if (strcmp(envar, "avx") == 0) { | ||
return CPUCapability::AVX; | ||
} | ||
if (strcmp(envar, "default") == 0) { | ||
return CPUCapability::DEFAULT; | ||
} | ||
AT_WARN("ignoring invalid value for ATEN_CPU_CAPABILITY: ", envar); | ||
} | ||
|
||
#ifndef __powerpc__ | ||
if (cpuinfo_initialize()) { | ||
if (cpuinfo_has_x86_avx2() && cpuinfo_has_x86_fma3()) { | ||
return CPUCapability::AVX2; | ||
} | ||
if (cpuinfo_has_x86_avx()) { | ||
return CPUCapability::AVX; | ||
} | ||
} | ||
#endif | ||
return CPUCapability::DEFAULT; | ||
} | ||
|
||
CPUCapability get_cpu_capability() { | ||
static CPUCapability capability = compute_cpu_capability(); | ||
return capability; | ||
} | ||
|
||
}} // namespace at::native |
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
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