Skip to content

Commit

Permalink
🔥 Remove opencl
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Dec 31, 2024
1 parent 8e1b37a commit c2dee0d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 149 deletions.
3 changes: 1 addition & 2 deletions src/cpp/ipc_apple.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef __IPC_APPLE_H__
#define __IPC_APPLE_H__

#define USE_OPENCL_DL_PACK_TENSOR 0
#define USE_CUSTOM_DL_PACK_TENSOR (HAS_TORCH)
#define USE_CUSTOM_DL_PACK_TENSOR 1

py::object
mtl_tensor_from_mach_port(unsigned int machPort, int width, int height);
Expand Down
19 changes: 2 additions & 17 deletions src/cpp/ipc_apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
namespace py = pybind11;
#include "dlpack.h"
#include "ipc_apple.h"
#include <OpenCL/cl_ext.h>
#include <OpenCL/opencl.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <iostream>
Expand All @@ -17,6 +15,8 @@

// Sad news: PyTorch does not support from_dlpack for Metal tensors.
// Therefore, we should create a OpenCL dlpack tensor from the IOSurface.
// However OpenCL is not supported in PyTorch!
// Use custom dlpack tensor for now.

IOSurfaceRef getIOSurfaceFromMachPort(mach_port_t machPort) {
mach_port_type_t portType;
Expand Down Expand Up @@ -136,20 +136,6 @@ static void deleteDLManagedTensor(DLManagedTensor *self) {
);
}

#if USE_OPENCL_DL_PACK_TENSOR
cl_context context = createOpenCLContext();
DLManagedTensor *tensor =
createDLPackTensorFromOpenCL(context, ioSurface, width, height);
return py::reinterpret_steal<py::object>(PyCapsule_New(
tensor,
"dltensor",
[](PyObject *capsule) {
DLManagedTensor *tensor =
(DLManagedTensor *)PyCapsule_GetPointer(capsule, "dltensor");
tensor->deleter(tensor);
}
));
#else
DLManagedTensor *tensor = createDLPackTensorMetal(mtlBuffer, width, height);

#if USE_CUSTOM_DL_PACK_TENSOR
Expand All @@ -165,5 +151,4 @@ static void deleteDLManagedTensor(DLManagedTensor *self) {
}
));
#endif
#endif
}
127 changes: 0 additions & 127 deletions src/cpp/ipc_apple_opencl.mm

This file was deleted.

4 changes: 1 addition & 3 deletions src/cpp/ipc_apple_torch.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "dlpack.h"
#include "ipc_apple.h"
#include <ATen/DLConvertor.h>
#include <ATen/Tensor.h>
#include <torch/extension.h>
#include "ipc_apple.h"

#if USE_CUSTOM_DL_PACK_TENSOR
at::Tensor
Expand Down

0 comments on commit c2dee0d

Please sign in to comment.