2025-05-07 13:26:46 +09:00
|
|
|
// Copyright © 2025 Apple Inc.
|
|
|
|
|
|
2025-04-13 10:53:15 +00:00
|
|
|
// This file include utilies that are used by C++ code (i.e. .cpp files).
|
|
|
|
|
|
2025-05-07 13:26:46 +09:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-04-17 09:13:00 +00:00
|
|
|
#include "mlx/array.h"
|
|
|
|
|
|
2025-05-07 13:26:46 +09:00
|
|
|
#include <cuda_runtime.h>
|
|
|
|
|
|
|
|
|
|
namespace mlx::core {
|
|
|
|
|
|
|
|
|
|
namespace cu {
|
|
|
|
|
class Device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cuda stream managed with RAII.
|
|
|
|
|
class CudaStream {
|
|
|
|
|
public:
|
|
|
|
|
explicit CudaStream(cu::Device& device);
|
|
|
|
|
~CudaStream();
|
|
|
|
|
|
|
|
|
|
CudaStream(const CudaStream&) = delete;
|
|
|
|
|
CudaStream& operator=(const CudaStream&) = delete;
|
|
|
|
|
|
|
|
|
|
operator cudaStream_t() const {
|
|
|
|
|
return stream_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
cudaStream_t stream_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Throw exception if the cuda API does not succeed.
|
|
|
|
|
void check_cuda_error(const char* name, cudaError_t err);
|
|
|
|
|
|
|
|
|
|
// The macro version that prints the command that failed.
|
|
|
|
|
#define CHECK_CUDA_ERROR(cmd) check_cuda_error(#cmd, (cmd))
|
|
|
|
|
|
2025-04-17 09:13:00 +00:00
|
|
|
// Computes a 2D grid where each element is < UINT_MAX.
|
|
|
|
|
dim3 get_2d_grid_dims(const Shape& shape, const Strides& strides);
|
|
|
|
|
|
2025-05-07 13:26:46 +09:00
|
|
|
} // namespace mlx::core
|