我正在尝试使用ISPC (隐式SPMD程序编译器)使用巴泽尔。因此,我开始实现ispc。
不幸的是,我在使用ispc生成文件时遇到了问题。
你可以通过以下方式复制我的问题:
git clone https://github.com/Vertexwahn/rules_ispc.git
cd rules_ispc
cd tests
bazel build //example:main将产生以下错误:
错误: /home/vertexwahn/rules_ispc/tests/example/BUILD.bazel:3:16:声明的输出‘样例/平方.o’不是由泛型规则创建的。这可能是因为泛型规则实际上没有创建这个输出,或者是因为输出是一个目录,并且是远程运行的(请注意,只有声明的文件输出的内容是远程复制的)错误: /home/vertexwahn/rules_ispc/tests/example/BUILD.bazel:3:16:声明的输出‘样例/平方.h’不是由泛型规则创建的。这可能是因为泛型规则实际上没有创建这个输出,或者是因为输出是一个目录,并且是远程运行的(请注意,只有声明的文件输出的内容是从远程运行的)错误: /home/vertexwahn/rules_ispc/tests/example/BUILD.bazel:3:16:执行泛型规则//示例:square_ispc_gen失败:并非所有输出都已创建或有效。
我在Ubuntu20.04、Ubuntu22.04、Windows 2019、Windows 2022、macOS 11和macOS 12上看到了同样的错误。
我的BUILD.bazel文件如下所示:
load("@rules_ispc//:ispc.bzl", "ispc_cc_library")
ispc_cc_library(
name = "square",
srcs = ["square.ispc"],
)
cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [":square"],
)ispc_cc_library调用ISPC内部生成一个头文件和一个o文件:
def ispc_cc_library(name, srcs, target_compatible_with = [], **kwargs):
for ispc_source_file in srcs:
generted_header_filename = name + ".h"
native.genrule(
name = "%s_ispc_gen" % name,
srcs = [ispc_source_file],
outs = [name + ".o", generted_header_filename],
cmd = select({
"@platforms//os:linux": "$(location @ispc_linux_x86_64//:ispc) --target=avx2 --arch=x86-64 $(locations %s) --header-outfile=%s -o %s.o" % (ispc_source_file, generted_header_filename, name),
"@platforms//os:osx": "$(location @ispc_osx_x86_64//:ispc) --target=avx2 --arch=x86-64 $(locations %s) --header-outfile=%s -o %s.o" % (ispc_source_file, generted_header_filename, name),
"@platforms//os:windows": "$(location @ispc_windows_x86_64//:ispc) --target=avx2 --target-os=windows --arch=x86-64 $(locations %s) --header-outfile=%s -o %s.o" % (ispc_source_file, generted_header_filename, name),
}),
tools = select({
"@platforms//os:linux": ["@ispc_linux_x86_64//:ispc"],
"@platforms//os:osx": ["@ispc_osx_x86_64//:ispc"],
"@platforms//os:windows": ["@ispc_windows_x86_64//:ispc"],
}),
target_compatible_with = target_compatible_with,
)
native.cc_library(
name = name,
srcs = [name + ".o"],
hdrs = [name + ".h"],
target_compatible_with = target_compatible_with,
**kwargs
)我想知道如何使用genrule正确地获取ISPC生成的文件。任何暗示都欢迎!
更多详细信息:
square.ispc
export void square(uniform float vin[], uniform float vout[],
uniform int count) {
foreach (index = 0 ... count) {
float v = vin[index];
v = v * v;
vout[index] = v;
}
}ISPC生成的标题应该如下所示:
square.h
//
// C:/rules_ispc/tests/example/square.h
// (Header automatically generated by the ispc compiler.)
// DO NOT EDIT THIS FILE.
//
#pragma once
#include <stdint.h>
#ifdef __cplusplus
namespace ispc { /* namespace */
#endif // __cplusplus
#ifndef __ISPC_ALIGN__
#if defined(__clang__) || !defined(_MSC_VER)
// Clang, GCC, ICC
#define __ISPC_ALIGN__(s) __attribute__((aligned(s)))
#define __ISPC_ALIGNED_STRUCT__(s) struct __ISPC_ALIGN__(s)
#else
// Visual Studio
#define __ISPC_ALIGN__(s) __declspec(align(s))
#define __ISPC_ALIGNED_STRUCT__(s) __ISPC_ALIGN__(s) struct
#endif
#endif
///////////////////////////////////////////////////////////////////////////
// Functions exported from ispc code
///////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus) && (! defined(__ISPC_NO_EXTERN_C) || !__ISPC_NO_EXTERN_C )
extern "C" {
#endif // __cplusplus
extern void square(float * vin, float * vout, int32_t count);
#if defined(__cplusplus) && (! defined(__ISPC_NO_EXTERN_C) || !__ISPC_NO_EXTERN_C )
} /* end extern C */
#endif // __cplusplus
#ifdef __cplusplus
} /* namespace */
#endif // __cplusplus如果我在Bazel生成的目录中搜索生成的头文件square.h .h,那么该文件似乎不存在,即不生成。
发布于 2022-11-24 03:18:08
您也需要对输出执行$(location)扩展,因为Bazel将在bazel-out/输出树中为它们分配路径。
diff --git a/ispc.bzl b/ispc.bzl
index 1fca9b4..a1b9450 100644
--- a/ispc.bzl
+++ b/ispc.bzl
@@ -6,9 +6,9 @@ def ispc_cc_library(name, srcs, target_compatible_with = [], **kwargs):
srcs = [ispc_source_file],
outs = [name + ".o", generted_header_filename],
cmd = select({
- "@platforms//os:linux": "$(location @ispc_linux_x86_64//:ispc) --target=avx2 --arch=x86-64 $(locations %s) --header-outfile=%s -o %s.o" % (ispc_source_file, generted_header_filename, name),
- "@platforms//os:osx": "$(location @ispc_osx_x86_64//:ispc) --target=avx2 --arch=x86-64 $(locations %s) --header-outfile=%s -o %s.o" % (ispc_source_file, generted_header_filename, name),
- "@platforms//os:windows": "$(location @ispc_windows_x86_64//:ispc) --target=avx2 --target-os=windows --arch=x86-64 $(locations %s) --header-outfile=%s -o %s.o" % (ispc_source_file, generted_header_filename, name),
+ "@platforms//os:linux": "$(location @ispc_linux_x86_64//:ispc) --target=avx2 --arch=x86-64 $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_source_file, generted_header_filename, name),
+ "@platforms//os:osx": "$(location @ispc_osx_x86_64//:ispc) --target=avx2 --arch=x86-64 $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_source_file, generted_header_filename, name),
+ "@platforms//os:windows": "$(location @ispc_windows_x86_64//:ispc) --target=avx2 --target-os=windows --arch=x86-64 $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_source_file, generted_header_filename, name),
}),
tools = select({
"@platforms//os:linux": ["@ispc_linux_x86_64//:ispc"],
diff --git a/tests/example/main.cpp b/tests/example/main.cpp
index 44f7feb..1883757 100644
--- a/tests/example/main.cpp
+++ b/tests/example/main.cpp
@@ -1,4 +1,4 @@
-#include "square.h"
+#include "example/square.h"
#include <stdio.h>https://stackoverflow.com/questions/74512662
复制相似问题