Skip to content

Commit

Permalink
Add ability to create shared library to the driver. (#985)
Browse files Browse the repository at this point in the history
Closes #314.

Adds PIC code flag to the requires spots and allows `-static` and
`-shared` flags to be passed to the linker.
  • Loading branch information
schweitzpgi authored Dec 4, 2023
1 parent d47a100 commit 4ca0bc1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docker/build/devdeps.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y wget ca-certifi
&& apt-get autoremove -y --purge && apt-get clean && rm -rf /var/lib/apt/lists/*
ENV PATH="${PATH}:/usr/local/cmake-3.26/bin"
RUN apt-get update && apt-get install -y --no-install-recommends \
git ninja-build libcurl4-openssl-dev \
git ninja-build file libcurl4-openssl-dev \
python3 python3-pip libpython3-dev \
&& python3 -m pip install --no-cache-dir \
lit pytest numpy \
Expand Down
19 changes: 19 additions & 0 deletions test/NVQPP/shared_obj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// RUN: nvq++ --enable-mlir -shared -fpic %s -o %t && file %t | FileCheck %s

#include <cudaq.h>

struct Qernel {
void operator()() __qpu__ {}
};

int plain_old_function() { return 0; }

// CHECK: shared
10 changes: 8 additions & 2 deletions tools/nvqpp/nvq++.in
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,16 @@ while [ $# -ne 0 ]; do
LINKLIBS="${LINKLIBS} -l$2"
shift
;;
-fPIC|-fpic)
# Pass to linker, library mode, and cudaq-quake
LINKER_FLAGS="${LINKER_FLAGS} $1"
ARGS="${ARGS} $1"
CUDAQ_QUAKE_ARGS="${CUDAQ_QUAKE_ARGS} --Xcudaq $1"
;;
-c)
DO_LINK=false
;;
-L* | -Wl*)
-L* | -Wl* |-shared|-static)
LINKER_FLAGS="${LINKER_FLAGS} $1"
;;
-I*)
Expand Down Expand Up @@ -652,7 +658,7 @@ if ${DO_LINK}; then
run ${LINKER_CXX} ${LINKER_PATH} ${LINKER_FLAGS} ${LINKDIRS} ${OBJS} ${LINKLIBS} ${OUTPUTOPTS}
else
# Save the object file to what the user specified
if [ ! -z "${OUTPUTFILE}" ] && [ $((${#OBJS[@]} == 0)) ]; then
if [ ! -z "${OUTPUTFILE}" ] && ((${#OBJS[@]} == 0)); then
run mv ${OBJS} ${OUTPUTFILE}
fi
fi

0 comments on commit 4ca0bc1

Please sign in to comment.