gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / q35-9b / tools / torch-cpu-exp.cpp
| 1 | // Independent verification oracle only. Uses the original converter's pinned |
| 2 | // ATen CPU exp, without Python, model code, CUDA computation, or a production dependency. |
| 3 | // The pinned library's dependencies include libcudart; no library-absence claim is made. |
| 4 | #include <ATen/ATen.h> |
| 5 | #include <cstdio> |
| 6 | #include <cstring> |
| 7 | int main(int argc,char **argv) { |
| 8 | if(argc!=2||std::strcmp(argv[1],"negexp"))return 2; |
| 9 | static_assert(sizeof(float)==4); |
| 10 | unsigned char raw[65536];const size_t bytes=std::fread(raw,1,sizeof raw,stdin); |
| 11 | if(std::ferror(stdin)||!std::feof(stdin)||!bytes||bytes%4)return 2; |
| 12 | float values[16384];std::memcpy(values,raw,bytes);const size_t n=bytes/4; |
| 13 | try { |
| 14 | auto input=at::from_blob(values,{static_cast<int64_t>(n)},at::TensorOptions().dtype(at::kFloat).device(at::kCPU)); |
| 15 | auto result=at::neg(at::exp(input)).contiguous(); |
| 16 | return std::fwrite(result.const_data_ptr<float>(),sizeof(float),n,stdout)==n?0:4; |
| 17 | }catch(const std::exception &){return 3;} |
| 18 | } |