aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp
blob: 293738982e060c3bc5117944bcf9215f094c24b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//===- Chipset.cpp - AMDGPU Chipset version struct parsing ----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/AMDGPU/Utils/Chipset.h"
#include "llvm/ADT/StringRef.h"

namespace mlir::amdgpu {

FailureOr<Chipset> Chipset::parse(StringRef name) {
  if (!name.consume_front("gfx"))
    return failure();
  if (name.size() < 3)
    return failure();

  unsigned major = 0;
  unsigned minor = 0;
  unsigned stepping = 0;

  StringRef majorRef = name.drop_back(2);
  StringRef minorRef = name.take_back(2).drop_back(1);
  StringRef steppingRef = name.take_back(1);
  if (majorRef.getAsInteger(10, major))
    return failure();
  if (minorRef.getAsInteger(16, minor))
    return failure();
  if (steppingRef.getAsInteger(16, stepping))
    return failure();
  return Chipset(major, minor, stepping);
}

} // namespace mlir::amdgpu