整理gcc使用的Cython构建标记

时间:2018-06-25 08:21:49

标签: python cython setuptools compiler-flags cythonize

我目前使用'setuptools'在Linux上使用gcc自动cythonize和编译我的Cython模块。从现在开始,我需要对提供给gcc的构建标志进行更多控制。如果我在setup.py中使用以下内容:

cythonize(
    [Extension("*", ["project/*.pyx"])
    nthreads=4
)

我得到构建标记,看起来像:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -fPIC -I./fastmat/core -I/home/seb/.local/lib/python3.6/site-packages/numpy/core/include -Iproject/core -Ifastmat/inspect -Iutil -I/usr/include/python3.6m -c project/BlockDiag.c -o build/temp.linux-x86_64-3.6/project/BlockDiag.o

在这里,我对所有的构建标志多次出现而没有以任何(对我来说很明显)的方式发布这个事实感到非常惊讶。

如何清理这些构建标志,使它们看起来像建议的here?我希望能一路学习关于setuptools的方法,以最终完全控制构建过程,而不必使用自维护的makefile。

1 个答案:

答案 0 :(得分:0)

GCC获得的标志来自env变量之一。输入

SparkException: Job aborted due to stage failure: Task 0 in stage 71.0 failed 4 times, most recent failure: Lost task 0.3 in stage 71.0 (TID 140, 10.139.64.5, executor 0): org.apache.spark.SparkException: Failed to execute user defined function($anonfun$1: (array<struct<annotatorType:string,begin:int,end:int,result:string,metadata:map<string,string>>>) => array<string>)
at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)
at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
at org.apache.spark.sql.execution.WholeStageCodegenExec$$anonfun$10$$anon$1.hasNext(WholeStageCodegenExec.scala:620)
at org.apache.spark.sql.execution.collect.UnsafeRowBatchUtils$.encodeUnsafeRows(UnsafeRowBatchUtils.scala:49)
at org.apache.spark.sql.execution.collect.Collector$$anonfun$2.apply(Collector.scala:126)
at org.apache.spark.sql.execution.collect.Collector$$anonfun$2.apply(Collector.scala:125)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
at org.apache.spark.scheduler.Task.run(Task.scala:111)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:349)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema cannot be cast to line3bae92b2d0d94e17a4d1cd71f9096486112.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$AnnotatorType
    at line3bae92b2d0d94e17a4d1cd71f9096486112.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$anonfun$getNouns$1.apply$mcVI$sp(command-1488395665137969:10)
    at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:160)
    at line3bae92b2d0d94e17a4d1cd71f9096486112.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw.getNouns(command-1488395665137969:9)
    at line3bae92b2d0d94e17a4d1cd71f9096486112.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$anonfun$1.apply(command-1488395665137969:15)
    at line3bae92b2d0d94e17a4d1cd71f9096486112.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$anonfun$1.apply(command-1488395665137969:15)
    ... 12 more

打印它们。这是$ python -c "from distutils import sysconfig;\ print(sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',\ 'BASECFLAGS', 'LDFLAGS', 'CCSHARED', 'LDSHARED', 'SO'))" 默认用于扩展编译的内容。现在检查哪个env var引入了哪个标志并相应地覆盖env var,例如

distutils

使用特定的编译器版本并启用$ CC="gcc-7.3.0" CFLAGS="-Ofast" python setup.py build_ext 优化。

此外,您似乎正在使用O3而不是普通的numpy.distutils,因此请注意,distutils会在幕后添加额外的包含/链接标志。