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) 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)") 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 # 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 export LLVM_SRC_DIR=/path/to/llvm-project
# Check out last known good commit. # 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) (cd $LLVM_SRC_DIR && git checkout $LLVM_COMMIT)
./build_tools/install_mlir.sh ./build_tools/install_mlir.sh

View File

@ -15,13 +15,43 @@ fi
mkdir -p "$build_dir" mkdir -p "$build_dir"
# Make sure we are using python3. # 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" echo "Using python: $python_exe"
if [ -z "$python_exe" ]; then if [ -z "$python_exe" ]; then
echo "Could not find python3" echo "Could not find python3"
exit 1 exit 1
fi 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. # Write a .env file for python tooling.
echo "Updating $td/.env file" echo "Updating $td/.env file"
echo "PYTHONPATH=\"$(realpath "$build_dir/python_native"):$(realpath "$build_dir/python"):$(realpath "$build_dir/iree/bindings/python")\"" > "$td/.env" 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" \ "-H$td" \
"-B$build_dir" \ "-B$build_dir" \
"-DCMAKE_BUILD_TYPE=Debug" \ "-DCMAKE_BUILD_TYPE=Debug" \
"-DCMAKE_CXX_FLAGS_DEBUG=-g3 -gdwarf-2" \ "-DCMAKE_CXX_FLAGS_DEBUG=$DEBUG_FLAGS" \
"-DPYTHON_EXECUTABLE=$python_exe" \ "-DPYTHON_EXECUTABLE=$python_exe" \
"-DMLIR_DIR=$install_mlir/lib/cmake/mlir" \ "-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" \ "-DLLVM_ENABLE_WARNINGS=ON" \
"-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE" \ "-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE" \
"${extra_opts[@]}" \ "${extra_opts[@]}" \

View File

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

View File

@ -19,10 +19,10 @@ class DialectHelper(Basicpy.DialectHelper):
>>> h = DialectHelper(c, ir.OpBuilder(c)) >>> h = DialectHelper(c, ir.OpBuilder(c))
DenseElementsAttrs: DenseElementsAttrs:
>>> c.dense_elements_attr(np.asarray([1, 2, 3, 4])) >>> c.dense_elements_attr(np.asarray([1, 2, 3, 4], dtype=np.int32))
dense<[1, 2, 3, 4]> : tensor<4xsi64> dense<[1, 2, 3, 4]> : tensor<4xsi32>
>>> c.dense_elements_attr(np.asarray([[1, 2], [3, 4]])) >>> c.dense_elements_attr(np.asarray([[1, 2], [3, 4]], dtype=np.int32))
dense<[[1, 2], [3, 4]]> : tensor<2x2xsi64> dense<[[1, 2], [3, 4]]> : tensor<2x2xsi32>
>>> c.dense_elements_attr(np.asarray([[1., 2.], [3., 4.]])) >>> 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> 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)) >>> 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_LINK_MODE SHARED)
set(NPCOMP_PYEXT_LIBADD ${PYTHON_LIBRARIES}) 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) if(NPCOMP_ENABLE_IREE)
list(APPEND NPCOMP_PYEXT_LIBADD NPCOMPBackendIREEPythonModule) list(APPEND NPCOMP_PYEXT_LIBADD NPCOMPBackendIREEPythonModule)
endif() endif()
@ -35,8 +42,7 @@ set(extension_pybind_sources
) )
set_source_files_properties( set_source_files_properties(
${extension_pybind_sources} ${extension_pybind_sources}
PROPERTIES COMPILE_FLAGS PROPERTIES COMPILE_FLAGS "${extension_cflags}")
"-frtti -fexceptions")
add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE} add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE}
${extension_pybind_sources} ${extension_pybind_sources}
${extension_llvm_sources} ${extension_llvm_sources}