From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id DFDB13858C53 for ; Mon, 9 Sep 2024 10:46:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFDB13858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DFDB13858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725878812; cv=none; b=Mh1w0NoILsAkP4OG3c0xWC7ZOH/WsPqy3T/J6IY296dxGHaEBdJ5LMJ+1CMXMgN2GcRPwFhFUtis2AdWQPxayvV+QYODOMiYGDC2A/mheBS/kRntN5BtImmmKP6GSV6gexKCBwIa98T4Xv7oWFIyCGEahRcgPmyfXPxLPOf5QF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725878812; c=relaxed/simple; bh=S57Pek5JrUxvp9pGgZGwbOiKlqJxAvystoDxf/dPiqg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=xuRuJ+qqwv9KA7xi0fZvCrDVcw+xmEF/BYtWlj3kzTGcTpQompC1ISsmBgGaKmSAJWDLP3/kb9Z3VszQoG3I8YE9r6XqSO+vzjcDqPm8UUNBaExCU/wVQGo0/J+pxGVV7vHoUKw7haeZORBJcWsEg53w/WJDQzWQlW3C/5nNayM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-371941bbfb0so2493566f8f.0 for ; Mon, 09 Sep 2024 03:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725878797; x=1726483597; darn=gcc.gnu.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Xxg44QWexXKCFW6GogZrXje1JGvmfKeyP8ydtH50ay0=; b=IRJeCwPFcGAOLN1AWTWfjPTyc2diJRwIwfR5Fu0Br53lDa1FkDGOiTHHcFPoqhSkxo sSo4rq+uzrFSPlTnZar8YsIrfbPbzRTZEQJAIE7J0uJ/vDjdb7Jl37qAvGJBaXzNWDJR ZeOD7ieRcbkU4bLkLvNPtqDccxIN8r/6HFiNtVp1iBvJbSos+/xfAdJayuFlmNyvI0w7 5Kcl3fkmkPn/jaLszD3kF7ouIqNu78bm87IowbK+1J3C6uQYlmSfxJqqBIGff/UA0hhC +af6B0gFf5XuBmrf2TbzInnou4GgKD7x01/mK6Kic6Nc4JkDsLFKZkiOoX7WMdpw27Tc A5aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725878797; x=1726483597; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Xxg44QWexXKCFW6GogZrXje1JGvmfKeyP8ydtH50ay0=; b=Fy12fIAuECHyZLTUc7UyokP4VTtytETVoqwp9HYfVzSKPHjYlZ1zma9QfIYGwfrTzD n4DtrtWTk+dHnoOAnVJQShV/EHs1IgrguuUNxGFPQp1awH07kl95DbC4tSAuUmoUhu8c 1kFOOQlo/hSPvXXcBJ2BEk6nGXbcIrdMYsKpE/W5rLTpqkDqs5N268xRIvDEkL55cqR7 7gCRfuMSJkkewJeJl+ijxBLWbbMQ1cYFhrfyBsXmVcXseioY5sU4dKNFqC/8tvM6XLr5 7eICargG7BHT3fZnpZzRbhklANJ9+Y+owIY15F2xAm2W20z7KEA/O0kgxyzEiNnsAgLM +NnA== X-Gm-Message-State: AOJu0YzQw4YaAm1qq/h+LKgXGnekhxvrEDbiBd/HAQpf9fSFmP+Ol9Mm Cxr2sCRQnuA4+jB+v7UJuISMERDQJgLw+GQTjFzVfFGICByCzhacgA9mzHwWktE= X-Google-Smtp-Source: AGHT+IErXzroTZa9wQdKFjgwrUIfpR76jCNDBe6xHTK2eLsTeCbBkImRFvL0wu85gexQ7X9fVC8gqA== X-Received: by 2002:adf:fa81:0:b0:374:c640:8596 with SMTP id ffacd0b85a97d-3789269e5admr3846627f8f.32.1725878797324; Mon, 09 Sep 2024 03:46:37 -0700 (PDT) Received: from ?IPV6:2001:16b8:3da2:d900:dc92:cab2:4adc:f4e1? ([2001:16b8:3da2:d900:dc92:cab2:4adc:f4e1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42caeb322fdsm71994985e9.11.2024.09.09.03.46.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Sep 2024 03:46:37 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------pE5EY0EiO0EtCur80HVG8vh0" Message-ID: Date: Mon, 9 Sep 2024 12:46:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 03/12] libgomp: runtime support for target_device selector To: Jakub Jelinek , Sandra Loosemore Cc: gcc-patches@gcc.gnu.org References: <20240720204231.2229891-1-sloosemore@baylibre.com> <20240720204231.2229891-4-sloosemore@baylibre.com> Content-Language: en-US From: Tobias Burnus In-Reply-To: X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multi-part message in MIME format. --------------pE5EY0EiO0EtCur80HVG8vh0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi all, Jakub Jelinek wrote: > On Sat, Jul 20, 2024 at 02:42:22PM -0600, Sandra Loosemore wrote: >> This patch implements the libgomp runtime support for the dynamic >> target_device selector via the GOMP_evaluate_target_device function. > […] > > Now for kind, isa and arch traits in the target_device set this patch > decides based on compiler flags used to compile some routine in libgomp.so > or libgomp.a. > > While this can work in the (very unfortunate) GCN state of things where > only exact isa match is possible (I really hope we can one day generalize > it by being able to compile for a set of isas by supporting lowest > denominator and patching the EM_* in the ELF header or something similar, > perhaps with runtime decisions on what to do for different CPUs), I think that can only work to some extend. LLVM has "gfx11-generic" which is compatible with gfx110{0,1,2,3,} and gfx115{0,1,2}, which at least helps a bit. For gfx10, it has gfx10-1-generic for gfx101{0,1,2,3} and gfx10-3-generic for gfx103[0-6] and gfx9-generic for gfx90{0,2,4,6,9,c}. Thus, we could have versions which support a common subset, but we still need multiple libraries. And it needs to be implemented … This sounds like a task for the GCN maintainer … * * * > deciding what to do based on how libgomp.a or libgomp.so.1 has been compiled for the > rest is IMHO wrong. I wonder whether we should do something like the following. [The following is a mix between compile code and generated code, for illustrative purpose.] Inside the compiler do: #ifndef ACCEL_COMPILER intr = 0; if (targetm.omp.device_kind_arch_isa != NULL) r = targetm.omp.device_kind_arch_isa (omp_device_{kind,arch,isa}, val); if (dev_num && TREE_CODE (dev_num) == INTEGER_CST) { if (dev_num < -1 /* INVALID_DEVICE or nonconforming */) → 0 if (dev_num == initial_device) → r } /* The '? :' condition is a compile time condition. */ d = ? : omp_get_default_device (); if (d < -1) → 0 else if (d == -1 || d == omp_get_initial_device ()) → r else → GOMP_get_device_kind_arch_isa (d, kind, arch, isa) #else /* VARIANT 1: Assume that neither reverse offload nor nested target occurs. */ →targetm.omp.device_kind_arch_isa (kind, arch, isa) /* VARIANT 2 - d = ? : omp_get_default_device (); if (d == omp_get_device_num ()) →targetm.omp.device_kind_arch_isa (kind, arch, isa) else /* Cannot really do anything here - and as no nested target is permitted, use 'false'. */ → 0 #endif * * * And on the libgomp side GOMP_get_device_kind_arch_isa → plugin code. And there: (A) GCN: kind and arch are clear. For ISA: agent->device_isa + use existing isa_hsa_name() function (or likewise). (B) Nvptx: cuDeviceGetAttribute + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75 and CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76. Example: sm_89 = (major) 8 and (minor) 9. * * * Does this sound sensible? Tobias PS: For the current host-offload GSoC task, we might eventually think of using cpuid on x86-64, i.e. gcc/config/i386/cpuid.h. PS: RFC remains: Should 'sm_80' be true if the hardware/compilation is 'sm_89' or not? Namely: Does 'sm_80' denote the capability or the specific hardware? Regarding this topic, see also https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662059.html --------------pE5EY0EiO0EtCur80HVG8vh0--