Skip to content

Commit

Permalink
[OpenPDK] Make synthesis targets for find_index for investigation of #23
Browse files Browse the repository at this point in the history


The following command works for sample `bazel_rules_hdl` based synthesis
(yosys, sky130):

```
bazel build -c opt //xls/examples:find_index_5000ps_model_unit_verilog_synth
```

Introduces `rules_pkg` dependency to XLS Bazel WORKSPACE which is required for
`bazel_rules_hdl` to produce this target output.

PiperOrigin-RevId: 447582850
  • Loading branch information
cdleary authored and copybara-github committed May 9, 2022
1 parent ecca7a8 commit b08f89e
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dependency_support/org_tuxfamily_eigen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ cc_test(
name = "smoke_test",
srcs = ["smoke_test.cc"],
deps = [
"@org_tuxfamily_eigen//:eigen",
"@org_tuxfamily_eigen//:eigen3",
],
)
2 changes: 1 addition & 1 deletion dependency_support/org_tuxfamily_eigen/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ EIGEN_MPL2_HEADER_FILES = glob(
)

cc_library(
name = "eigen",
name = "eigen3",
hdrs = EIGEN_MPL2_HEADER_FILES,
defines = [
# This define (mostly) guarantees we don't link any problematic
Expand Down
10 changes: 10 additions & 0 deletions dependency_support/rules_hdl/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def repo():
# Required to support rules_hdl, 0.7.0 release is current as of 2022-05-09.
http_archive(
name = "rules_pkg",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
urls = [
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
],
)

# Commit on 2022-03-28, current as of 2022-05-04
git_hash = "99bd5371ed3b8551dc74bfce6a0b5b3c47adae15"
git_sha256 = "8ebe9e237072754f4b0c9b0413bf2b7e6a7a87fa711a011c1224496ddaa28a77"
Expand Down
65 changes: 65 additions & 0 deletions xls/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ load(
"xls_dslx_opt_ir_test",
"xls_dslx_test",
"xls_eval_ir_test",
"xls_ir_verilog",
)
load("@rules_hdl//verilog:providers.bzl", "verilog_library")
load("@rules_hdl//synthesis:build_defs.bzl", "synthesize_rtl")
# TODO(cdleary): 2022-05-09 Re-enable use of this rule.
# load("@rules_hdl//place_and_route:build_defs.bzl", "place_and_route")

package(
default_visibility = ["//xls:xls_internal"],
Expand Down Expand Up @@ -338,3 +343,63 @@ xls_dslx_opt_ir(
opt_ir_file = "proc_iota.opt.ir",
tags = ["optonly"],
)

# -- find_index sample, with OpenROAD synthesis

xls_dslx_library(
name = "find_index_dslx",
srcs = ["find_index.x"],
)

xls_dslx_test(
name = "find_index_test",
library = ":find_index_dslx",
)

xls_dslx_opt_ir(
name = "find_index_opt_ir",
srcs = ["find_index.x"],
dslx_top = "find_index",
ir_file = "find_index.ir",
opt_ir_file = "find_index.opt.ir",
deps = [":find_index_dslx"],
)

xls_ir_verilog(
name = "find_index_5000ps_model_unit",
src = ":find_index.opt.ir",
codegen_args = {
"delay_model": "unit",
"clock_period_ps": "5000",
"module_name": "find_index",
"use_system_verilog": "false",
},
verilog_file = "find_index_5000ps_model_unit.v",
)

verilog_library(
name = "find_index_5000ps_model_unit_verilog",
srcs = [
":find_index_5000ps_model_unit.v",
],
)

synthesize_rtl(
name = "find_index_5000ps_model_unit_verilog_synth",
top_module = "find_index",
deps = [
":find_index_5000ps_model_unit_verilog",
],
)

# TODO(cdleary): 2022-05-09 Get this target working as well, requires
# addressing the dependence on openmp runtime.
# place_and_route(
# name = "find_index_place_and_route",
# # ~64 MhZ
# clock_period = "15.42857143",
# core_padding_microns = 30,
# placement_density = "0.8",
# synthesized_rtl = ":find_index_5000ps_model_unit_verilog_synth",
# target_die_utilization_percentage = "30",
# )
28 changes: 28 additions & 0 deletions xls/examples/find_index.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The XLS Authors
//
// 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.

import std

fn find_index(x: u4[4], target: u4) -> (bool, u2) {
let (found, index) = std::find_index(x, target);
(found, index as u2)
}

#![test]
fn test_sample_values() {
let _ = assert_eq(find_index(u4[4]:[1, 2, 3, 4], u4:1), (true, u2:0));
let _ = assert_eq(find_index(u4[4]:[1, 2, 3, 4], u4:3), (true, u2:2));
let _ = assert_eq(find_index(u4[4]:[1, 2, 3, 4], u4:5), (false, u2:0));
()
}

0 comments on commit b08f89e

Please sign in to comment.