Skip to content

[SYCL] Introduce backend macros #4636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 14, 2021
Merged

Conversation

vladimirlaz
Copy link
Contributor

@vladimirlaz vladimirlaz commented Sep 27, 2021

According to SYCL spec: backend macro should be specified for all supported
backends (defined in the Khronos group). It also refers to extension macros
(aka feature test macro) for other backends introduced by a vendor. Khronos
group defines only OpenCL backend and other backends supported by DPC++
should be treated as extensions.

The following macros are defined when the compiler is built with the
corresponding backend. OpenCL and Level_Zero backends are always
available, others are enabled on build time:

  • OpenCL backed: SYCL_BACKEND_OPENCL
  • Level Zero backend: SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO ()
  • CUDA backend: SYCL_EXT_ONEAPI_BACKEND_CUDA
  • ESIMD_CPU backend: SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR
  • HIP backend: SYCL_EXT_ONEAPI_BACKEND_HIP
    Extra libs may be required to link DPC++ application and run it.

backend::esimd_cpu is renamed to backend::ext_intel_esimd_emulator. Old
naming was marked as deprecated.

According to SYCL spec: backend macro should be specified for all supported
backends (defined in the Khronos group). It also refers to extension macros
(aka feature test macro) for other backends introduced by a vendor. Khronos
group defines only OpenCL backend and other backends supported by DPC++
should be treated as extensions.

The following macros are defined unconditionaly because backend support
is always available on DPC++ compile stage:
 - OpenCL backed:      SYCL_BACKEND_OPENCL
 - Level Zero backend: SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
 - CUDA backend:       SYCL_EXT_ONEAPI_BACKEND_CUDA
 - ESIMD_CPU backend:  SYCL_EXT_INTEL_BACKEND_ESIMD_CPU
 - HIP backend:        SYCL_EXT_ONEAPI_BACKEND_HIP
Extra libs may be required to link DPC++ application and run it.
@vladimirlaz vladimirlaz requested a review from a team as a code owner September 27, 2021 08:24
s-kanaev
s-kanaev previously approved these changes Sep 27, 2021
Copy link
Contributor

@s-kanaev s-kanaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vladimirlaz
Copy link
Contributor Author

@gmlueck, @jbrodman, @Pennycook could you please have a look?

@gmlueck
Copy link
Contributor

gmlueck commented Sep 27, 2021

It looks like the backends cuda, esimd_cpu, and hip are only conditionally supported if they are enabled in the "configure.py" script. Therefore, shouldn't these macros only be conditionally defined?

@vladimirlaz
Copy link
Contributor Author

vladimirlaz commented Sep 28, 2021

cuda, esimd_cpu, and hip are only conditionally supported if they a

We do not remove support for BEs in headers depending on the build configuration. So we headers contain all BE specific code. that is why I decided to add these macros unconditionally.

@gmlueck
Copy link
Contributor

gmlueck commented Sep 28, 2021

We do not remove support for BEs in headers depending on the build configuration. So we headers contain all BE specific code. that is why I decided to add these macros unconditionally.

Conformant SYCL code might look something like this:

void conditionallyDoCudaThing(queue q) {
#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA
  if (q.get_backend() == backend::cuda) {
    q.single_task([=] {
      // Calls that are legal in a CUDA kernel
    });
  }
#endif
}

What will happen if DPC++ is configured without CUDA support? Will that code still compile and run without errors? Obviously, the kernel won't be submitted in this case because q.get_backend() == backend::cuda will evaluate to false. However, the compiler must not report any errors and the runtime must not throw any exceptions or fail even though DPC++ is not configured with CUDA support. Will this be the case even though SYCL_EXT_ONEAPI_BACKEND_CUDA is defined?

@vladimirlaz
Copy link
Contributor Author

vladimirlaz commented Sep 28, 2021

We do not remove support for BEs in headers depending on the build configuration. So we headers contain all BE specific code. that is why I decided to add these macros unconditionally.

Conformant SYCL code might look something like this:

void conditionallyDoCudaThing(queue q) {
#ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA
  if (q.get_backend() == backend::cuda) {
    q.single_task([=] {
      // Calls that are legal in a CUDA kernel
    });
  }
#endif
}

What will happen if DPC++ is configured without CUDA support? Will that code still compile and run without errors? Obviously, the kernel won't be submitted in this case because q.get_backend() == backend::cuda will evaluate to false. However, the compiler must not report any errors and the runtime must not throw any exceptions or fail even though DPC++ is not configured with CUDA support. Will this be the case even though SYCL_EXT_ONEAPI_BACKEND_CUDA is defined?

For CUDA support where was the explicit request to make DPC++ ready for CUDA (implemented in #3811). If user drop have lib_pi_cud.so and libclc-builtin libraries to the regular compiler it can be used to work with CUDA BE.

@gmlueck
Copy link
Contributor

gmlueck commented Sep 28, 2021

For CUDA support where was the explicit request to make DPC++ ready for CUDA (implemented in #3811). If user drop have lib_pi_cud.so and libclc-builtin libraries to the regular compiler it can be used to work with CUDA BE.

Let's consider the DPCPP production build. I think CUDA support is not configured for that build, correct? I presume the libraries you mention are also not included in that build. Will the example code I show above compile without errors in that case?

@vladimirlaz
Copy link
Contributor Author

Let's consider the DPCPP production build. I think CUDA support is not configured for that build, correct? I presume the libraries you mention are also not included in that build. Will the example code I show above compile without errors in that case?

It will be successfully compiled. On the link step there will be an error due to missed built-in libraries.

@gmlueck
Copy link
Contributor

gmlueck commented Sep 28, 2021

It will be successfully compiled. On the link step there will be an error due to missed built-in libraries.

This is the sort of thing I was concerned about. This would be solved if we defined the macros conditionally based on the source configuration. Is that difficult?

@vladimirlaz
Copy link
Contributor Author

It will be successfully compiled. On the link step there will be an error due to missed built-in libraries.

This is the sort of thing I was concerned about. This would be solved if we defined the macros conditionally based on the source configuration. Is that difficult?

We can enable macros conditionally during the build of the compiler (there are no technical difficulties here). But this approach contradicts the request implemented in the scope of #3811.
@pvchupin does the support of CUDA backend is still required in the regular build (when a customer drops libpi_cuda.so and libclc in the compiler)?

@pvchupin
Copy link
Contributor

It will be successfully compiled. On the link step there will be an error due to missed built-in libraries.

This is the sort of thing I was concerned about. This would be solved if we defined the macros conditionally based on the source configuration. Is that difficult?

We can enable macros conditionally during the build of the compiler (there are no technical difficulties here). But this approach contradicts the request implemented in the scope of #3811. @pvchupin does the support of CUDA backend is still required in the regular build (when a customer drops libpi_cuda.so and libclc in the compiler)?

I don't see any contradiction. Let's chat offline...

@gmlueck
Copy link
Contributor

gmlueck commented Sep 29, 2021

We were discussing the name of the SYCL_EXT_INTEL_BACKEND_ESIMD_CPU macro offline with @kbobrovs, and we think the current name is confusing. Suggested alternatives are:

  • SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR, or
  • SYCL_EXT_INTEL_BACKEND_ESIMD_EMU

Can we change the name to one of those? Possibly, it makes sense to rename the enumerator in sycl::backend also to ext_intel_esimd_emulator (or ext_intel_esimd_emu) in this PR also, so they are in sync?

@vladimirlaz
Copy link
Contributor Author

We were discussing the name of the SYCL_EXT_INTEL_BACKEND_ESIMD_CPU macro offline with @kbobrovs, and we think the current name is confusing. Suggested alternatives are:

  • SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR, or
  • SYCL_EXT_INTEL_BACKEND_ESIMD_EMU

Can we change the name to one of those? Possibly, it makes sense to rename the enumerator in sycl::backend also to ext_intel_esimd_emulator (or ext_intel_esimd_emu) in this PR also, so they are in sync?

I will apply suggested changes later this week

@kbobrovs
Copy link
Contributor

Let's use full SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR for the ESIMD emulator macro.

@vladimirlaz vladimirlaz closed this Oct 8, 2021
@vladimirlaz vladimirlaz deleted the backend_macro branch October 8, 2021 06:18
@vladimirlaz
Copy link
Contributor Author

@kbobrovs, @gmlueck, could you please review?

Copy link
Contributor

@gmlueck gmlueck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildbot/configure.py looks good to me (not sure if ESIMD_CPU -> EMULATOR renaming directly related to backend macos though).

@vladimirlaz vladimirlaz merged commit 2b0ebab into intel:sycl Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants