Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion python/tvm/target/detect_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ def _detect_rocm(dev: Device) -> Target:
)


def _detect_opencl(dev: Device) -> Target:
return Target(
{
"kind": "opencl",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases, we can initialize OpenCL target with specifying specific device, e.g.:

target = Target("opencl -device=mali", host="llvm -mtriple=aarch64-linux-gnu")
or
target = Target("opencl -device=adreno", host="llvm -mtriple=arm64-linux-android")

Can we handle these cases somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have verified on Orange Pi.

Screenshot from 2024-04-09 12-56-06

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, probably my question wasn't clear. Yes, I know that we can get such information from target. But I'm curious if we can get this information from the device somehow?

Probably, we can specify by an addition parameter to Target.from_device(input_device). For example: Target.from_device(input_device, '-device=adreno') will specify target as "kind": "opencl -device=adreno". Does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is no argument for '-device=adreno' in API Target.from_device.

This PR intends to fix weight conversion for MLC LLM on OrangePi (#1557), assuming there are no other issues. I would like to merge it first. If you have any suggestions, perhaps we can create another issue to discuss. Thanks.

"max_shared_memory_per_block": dev.max_shared_memory_per_block,
"max_threads_per_block": dev.max_threads_per_block,
"thread_warp_size": dev.warp_size,
}
)


def _detect_vulkan(dev: Device) -> Target:
f_get_target_property = get_global_func("device_api.vulkan.get_target_property")
return Target(
Expand Down Expand Up @@ -99,7 +110,7 @@ def detect_target_from_device(dev: Union[str, Device]) -> Target:
----------
dev : Union[str, Device]
The device to detect the target for.
Supported device types: ["cuda", "metal", "rocm", "vulkan"]
Supported device types: ["cuda", "metal", "rocm", "vulkan", "opencl"]

Returns
-------
Expand Down Expand Up @@ -128,4 +139,5 @@ def detect_target_from_device(dev: Union[str, Device]) -> Target:
"metal": _detect_metal,
"vulkan": _detect_vulkan,
"rocm": _detect_rocm,
"opencl": _detect_opencl,
}
12 changes: 12 additions & 0 deletions tests/python/target/test_target_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,5 +547,17 @@ def test_target_from_device_rocm(input_device):
)


@tvm.testing.requires_opencl
@pytest.mark.parametrize("input_device", ["opencl", tvm.opencl()])
def test_target_from_device_opencl(input_device):
target = Target.from_device(input_device)

dev = tvm.opencl()
assert target.kind.name == "opencl"
assert target.attrs["max_threads_per_block"] == dev.max_threads_per_block
assert target.max_shared_memory_per_block == dev.max_shared_memory_per_block
assert target.thread_warp_size == dev.warp_size


if __name__ == "__main__":
tvm.testing.main()