Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AVX512 support #675

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ bool HostHasAVX() {
return Features["avx"];
}

bool HostHasAVX512() {
StringMap<bool> Features;
sys::getHostCPUFeatures(Features);
// The following instructions sets are supported by Intel CPUs starting 2017
// (Skylake-SP and beyond) and AMD CPUs starting 2022 (Zen4 and beyond)
const char *instruction_set[] = {
"avx512f", // Foundation
"avx512dq", // Double Word, Quad Word
"avx512bw", // Vector Byte and Word
"avx512vl", // Vector Length
"avx512cd", // Conflict Detection
};
bool has_avx512 = true;
for (auto &instr : instruction_set) {
has_avx512 &= Features[instr];
}
return has_avx512;
}

int terra_inittarget(lua_State *L) {
terra_State *T = terra_getstate(L, 1);
TerraTarget *TT = new TerraTarget();
Expand Down Expand Up @@ -257,7 +276,13 @@ int terra_inittarget(lua_State *L) {
#ifdef DISABLE_AVX
TT->Features = "-avx";
#else
TT->Features = HostHasAVX() ? "+avx" : "";
if (HostHasAVX512()) {
TT->Features = "+avx512f,+avx512dq,+avx512bw,+avx512vl,+avx512cd";
} else if (HostHasAVX()) {
TT->Features = "+avx";
} else {
TT->Features = "";
}
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions tests/avx512.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local vec = vector(int8, 64)
terra compute(x: vec, y: vec)
-- vec has a size of 8 * 64 = 512 bits so this operation should compile
-- to a single AVX512 instruction
return x + y
end
compute:compile()
compute:disas()
Loading