oneapi-src / level-zero

oneAPI Level Zero Specification Headers and Loader
https://spec.oneapi.com/versions/latest/elements/l0/source/index.html
MIT License
208 stars 90 forks source link

[Error] Don't get kernel #127

Open muzhailong opened 10 months ago

muzhailong commented 10 months ago

I use the following spirv code, then I use spirv-tools library to compile the source code into binary by core.Assemble(new_code, &binary). Creating L0 Module is ok, I use zeModuleGetKernelNames to get all kernle names, but the func return 0, don't find kernle name. why?

    ; SPIR-V
    ; Version: 1.2
    ; Generator: Khronos; 22
    ; Bound: 3
    ; Schema: 0
                   OpCapability Addresses
                   OpCapability Kernel
                   OpCapability VectorAnyINTEL
                   OpCapability VectorComputeINTEL
                   OpCapability FunctionPointersINTEL
                   OpCapability FloatingPointModeINTEL
                   OpCapability Int64
                   OpCapability Vector16
                   OpCapability Int8
                   OpCapability Int16
                   OpExtension "SPV_INTEL_float_controls2"
                   OpExtension "SPV_INTEL_function_pointers"
                   OpExtension "SPV_INTEL_vector_compute"
            %ext = OpExtInstImport "OpenCL.std"
                   OpMemoryModel Physical64 OpenCL
                   OpEntryPoint Kernel %easy_func "easy_func"
           %void = OpTypeVoid
              %1 = OpTypeFunction %void
      %easy_func = OpFunction %void DontInline %1
              %2 = OpLabel
                   OpReturn
                   OpFunctionEnd

The c++ code is:

 binary.clear();
    if (!core.Assemble(new_code, &binary)) { std::cout << "assemble failure "; }
    std::cout << new_code;
    // binary = bins;

    std::ostringstream oss {std::ofstream::binary};
    oss.write(reinterpret_cast<const char *>(binary.data()),
               sizeof(binary[0]) * binary.size())
            .flush();
    isa_code_ = oss.str();

... init, create L0

ze_module_desc_t moduleDesc = {ZE_STRUCTURE_TYPE_MODULE_DESC, nullptr,
            ZE_MODULE_FORMAT_IL_SPIRV, isa_code.size(),
            (const uint8_t *)isa_code.c_str(), "-vc-codegen -g", nullptr};

    ze_module_build_log_handle_t buildlog;
    L0_SAFE_CALL(
            zeModuleCreate(context, device, &moduleDesc, &program_, &buildlog));
    // Only save build logs for module creation errors.
    {
        size_t szLog = 0;
        std::vector<char> str_log(szLog);
        zeModuleBuildLogGetString(buildlog, &szLog, str_log.data());
        std::string build_log(str_log.data(), str_log.size());
        std::cout << "build log: \n" << build_log;
    }
    zeModuleBuildLogDestroy(buildlog);
    uint32_t pCount;
    const char *pName = nullptr;
    zeModuleGetKernelNames(program_, &pCount, &pName);
    std::cout << "kernel number: " << pCount;
eero-t commented 10 months ago

This issue may belong to the L0 backend implementation you're using [1], rather than here in the frontend/loader project.

[1] For Intel HW, L0 backend is implemented in following project: https://github.com/intel/compute-runtime/

PS. You may need to state the versions of components in the stack you're using (HW, FW, kernel and user space driver versions).