Some fixes to get npcomp building and passing on windows.

There is more that can be done here, but this gets it minimally working.
pull/1/head
Stella Laurenzo 2020-07-01 21:28:04 -07:00
parent 92190176fb
commit aeb422b030
6 changed files with 66 additions and 12 deletions

View File

@ -28,6 +28,18 @@ set(CMAKE_CXX_STANDARD 14)
option(NPCOMP_ENABLE_IREE "Enables the IREE backend (must configure location via IREE_DIR)." OFF)
set(NPCOMP_IREE_SRCDIR "" CACHE STRING "If building IREE, then setting this elects to build from a source directory (versus installed package)")
#-------------------------------------------------------------------------------
# MSVC defaults
#-------------------------------------------------------------------------------
if(MSVC)
add_compile_options(
$<$<CONFIG:>:/MD>
$<$<CONFIG:Debug>:/MD>
$<$<CONFIG:Release>:/MD>
)
endif()
#-------------------------------------------------------------------------------
# MLIR/LLVM Configuration
#-------------------------------------------------------------------------------

View File

@ -71,7 +71,7 @@ export LDFLAGS=-fuse-ld=$(which ld.lld-$LLVM_VERSION)
export LLVM_SRC_DIR=/path/to/llvm-project
# Check out last known good commit.
LLVM_COMMIT="$(cat ./built_tools/llvm.version)"
LLVM_COMMIT="$(cat ./build_tools/llvm_version.txt)"
(cd $LLVM_SRC_DIR && git checkout $LLVM_COMMIT)
./build_tools/install_mlir.sh

View File

@ -15,13 +15,43 @@ fi
mkdir -p "$build_dir"
# Make sure we are using python3.
python_exe="$(which python3)"
function probe_python() {
local python_exe="$1"
local found
local command="import sys
if sys.version_info.major >= 3: print(sys.executable)"
set +e
found="$(echo "$command" | "$python_exe" - 2>/dev/null)"
if ! [ -z "$found" ]; then
echo "$found"
fi
}
python_exe=""
for python_candidate in python3 python; do
python_exe="$(probe_python "$python_candidate")"
done
echo "Using python: $python_exe"
if [ -z "$python_exe" ]; then
echo "Could not find python3"
exit 1
fi
# Detect windows.
if (which cygpath 2>/dev/null); then
echo "Using windows path mangling and flags"
DEBUG_FLAGS=""
function translate_path() {
cygpath --windows "$1"
}
else
DEBUG_FLAGS="-g3 -gdwarf2"
function translate_path() {
echo "$1"
}
fi
# Write a .env file for python tooling.
echo "Updating $td/.env file"
echo "PYTHONPATH=\"$(realpath "$build_dir/python_native"):$(realpath "$build_dir/python"):$(realpath "$build_dir/iree/bindings/python")\"" > "$td/.env"
@ -32,10 +62,10 @@ cmake -GNinja \
"-H$td" \
"-B$build_dir" \
"-DCMAKE_BUILD_TYPE=Debug" \
"-DCMAKE_CXX_FLAGS_DEBUG=-g3 -gdwarf-2" \
"-DCMAKE_CXX_FLAGS_DEBUG=$DEBUG_FLAGS" \
"-DPYTHON_EXECUTABLE=$python_exe" \
"-DMLIR_DIR=$install_mlir/lib/cmake/mlir" \
"-DLLVM_EXTERNAL_LIT=$build_mlir/bin/llvm-lit" \
"-DLLVM_EXTERNAL_LIT=$build_mlir/bin/llvm-lit.py" \
"-DLLVM_ENABLE_WARNINGS=ON" \
"-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE" \
"${extra_opts[@]}" \

View File

@ -2,6 +2,13 @@
# NPCOMPPythonCommon
################################################################################
if(MSVC)
# Exceptions and RTTI
set(extension_cflags "/EHsc /GR")
else()
set(extension_cflags "-frtti -fexceptions")
endif()
set(PYBIND_SOURCES
MlirInit.cpp
MlirIr.cpp
@ -12,8 +19,7 @@ set(PYBIND_SOURCES
)
set_source_files_properties(
${PYBIND_SOURCES}
PROPERTIES COMPILE_FLAGS
"-frtti -fexceptions")
PROPERTIES COMPILE_FLAGS "${extension_cflags}")
add_library(NPCOMPPythonCommon
${PYBIND_SOURCES}

View File

@ -19,10 +19,10 @@ class DialectHelper(Basicpy.DialectHelper):
>>> h = DialectHelper(c, ir.OpBuilder(c))
DenseElementsAttrs:
>>> c.dense_elements_attr(np.asarray([1, 2, 3, 4]))
dense<[1, 2, 3, 4]> : tensor<4xsi64>
>>> c.dense_elements_attr(np.asarray([[1, 2], [3, 4]]))
dense<[[1, 2], [3, 4]]> : tensor<2x2xsi64>
>>> c.dense_elements_attr(np.asarray([1, 2, 3, 4], dtype=np.int32))
dense<[1, 2, 3, 4]> : tensor<4xsi32>
>>> c.dense_elements_attr(np.asarray([[1, 2], [3, 4]], dtype=np.int32))
dense<[[1, 2], [3, 4]]> : tensor<2x2xsi32>
>>> c.dense_elements_attr(np.asarray([[1., 2.], [3., 4.]]))
dense<[[1.000000e+00, 2.000000e+00], [3.000000e+00, 4.000000e+00]]> : tensor<2x2xf64>
>>> c.dense_elements_attr(np.asarray([[1., 2.], [3., 4.]], dtype=np.float32))

View File

@ -15,6 +15,13 @@
set(NPCOMP_PYEXT_LINK_MODE SHARED)
set(NPCOMP_PYEXT_LIBADD ${PYTHON_LIBRARIES})
if(MSVC)
# Exceptions and RTTI
set(extension_cflags "/EHsc /GR")
else()
set(extension_cflags "-frtti -fexceptions")
endif()
if(NPCOMP_ENABLE_IREE)
list(APPEND NPCOMP_PYEXT_LIBADD NPCOMPBackendIREEPythonModule)
endif()
@ -35,8 +42,7 @@ set(extension_pybind_sources
)
set_source_files_properties(
${extension_pybind_sources}
PROPERTIES COMPILE_FLAGS
"-frtti -fexceptions")
PROPERTIES COMPILE_FLAGS "${extension_cflags}")
add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE}
${extension_pybind_sources}
${extension_llvm_sources}