Skip to content

Commit

Permalink
Merge branch 'main' into update-perplexity-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
archana-ramalingam authored Nov 9, 2024
2 parents b5d7b0e + 2cbf768 commit f9171c1
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
37 changes: 35 additions & 2 deletions shortfin/dev_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@
# Otherwise, the shortfin build will download a pinned IREE source tree.

import argparse
import importlib
import os
from packaging.version import Version
from pathlib import Path
import re
import subprocess
import shutil
import sys
import sysconfig

try:
from packaging.version import Version
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
f"'packaging' package not installed and required: Install with:\n"
f" {sys.executable} -m pip install packaging"
)


CMAKE_REQUIRED_VERSION = Version("3.29")
PYTHON_REQUIRED_VERSION = Version("3.12")
CLANG_REQUIRED_VERSION = Version("16")
SETUPTOOLS_REQUIRED_VERSION = Version("61.0")


class EnvInfo:
Expand All @@ -58,6 +67,8 @@ def __init__(self, args):
self.ninja_exe = shutil.which("ninja")
self.clang_exe, self.clang_version = self.find_clang(args)
self.iree_dir = self.find_iree(args)
self.setuptools_version = self.find_package_version("setuptools")
self.wheel_version = self.find_package_version("wheel")

self.configured_dirs = []
self.add_configured(self.this_dir / "build" / "cmake" / "default")
Expand Down Expand Up @@ -116,6 +127,13 @@ def find_iree(self, args):
sys.exit(1)
return str(iree_dir)

def find_package_version(self, package_name: str) -> Version | None:
try:
m = importlib.import_module(package_name)
except ModuleNotFoundError:
return None
return Version(m.__version__)

def check_prereqs(self, args):
if self.cmake_version is None or self.cmake_version < CMAKE_REQUIRED_VERSION:
print(
Expand All @@ -131,7 +149,7 @@ def check_prereqs(self, args):
)
sys.exit(1)
if self.clang_exe and self.clang_version < CLANG_REQUIRED_VERSION:
print(f"ERROR: clang version too old: {self.clang_exe}")
print(f"WARNING: clang version too old: {self.clang_exe}")
print(f" REQUIRED: {CLANG_REQUIRED_VERSION}, Found {self.clang_version}")
elif not self.clang_exe:
print(f"WARNING: Building the project with clang is highly recommended")
Expand All @@ -143,6 +161,19 @@ def check_prereqs(self, args):
)
sys.exit(1)

if (
self.setuptools_version is None
or self.setuptools_version < SETUPTOOLS_REQUIRED_VERSION
):
print(
f"ERROR: 'setuptools' packaging is not installed or too old. "
f"Found {self.setuptools_version}, Need {SETUPTOOLS_REQUIRED_VERSION}"
)
sys.exit(1)
if self.wheel_version is None:
print(f"'wheel' package is not installed")
sys.exit(1)

def __repr__(self):
report = [
f"python: {self.python_exe}",
Expand All @@ -153,6 +184,8 @@ def __repr__(self):
f"ninja: {self.ninja_exe}",
f"clang: {self.clang_exe} ({self.clang_version})",
f"iree: {self.iree_dir}",
f"setuptools: {self.setuptools_version}",
f"wheel: {self.wheel_version}",
]
return "\n".join(report)

Expand Down
20 changes: 18 additions & 2 deletions shortfin/python/_shortfin/asyncio_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import asyncio
import inspect

from . import lib as sfl


# Feature detect some versions where signatures changes.
if "context" in inspect.signature(asyncio.Task).parameters:
# Python > 3.10
_ASYNCIO_TASK_HAS_CONTEXT = True
else:
_ASYNCIO_TASK_HAS_CONTEXT = False


class PyWorkerEventLoop(asyncio.AbstractEventLoop):
def __init__(self, worker: sfl.local.Worker):
self._worker = worker
Expand All @@ -17,8 +26,15 @@ def get_debug(self):
# Requirement of asyncio.
return False

def create_task(self, coro, *, name=None, context=None):
return asyncio.Task(coro, loop=self, name=name, context=context)
if _ASYNCIO_TASK_HAS_CONTEXT:

def create_task(self, coro, *, name=None, context=None):
return asyncio.Task(coro, loop=self, name=name, context=context)

else:

def create_task(self, coro, *, name=None):
return asyncio.Task(coro, loop=self, name=name)

def create_future(self):
return asyncio.Future(loop=self)
Expand Down
2 changes: 1 addition & 1 deletion shortfin/python/shortfin_apps/sd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_modules(args):
f"--model={modelname}",
f"--iree-hal-target-device={args.device}",
f"--iree-hip-target={args.target}",
f"--iree-compile-extra-args={" ".join(ireec_args)}",
f"--iree-compile-extra-args={' '.join(ireec_args)}",
]
print("BUILDER INPUT:\n", " \ \n ".join(builder_args))
output = subprocess.check_output(builder_args).decode()
Expand Down
5 changes: 5 additions & 0 deletions shortfin/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Any definitions which must be reflected on the public library must be added
# to this library.
add_library(shortfin_public_defs INTERFACE)

add_subdirectory(shortfin)

# Common definitions exported from both static and dynamic libraries.
Expand All @@ -28,6 +32,7 @@ shortfin_public_library(
shortfin_systems_factory
${_SHORTFIN_LIB_OPTIONAL_COMPONENTS}
USAGE_DEPS
shortfin_public_defs
spdlog::spdlog
fmt::fmt
xtensor
Expand Down
12 changes: 6 additions & 6 deletions shortfin/src/shortfin/array/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ class typed_mapping {
span_type span() { return span_type(data(), size()); }
const_span_type span() const { return const_span_type(data(), size()); }

span_type::iterator begin() { return span().begin(); }
span_type::iterator end() { return span().end(); }
typename span_type::iterator begin() { return span().begin(); }
typename span_type::iterator end() { return span().end(); }

const_span_type::iterator begin() const { return span().begin(); }
const_span_type::iterator end() const { return span().end(); }
typename const_span_type::iterator begin() const { return span().begin(); }
typename const_span_type::iterator end() const { return span().end(); }

const_span_type::iterator cbegin() const { return span().begin(); }
const_span_type::iterator cend() const { return span().end(); }
typename const_span_type::iterator cbegin() const { return span().begin(); }
typename const_span_type::iterator cend() const { return span().end(); }

private:
mapping untyped_mapping_;
Expand Down
2 changes: 2 additions & 0 deletions shortfin/src/shortfin/local/systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ shortfin_cc_component(
iree_task_task
)
list(APPEND _SYSTEM_COMPONENTS shortfin_systems_host)
target_compile_definitions(shortfin_public_defs INTERFACE SHORTFIN_HAVE_HOSTCPU)

if(SHORTFIN_SYSTEMS_AMDGPU)
shortfin_cc_component(
Expand All @@ -47,6 +48,7 @@ if(SHORTFIN_SYSTEMS_AMDGPU)
iree_hal_drivers_hip_hip
)
list(APPEND _SYSTEM_COMPONENTS shortfin_systems_amdgpu)
target_compile_definitions(shortfin_public_defs INTERFACE SHORTFIN_HAVE_AMDGPU)
endif()

shortfin_cc_component(
Expand Down

0 comments on commit f9171c1

Please sign in to comment.