Files
whetstone_DSL/editor/tests/step1979_test.cpp

96 lines
3.2 KiB
C++
Raw Normal View History

// Step 1979: CUDASymbolCatalog
//
// t1: catalog has cublasSgemm for cublas/compute.matrix
// t2: catalog has thrust::sort for thrust/compute.sort
// t3: cufft symbols present for compute.fft
// t4: cudnn symbols present for compute.ml.inference
// t5: total catalog has >= 18 symbols
#include "CUDASymbolCatalog.h"
#include <iostream>
namespace ws = whetstone;
static int p = 0, f = 0;
#define T(n) { std::cout << " " << #n << "... "; }
#define P() { std::cout << "PASS\n"; ++p; }
#define F(m) { std::cout << "FAIL: " << m << "\n"; ++f; }
#define C(c, m) if (!(c)) { F(m); return; }
void t1() {
T(cublasSgemm_in_catalog);
auto cat = ws::CUDASymbolCatalog::buildCatalog();
auto syms = cat.get("cublas", "compute.matrix");
C(syms.size() >= 5, "at least 5 cublas symbols");
bool found = false;
for (const auto& s : syms)
if (s.functionName == "cublasSgemm") found = true;
C(found, "cublasSgemm present");
// Check signature contains cublasHandle_t
for (const auto& s : syms) {
if (s.functionName == "cublasSgemm") {
C(s.signature.find("cublasHandle_t") != std::string::npos, "signature has handle");
C(!s.caveats.empty(), "cublasSgemm has caveats");
}
}
P();
}
void t2() {
T(thrust_sort_in_catalog);
auto cat = ws::CUDASymbolCatalog::buildCatalog();
auto syms = cat.get("thrust", "compute.sort");
C(!syms.empty(), "thrust/compute.sort non-empty");
bool found = false;
for (const auto& s : syms)
if (s.functionName == "thrust::sort") found = true;
C(found, "thrust::sort present");
// Also verify compute.parallel has thrust symbols
auto par = cat.get("thrust", "compute.parallel");
C(par.size() >= 4, "at least 4 thrust/compute.parallel symbols");
P();
}
void t3() {
T(cufft_symbols_for_compute_fft);
auto cat = ws::CUDASymbolCatalog::buildCatalog();
auto syms = cat.get("cufft", "compute.fft");
C(syms.size() >= 3, "at least 3 cufft symbols");
bool hasPlan = false, hasExec = false;
for (const auto& s : syms) {
if (s.functionName == "cufftPlan1d") hasPlan = true;
if (s.functionName == "cufftExecC2C") hasExec = true;
}
C(hasPlan, "cufftPlan1d present");
C(hasExec, "cufftExecC2C present");
P();
}
void t4() {
T(cudnn_symbols_for_ml_inference);
auto cat = ws::CUDASymbolCatalog::buildCatalog();
auto syms = cat.get("cudnn", "compute.ml.inference");
C(syms.size() >= 5, "at least 5 cudnn symbols");
bool hasConv = false, hasCreate = false;
for (const auto& s : syms) {
if (s.functionName == "cudnnConvolutionForward") hasConv = true;
if (s.functionName == "cudnnCreate") hasCreate = true;
}
C(hasConv, "cudnnConvolutionForward present");
C(hasCreate, "cudnnCreate present");
P();
}
void t5() {
T(total_catalog_size_at_least_18);
auto cat = ws::CUDASymbolCatalog::buildCatalog();
C(cat.size() >= 18, "at least 18 total symbols, got " + std::to_string(cat.size()));
P();
}
int main() {
std::cout << "Step 1979: CUDASymbolCatalog\n";
t1(); t2(); t3(); t4(); t5();
std::cout << "\n" << p << "/" << (p + f) << " passed\n";
return f > 0 ? 1 : 0;
}