ByteDance is building its own CPUs on Arm and RISC-V to feed its AI infrastructure
Back to Tutorials
techTutorialbeginner

ByteDance is building its own CPUs on Arm and RISC-V to feed its AI infrastructure

May 27, 202611 views4 min read

Learn how to set up a RISC-V development environment, which is one of the key architectures being used by ByteDance for its AI infrastructure. This tutorial teaches you to install the RISC-V toolchain and compile your first RISC-V program.

Introduction

ByteDance, the parent company of TikTok, is developing its own custom CPUs using Arm and RISC-V architectures to power its growing AI infrastructure. This move is driven by the rising costs of traditional processors and US export restrictions. In this tutorial, you'll learn how to set up a basic RISC-V development environment, which is one of the key architectures ByteDance is using for its custom chips. This is an excellent starting point for anyone interested in understanding modern processor architectures and how they're being used in AI infrastructure.

Prerequisites

Before beginning this tutorial, you should have:

  • A computer running Linux (Ubuntu 20.04 or newer recommended)
  • Basic understanding of command-line operations
  • Internet connection for downloading tools and packages
  • Root access or sudo privileges for installing software

Step-by-Step Instructions

1. Setting Up Your Development Environment

1.1 Update Your System

First, we need to ensure your system is up-to-date with the latest packages:

sudo apt update && sudo apt upgrade -y

This ensures you have the latest security patches and software versions, which is crucial for a stable development environment.

1.2 Install Essential Development Tools

Next, install the basic tools needed for development:

sudo apt install build-essential git wget curl -y

These tools include the GNU Compiler Collection (GCC), Git for version control, and download utilities that will be needed throughout this tutorial.

2. Installing RISC-V Toolchain

2.1 Download RISC-V GNU Toolchain

Now we'll install the RISC-V toolchain, which allows us to compile code for RISC-V processors:

cd ~
wget https://github.com/riscv/riscv-gnu-toolchain/archive/refs/heads/master.zip
unzip master.zip

This downloads the latest RISC-V GNU toolchain from GitHub, which is essential for cross-compiling programs for RISC-V architecture.

2.2 Configure and Build the Toolchain

cd riscv-gnu-toolchain-master
./configure --prefix=/opt/riscv
make

The configuration step sets up the installation path, and make compiles the toolchain. This process may take 30-60 minutes depending on your system's performance.

3. Creating Your First RISC-V Program

3.1 Write a Simple C Program

Create a basic "Hello, World!" program that we'll compile for RISC-V:

cat > hello.c << EOF
#include <stdio.h>

int main() {
    printf("Hello from RISC-V!\n");
    return 0;
}
EOF

This simple program demonstrates how code can be written in C and then compiled for different architectures.

3.2 Compile for RISC-V Architecture

/opt/riscv/bin/riscv64-unknown-elf-gcc -o hello hello.c

This command uses the RISC-V compiler to create an executable file that can run on RISC-V processors. The prefix /opt/riscv/bin/ tells the system where to find the RISC-V tools we installed.

4. Understanding RISC-V Architecture Concepts

4.1 Explore RISC-V Instruction Set

Let's examine what instructions are available in our RISC-V toolchain:

/opt/riscv/bin/riscv64-unknown-elf-objdump -d hello

This disassembles the compiled program, showing the actual RISC-V instructions that will be executed on a RISC-V processor. This is important for understanding how the code translates to machine-level operations.

4.2 Learn About RISC-V Features

RISC-V is a modern, open instruction set architecture that's gaining popularity for AI and edge computing because:

  • It's open-source and free to use
  • It's designed for scalability from microcontrollers to supercomputers
  • It supports efficient AI processing with specialized extensions

ByteDance's move toward RISC-V is part of a broader industry trend toward open, customizable architectures that can be optimized for specific AI workloads.

5. Testing Your Setup

5.1 Verify Toolchain Installation

/opt/riscv/bin/riscv64-unknown-elf-gcc --version

This confirms that your RISC-V toolchain is properly installed and accessible. You should see version information for the compiler.

5.2 Run a Simple Test

While we can't execute RISC-V binaries on regular x86 processors, we can verify the compilation worked correctly:

file hello

The file command should show that hello is a RISC-V executable, confirming our compilation was successful.

Summary

In this tutorial, you've learned how to set up a RISC-V development environment, which is one of the key architectures being used by companies like ByteDance for their AI infrastructure. You installed the RISC-V GNU toolchain, created and compiled a simple program, and explored how RISC-V architecture differs from traditional x86 processors. This foundational knowledge is crucial for understanding how custom processors are being developed to support the growing demands of AI workloads. As companies move away from traditional processors due to cost and availability issues, understanding architectures like RISC-V becomes increasingly important for developers working in AI and high-performance computing.

Source: TNW Neural

Related Articles