-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a `DeviceOptions` provider and updates the OptionsContext and OptionsProviders to use `llvm::Error`s instead of `mlirtrt::Status` since the latter is not accessible to the OptionsContext.
- Loading branch information
1 parent
97b13ec
commit 78ce313
Showing
10 changed files
with
172 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//===- OptionsProviders.cpp -------------------------------------*- C++ -*-===// | ||
// | ||
// SPDX-FileCopyrightText: Copyright 2024 NVIDIA CORPORATION & AFFILIATES. | ||
// All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// Data structures and functions for manipulating compiler options. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
#include "mlir-tensorrt/Compiler/OptionsProviders.h" | ||
#include "cuda_runtime_api.h" | ||
#include "llvm/Support/Error.h" | ||
|
||
// TODO (pranavm): Check if we can just reuse `DeviceInfo.cpp`? | ||
llvm::Error mlirtrt::compiler::DeviceOptions::inferDeviceOptionsFromHost() { | ||
cudaDeviceProp properties; | ||
cudaError_t err = cudaGetDeviceProperties(&properties, 0); | ||
if (err != cudaSuccess) | ||
return llvm::createStringError("failed to get cuda device properties"); | ||
|
||
int ccMajor = 0; | ||
int ccMinor = 0; | ||
err = cudaDeviceGetAttribute( | ||
&ccMajor, cudaDeviceAttr::cudaDevAttrComputeCapabilityMajor, 0); | ||
if (err != cudaSuccess) | ||
return llvm::createStringError( | ||
"failed to get cuda device compute capability"); | ||
err = cudaDeviceGetAttribute( | ||
&ccMinor, cudaDeviceAttr::cudaDevAttrComputeCapabilityMinor, 0); | ||
if (err != cudaSuccess) | ||
return llvm::createStringError( | ||
"failed to get cuda device compute capability"); | ||
|
||
// We want SM version as a single number. | ||
int64_t smVersion = ccMajor * 10 + ccMinor; | ||
this->computeCapability = smVersion; | ||
this->maxSharedMemoryPerBlockKb = properties.sharedMemPerBlock / 1024; | ||
this->maxRegistersPerBlock = properties.regsPerBlock; | ||
return llvm::Error::success(); | ||
} | ||
|
||
llvm::Error mlirtrt::compiler::DeviceOptions::finalize() { | ||
if (shouldInferFromHost) { | ||
// TODO (pranavm): How to check whether options were provided? | ||
// Does llvm::cl have a notion of mutually exclusive options like Python's | ||
// argparse? | ||
return inferDeviceOptionsFromHost(); | ||
} | ||
return llvm::Error::success(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.