Skip to content

Commit

Permalink
[Feature] Add MPS bbox overlap (#2123)
Browse files Browse the repository at this point in the history
* add mps bbox overlap

* format

* update document and manifest

* update readme
  • Loading branch information
q.yao authored Jul 22, 2022
1 parent 7306643 commit 22fadce
Show file tree
Hide file tree
Showing 12 changed files with 687 additions and 122 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ include mmcv/model_zoo/open_mmlab.json mmcv/model_zoo/deprecated.json mmcv/model
include mmcv/ops/csrc/common/cuda/*.cuh mmcv/ops/csrc/common/cuda/*.hpp mmcv/ops/csrc/common/*.hpp
include mmcv/ops/csrc/pytorch/*.cpp mmcv/ops/csrc/pytorch/cuda/*.cu mmcv/ops/csrc/pytorch/cuda/*.cpp mmcv/ops/csrc/pytorch/cpu/*.cpp
include mmcv/ops/csrc/parrots/*.h mmcv/ops/csrc/parrots/*.cpp
recursive-include mmcv/ops/csrc/ *.h *.hpp *.cpp *.cuh *.cu
include mmcv/ops/csrc/pytorch/mps/*.mm mmcv/ops/csrc/common/mps/*.h mmcv/ops/csrc/common/mps/*.mm
recursive-include mmcv/ops/csrc/ *.h *.hpp *.cpp *.cuh *.cu *.mm
110 changes: 55 additions & 55 deletions docs/en/understand_mmcv/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

We implement common ops used in detection, segmentation, etc.

| Device | CPU | CUDA | MLU |
| ---------------------------- | --- | ---- | --- |
| ActiveRotatedFilter ||| |
| AssignScoreWithK | || |
| BallQuery | || |
| BBoxOverlaps | |||
| BorderAlign | || |
| BoxIouRotated ||| |
| CARAFE | || |
| ChamferDistance | || |
| CrissCrossAttention | || |
| ContourExpand || | |
| ConvexIoU | || |
| CornerPool | || |
| Correlation | || |
| Deformable Convolution v1/v2 ||| |
| Deformable RoIPool | || |
| DiffIoURotated | || |
| DynamicScatter | || |
| FurthestPointSample | || |
| FurthestPointSampleWithDist | || |
| FusedBiasLeakyrelu | || |
| GatherPoints | || |
| GroupPoints | || |
| Iou3d | || |
| KNN | || |
| MaskedConv | || |
| MergeCells | || |
| MinAreaPolygon | || |
| ModulatedDeformConv2d ||| |
| MultiScaleDeformableAttn | || |
| NMS ||||
| NMSRotated ||| |
| PixelGroup || | |
| PointsInBoxes ||| |
| PointsInPolygons | || |
| PSAMask ||||
| RotatedFeatureAlign ||| |
| RoIPointPool3d | || |
| RoIPool | |||
| RoIAlignRotated ||||
| RiRoIAlignRotated | || |
| RoIAlign ||||
| RoIAwarePool3d | || |
| SAConv2d | || |
| SigmoidFocalLoss | |||
| SoftmaxFocalLoss | || |
| SoftNMS | || |
| Sparse Convolution | || |
| Synchronized BatchNorm | || |
| ThreeInterpolate | || |
| ThreeNN | || |
| TINShift | |||
| UpFirDn2d | || |
| Voxelization ||| |
| Device | CPU | CUDA | MLU | MPS |
| ---------------------------- | --- | ---- | --- | --- |
| ActiveRotatedFilter ||| | |
| AssignScoreWithK | || | |
| BallQuery | || | |
| BBoxOverlaps | ||||
| BorderAlign | || | |
| BoxIouRotated ||| | |
| CARAFE | || | |
| ChamferDistance | || | |
| CrissCrossAttention | || | |
| ContourExpand || | | |
| ConvexIoU | || | |
| CornerPool | || | |
| Correlation | || | |
| Deformable Convolution v1/v2 ||| | |
| Deformable RoIPool | || | |
| DiffIoURotated | || | |
| DynamicScatter | || | |
| FurthestPointSample | || | |
| FurthestPointSampleWithDist | || | |
| FusedBiasLeakyrelu | || | |
| GatherPoints | || | |
| GroupPoints | || | |
| Iou3d | || | |
| KNN | || | |
| MaskedConv | || | |
| MergeCells | || | |
| MinAreaPolygon | || | |
| ModulatedDeformConv2d ||| | |
| MultiScaleDeformableAttn | || | |
| NMS |||| |
| NMSRotated ||| | |
| PixelGroup || | | |
| PointsInBoxes ||| | |
| PointsInPolygons | || | |
| PSAMask |||| |
| RotatedFeatureAlign ||| | |
| RoIPointPool3d | || | |
| RoIPool | ||| |
| RoIAlignRotated |||| |
| RiRoIAlignRotated | || | |
| RoIAlign |||| |
| RoIAwarePool3d | || | |
| SAConv2d | || | |
| SigmoidFocalLoss | ||| |
| SoftmaxFocalLoss | || | |
| SoftNMS | || | |
| Sparse Convolution | || | |
| Synchronized BatchNorm | || | |
| ThreeInterpolate | || | |
| ThreeNN | || | |
| TINShift | ||| |
| UpFirDn2d | || | |
| Voxelization ||| | |
110 changes: 55 additions & 55 deletions docs/zh_cn/understand_mmcv/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

MMCV 提供了检测、分割等任务中常用的算子

| Device | CPU | CUDA | MLU |
| ---------------------------- | --- | ---- | --- |
| ActiveRotatedFilter ||| |
| AssignScoreWithK | || |
| BallQuery | || |
| BBoxOverlaps | |||
| BorderAlign | || |
| BoxIouRotated ||| |
| CARAFE | || |
| ChamferDistance | || |
| CrissCrossAttention | || |
| ContourExpand || | |
| ConvexIoU | || |
| CornerPool | || |
| Correlation | || |
| Deformable Convolution v1/v2 ||| |
| Deformable RoIPool | || |
| DiffIoURotated | || |
| DynamicScatter | || |
| FurthestPointSample | || |
| FurthestPointSampleWithDist | || |
| FusedBiasLeakyrelu | || |
| GatherPoints | || |
| GroupPoints | || |
| Iou3d | || |
| KNN | || |
| MaskedConv | || |
| MergeCells | || |
| MinAreaPolygon | || |
| ModulatedDeformConv2d ||| |
| MultiScaleDeformableAttn | || |
| NMS ||||
| NMSRotated ||| |
| PixelGroup || | |
| PointsInBoxes ||| |
| PointsInPolygons | || |
| PSAMask ||||
| RotatedFeatureAlign ||| |
| RoIPointPool3d | || |
| RoIPool | |||
| RoIAlignRotated ||||
| RiRoIAlignRotated | || |
| RoIAlign ||||
| RoIAwarePool3d | || |
| SAConv2d | || |
| SigmoidFocalLoss | |||
| SoftmaxFocalLoss | || |
| SoftNMS | || |
| Sparse Convolution | || |
| Synchronized BatchNorm | || |
| ThreeInterpolate | || |
| ThreeNN | || |
| TINShift | |||
| UpFirDn2d | || |
| Voxelization ||| |
| Device | CPU | CUDA | MLU | MPS |
| ---------------------------- | --- | ---- | --- | --- |
| ActiveRotatedFilter ||| | |
| AssignScoreWithK | || | |
| BallQuery | || | |
| BBoxOverlaps | ||||
| BorderAlign | || | |
| BoxIouRotated ||| | |
| CARAFE | || | |
| ChamferDistance | || | |
| CrissCrossAttention | || | |
| ContourExpand || | | |
| ConvexIoU | || | |
| CornerPool | || | |
| Correlation | || | |
| Deformable Convolution v1/v2 ||| | |
| Deformable RoIPool | || | |
| DiffIoURotated | || | |
| DynamicScatter | || | |
| FurthestPointSample | || | |
| FurthestPointSampleWithDist | || | |
| FusedBiasLeakyrelu | || | |
| GatherPoints | || | |
| GroupPoints | || | |
| Iou3d | || | |
| KNN | || | |
| MaskedConv | || | |
| MergeCells | || | |
| MinAreaPolygon | || | |
| ModulatedDeformConv2d ||| | |
| MultiScaleDeformableAttn | || | |
| NMS |||| |
| NMSRotated ||| | |
| PixelGroup || | | |
| PointsInBoxes ||| | |
| PointsInPolygons | || | |
| PSAMask |||| |
| RotatedFeatureAlign ||| | |
| RoIPointPool3d | || | |
| RoIPool | ||| |
| RoIAlignRotated |||| |
| RiRoIAlignRotated | || | |
| RoIAlign |||| |
| RoIAwarePool3d | || | |
| SAConv2d | || | |
| SigmoidFocalLoss | ||| |
| SoftmaxFocalLoss | || | |
| SoftNMS | || | |
| Sparse Convolution | || | |
| Synchronized BatchNorm | || | |
| ThreeInterpolate | || | |
| ThreeNN | || | |
| TINShift | ||| |
| UpFirDn2d | || | |
| Voxelization ||| | |
37 changes: 28 additions & 9 deletions mmcv/ops/csrc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ This folder contains all non-python code for MMCV custom ops. Please follow the
│ ├── pytorch_cpp_helper.hpp
│ ├── pytorch_cuda_helper.hpp
│ ├── pytorch_device_registry.hpp
│   └── cuda
│   ├── common_cuda_helper.hpp
│   ├── parrots_cudawarpfunction.cuh
│   ├── ...
│   └── ops_cuda_kernel.cuh
│   ├── cuda
│   │ ├── common_cuda_helper.hpp
│   │ ├── parrots_cudawarpfunction.cuh
│   │ ├── ...
│   │ └── ops_cuda_kernel.cuh
|   ├── mps
│   │ ├── MPSLibrary.h
│   │ ├── ...
│   │ └── MPSUtils.h
|   ├── mlu
│   │ └── ...
|   └── utils
│   │ └── ...
├── onnxruntime
│   ├── onnxruntime_register.h
│   ├── onnxruntime_session_options_config_keys.h
Expand All @@ -41,9 +49,15 @@ This folder contains all non-python code for MMCV custom ops. Please follow the
│   ├── cuda
│   │   ├── ...
│   │   └── ops_cuda.cu
│   └── cpu
│   ├── cpu
│   │   ├── ...
│   │   └── ops.cpp
│   ├── mps
│   │   ├── ...
│   |   └── op_mps.mm
│   └── mlu
│      ├── ...
│      └── ops.cpp
│      └── op_mlu.cpp
└── tensorrt
├── trt_cuda_helper.cuh
├── trt_plugin_helper.hpp
Expand All @@ -63,13 +77,18 @@ This folder contains all non-python code for MMCV custom ops. Please follow the

- `common`: This directory contains all tools and shared codes.
- `cuda`: The cuda kernels which can be shared by all backends. **HIP** kernel is also here since they have similar syntax.
- `onnxruntime`: **ONNX Runtime** support for custom ops.
- `mps`: The tools used to support MPS ops. **NOTE** that MPS support is **experimental**.
- `mlu`: The MLU kernels used to support [Cambricon](https://www.cambricon.com/) device.
- `utils`: The kernels and utils of spconv.
- `onnxruntime`: **ONNX Runtime** support for custom ops. Has been deprecated, please try the latest custom ops in [MMDeploy](https://github.com/open-mmlab/mmdeploy).
- `cpu`: CPU implementation of supported ops.
- `parrots`: **Parrots** is a deep learning frame for model training and inference. Parrots custom ops are placed in this directory.
- `pytorch`: **PyTorch** custom ops are supported by binding C++ to Python with **pybind11**. The ops implementation and binding codes are placed in this directory.
- `cuda`: This directory contains cuda kernel launchers, which feed memory pointers of tensor to the cuda kernel in `common/cuda`. The launchers provide c++ interface of cuda implementation of corresponding custom ops.
- `cpu`: This directory contain cpu implementations of corresponding custom ops.
- `tensorrt`: **TensorRT** support for custom ops.
- `mlu`: This directory contain launchers of each MLU kernels.
- `mps`: MPS ops implementation and launchers.
- `tensorrt`: **TensorRT** support for custom ops. Has been deprecated, please try the latest custom ops in [MMDeploy](https://github.com/open-mmlab/mmdeploy).
- `plugins`: This directory contains the implementation of the supported custom ops. Some ops might also use shared cuda kernel in `common/cuda`.

## How to add new PyTorch ops?
Expand Down
64 changes: 64 additions & 0 deletions mmcv/ops/csrc/common/mps/MPSDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright © 2022 Apple Inc.

// This file is modify from:
// https://github.com/pytorch/pytorch/blob/a85d1f0bcdd02cf18d3b0517337458cb51a18cdb/aten/src/ATen/mps/MPSDevice.h

#pragma once
#include <ATen/ATen.h>
#include <c10/macros/Macros.h>
#include <c10/util/Exception.h>

#ifdef __OBJC__
#include <Foundation/Foundation.h>
#include <Metal/Metal.h>
#include <MetalPerformanceShaders/MetalPerformanceShaders.h>
typedef id<MTLDevice> MTLDevice_t;
#else
typedef void* MTLDevice;
typedef void* MTLDevice_t;
#endif

using namespace std;

namespace at {
namespace mps {

//-----------------------------------------------------------------
// MPSDevice
//
// MPSDevice is a singleton class that returns the default device
//-----------------------------------------------------------------

class TORCH_API MPSDevice {
public:
/**
* MPSDevice should not be cloneable.
*/
MPSDevice(MPSDevice& other) = delete;
/**
* MPSDevice should not be assignable.
*/
void operator=(const MPSDevice&) = delete;
/**
* Gets single instance of the Device.
*/
static MPSDevice* getInstance();
/**
* Returns the single device.
*/
MTLDevice_t device() { return _mtl_device; }

~MPSDevice();

private:
static MPSDevice* _device;
MTLDevice_t _mtl_device;
MPSDevice();
};

TORCH_API bool is_available();

TORCH_API at::Allocator* GetMPSAllocator(bool useSharedAllocator = false);

} // namespace mps
} // namespace at
Loading

0 comments on commit 22fadce

Please sign in to comment.