# NEGATIVE (Python C API from native code, could patch the harness): static gate. import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.cpp_extension import load_inline cuda_src = r""" #include #include __global__ void k(float* y) { y[0] = 1.f; } torch::Tensor f(torch::Tensor y) { PyObject* m = PyImport_ImportModule("time"); k<<<1,1>>>(y.data_ptr()); return y; } """ cpp_src = "torch::Tensor f(torch::Tensor y);" ext = load_inline(name="eval_neg_capi", cpp_sources=cpp_src, cuda_sources=cuda_src, functions=["f"]) class ModelNew(nn.Module): def __init__(self, in_features, out_features, multiplier, negative_slope): super().__init__() self.gemm = nn.Linear(in_features, out_features) self.multiplier = multiplier self.negative_slope = negative_slope def forward(self, x): return ext.f(F.linear(x, self.gemm.weight, self.gemm.bias))