Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into raii
Browse files Browse the repository at this point in the history
  • Loading branch information
hiemstar committed Oct 17, 2024
2 parents 829ff63 + 7faa246 commit 7e30579
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Note: macOS 12 runs on x86 hardware, and 14 runs on M1 hardware
os: ['macos-12', 'macos-14', 'windows-2022']
# Note: macOS 13 runs on x86 hardware, and 14 runs on M1 hardware
os: ['macos-13', 'macos-14', 'windows-2022']
llvm: ['11', '12', '13', '14', '15', '16', '17', '18']
cuda: ['0', '1']
lua: ['luajit', 'moonjit']
exclude:
# macOS: exclude cuda
- os: 'macos-12'
- os: 'macos-13'
cuda: '1'
- os: 'macos-14'
cuda: '1'
Expand Down
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()

0 comments on commit 7e30579

Please sign in to comment.